class Cockroach < Formula desc "Distributed SQL database" homepage "https://www.cockroachlabs.com" url "https://binaries.cockroachdb.com/cockroach-v2.0.0.src.tgz" version "2.0.0" sha256 "7ef33526ece2d41c869380ac1b287029387bce06c26fcb9ae162bdcd71711075" head "https://github.com/cockroachdb/cockroach.git" bottle do cellar :any_skip_relocation sha256 "e53286a099540e9d7afd12aacc7426eadb03987762240f270e6d6c85f2aed772" => :high_sierra sha256 "1129829aebd9b09233c48bf93b2e132b74e0c1b1546833f464ea72fdd96003f5" => :sierra sha256 "8f2364956936bdc733a33dfaa052f8984331ac7cdcd35feb198566f8647235e6" => :el_capitan end depends_on "autoconf" => :build depends_on "cmake" => :build depends_on "go" => :build depends_on "xz" => :build def install system "make", "install", "prefix=#{prefix}" end def caveats; <<~EOS For local development only, this formula ships a launchd configuration to start a single-node cluster that stores its data under: #{var}/cockroach/ Instead of the default port of 8080, the node serves its admin UI at: #{Formatter.url("http://localhost:26256")} Do NOT use this cluster to store data you care about; it runs in insecure mode and may expose data publicly in e.g. a DNS rebinding attack. To run CockroachDB securely, please see: #{Formatter.url("https://www.cockroachlabs.com/docs/secure-a-cluster.html")} EOS end plist_options :manual => "cockroach start --insecure" def plist; <<~EOS Label #{plist_name} ProgramArguments #{opt_bin}/cockroach start --store=#{var}/cockroach/ --http-port=26256 --insecure --host=localhost WorkingDirectory #{var} RunAtLoad KeepAlive EOS end test do begin # Redirect stdout and stderr to a file, or else `brew test --verbose` # will hang forever as it waits for stdout and stderr to close. system "#{bin}/cockroach start --insecure --background &> start.out" pipe_output("#{bin}/cockroach sql --insecure", <<~EOS) CREATE DATABASE bank; CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL); INSERT INTO bank.accounts VALUES (1, 1000.50); EOS output = pipe_output("#{bin}/cockroach sql --insecure --format=csv", "SELECT * FROM bank.accounts;") assert_equal <<~EOS, output id,balance 1,1000.50 EOS ensure system "#{bin}/cockroach", "quit", "--insecure" end end end