class Cockroach < Formula desc "Distributed SQL database" homepage "https://www.cockroachlabs.com" url "https://binaries.cockroachdb.com/cockroach-v19.1.3.src.tgz" version "19.1.3" sha256 "65e4c4ebb9c31a0d4e0522ad62d1f95663e594b05227ccedc7b05271bd5fd34a" head "https://github.com/cockroachdb/cockroach.git" bottle do cellar :any_skip_relocation sha256 "74ca511c16a2a256d8a585a9ca660241d5d2042e75493279e75e01db10c7f2ce" => :mojave sha256 "f24624225b210a23849a3af48a5a2823d6ddc8d5631b3b2c5914975cf51087f8" => :high_sierra sha256 "babb57e0f14672ea609e527a7615899fcceaf9ae5ceb702a34fcd9ba319a0783" => :sierra end depends_on "autoconf" => :build depends_on "cmake" => :build depends_on "go" => :build depends_on "make" => :build depends_on "xz" => :build def install # The GNU Make that ships with macOS Mojave (v3.81 at the time of writing) has a bug # that causes it to loop infinitely when trying to build cockroach. Use # the more up-to-date make that Homebrew provides. ENV.prepend_path "PATH", Formula["make"].opt_libexec/"gnubin" # Build only the OSS components system "make", "buildoss" system "make", "install", "prefix=#{prefix}", "BUILDTYPE=release" 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 rescue => e # If an error occurs, attempt to print out any messages from the # server. begin $stderr.puts "server messages:", File.read("start.out") rescue $stderr.puts "unable to load messages from start.out" end raise e ensure system "#{bin}/cockroach", "quit", "--insecure" end end end