homebrew-core/Formula/faas-cli.rb
2017-09-29 18:18:49 -07:00

82 lines
2.4 KiB
Ruby

class FaasCli < Formula
desc "CLI for templating and/or deploying FaaS functions"
homepage "http://docs.get-faas.com/"
url "https://github.com/openfaas/faas-cli.git",
:tag => "0.4.16",
:revision => "8fead1a494318efcc51b97c17334038b8b53d871"
bottle do
cellar :any_skip_relocation
sha256 "7d2b45ee8c7972a803e206c99ea3af61f758e0a1fe82f7c3758e34536139a561" => :high_sierra
sha256 "1cf1580b7f91d8cf7a51ea15877abed9aa4607ef1f14fe955ac7f1ed683e857c" => :sierra
sha256 "0d7cb4ff2cc9d80184982cc25efa4bd701dbe24fd6af3914e4dfcbe25b750f1e" => :el_capitan
end
depends_on "go" => :build
def install
ENV["XC_OS"] = "darwin"
ENV["XC_ARCH"] = MacOS.prefer_64_bit? ? "amd64" : "386"
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/openfaas/faas-cli").install buildpath.children
cd "src/github.com/openfaas/faas-cli" do
commit = Utils.popen_read("git rev-list -1 HEAD").chomp
system "go", "build", "-ldflags", "-s -w -X github.com/openfaas/faas-cli/commands.GitCommit=#{commit}", "-a",
"-installsuffix", "cgo", "-o", bin/"faas-cli"
prefix.install_metafiles
end
end
test do
require "socket"
server = TCPServer.new("localhost", 0)
port = server.addr[1]
pid = fork do
loop do
socket = server.accept
response = "OK"
socket.print "HTTP/1.1 200 OK\r\n" \
"Content-Length: #{response.bytesize}\r\n" \
"Connection: close\r\n"
socket.print "\r\n"
socket.print response
socket.close
end
end
(testpath/"test.yml").write <<-EOF.undent
provider:
name: faas
gateway: http://localhost:#{port}
network: "func_functions"
functions:
dummy_function:
lang: python
handler: ./dummy_function
image: dummy_image
EOF
expected = <<-EOS.undent
Deploying: dummy_function.
Removing old service.
Deployed.
URL: http://localhost:#{port}/function/dummy_function
200 OK
EOS
begin
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml")
assert_equal expected, output
commit = Utils.popen_read("git rev-list -1 HEAD").chomp
output = shell_output("#{bin}/faas-cli version")
assert_match commit, output.chomp
ensure
Process.kill("TERM", pid)
Process.wait(pid)
end
end
end