Skip to content

Instantly share code, notes, and snippets.

@ksol
Created January 13, 2021 09:46
Show Gist options
  • Save ksol/f4becaebb4a28757bfc69fd255c44157 to your computer and use it in GitHub Desktop.
Save ksol/f4becaebb4a28757bfc69fd255c44157 to your computer and use it in GitHub Desktop.
etcd 3.1.7
class Etcd < Formula
desc "Key value store for shared configuration and service discovery"
homepage "https://github.com/coreos/etcd"
url "https://github.com/coreos/etcd/archive/v3.1.7.tar.gz"
sha256 "41cbfc6744c76aa1735e11c82e6f6ff03c88dc88810938cf6eb80930dc994b2a"
head "https://github.com/coreos/etcd.git"
depends_on "go" => :build
def install
ENV["GOPATH"] = buildpath
mkdir_p "src/github.com/coreos"
ln_s buildpath, "src/github.com/coreos/etcd"
system "./build"
bin.install "bin/etcd"
bin.install "bin/etcdctl"
end
plist_options :manual => "etcd"
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>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/etcd</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
</dict>
</plist>
EOS
end
test do
begin
test_string = "Hello from brew test!"
etcd_pid = fork do
exec bin/"etcd", "--force-new-cluster", "--data-dir=#{testpath}"
end
# sleep to let etcd get its wits about it
sleep 10
etcd_uri = "http://127.0.0.1:2379/v2/keys/brew_test"
system "curl", "--silent", "-L", etcd_uri, "-XPUT", "-d", "value=#{test_string}"
curl_output = shell_output("curl --silent -L #{etcd_uri}")
response_hash = JSON.parse(curl_output)
assert_match(test_string, response_hash.fetch("node").fetch("value"))
ensure
# clean up the etcd process before we leave
Process.kill("HUP", etcd_pid)
end
end
end
1. save file above somewhere
2. `brew install <file above>`
3. `brew pin etcd` to lock the version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment