homebrew-core/Formula/cockroach.rb
2018-03-13 14:07:53 +10:00

96 lines
3.4 KiB
Ruby

class Cockroach < Formula
desc "Distributed SQL database"
homepage "https://www.cockroachlabs.com"
url "https://binaries.cockroachdb.com/cockroach-v1.1.6.src.tgz"
version "1.1.6"
sha256 "1a4d6e43d6fe8f4dc4b8f504862a4933c7d4f3d0912f780f6efba1d4003d40fd"
head "https://github.com/cockroachdb/cockroach.git"
bottle do
cellar :any_skip_relocation
sha256 "55da0d166ed9afb8ea1c3ea9f389946c509a42f5da8bc8c92b790306173d1a55" => :high_sierra
sha256 "d3679e5f6bc909beea3a5a6234f195cceb98855d65b01e3651d3abf74ff97791" => :sierra
sha256 "4883fe9f8b725605398088b33cffcfb88a88491f6cabacd823990925a430ad05" => :el_capitan
end
depends_on "autoconf" => :build
depends_on "cmake" => :build
depends_on "go" => :build
depends_on "xz" => :build
def install
# unpin the Go version
go_version = Formula["go"].installed_version.to_s.split(".")[0, 2].join(".")
inreplace "src/github.com/cockroachdb/cockroach/.go-version",
/^GOVERS = go.*/, "GOVERS = go#{go_version.gsub(".", "\\.")}.*"
# Allow building with Go versions > 1.8.3, which introduced additional LDFLAG whitelisting.
# TODO: remove when cockroach's Makefile handles this internally (i.e. >= 1.1.7).
ENV["CGO_LDFLAGS_ALLOW"] = "-u_je_zone_register"
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
<?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
# 1 row
EOS
ensure
system "#{bin}/cockroach", "quit", "--insecure"
end
end
end