homebrew-core/Formula/cockroach.rb
2019-02-20 01:19:58 +08:00

95 lines
3.3 KiB
Ruby

class Cockroach < Formula
desc "Distributed SQL database"
homepage "https://www.cockroachlabs.com"
url "https://binaries.cockroachdb.com/cockroach-v2.1.5.src.tgz"
version "2.1.5"
sha256 "f6cb86baab6077aac0b6d8eee5603015cc68521aa1b089c4dde58413d29fab2d"
head "https://github.com/cockroachdb/cockroach.git"
bottle do
cellar :any_skip_relocation
sha256 "83c9371766f1cb9431d6e39cf7dd803a43de02f4a8ff7db27d0a1200c4a790fc" => :mojave
sha256 "836a94224b0cec5739fa0510f57ca57a4fe166a82004c87eb63868f628ac5536" => :high_sierra
sha256 "aa84f03bf8917754983b839a284b0f271cd1844aaf2e29eb239ea258df68a7fe" => :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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/cockroach</string>
<string>start</string>
<string>--store=#{var}/cockroach/</string>
<string>--http-port=26256</string>
<string>--insecure</string>
<string>--host=localhost</string>
</array>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
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