81 lines
2.4 KiB
Ruby
81 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.15",
|
|
:revision => "ae3b137914f8478a4b7bf14db24df6677f9f278f"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "3c744e99931f023a14d1453af5f4458a10506866b8cf3101fd7adf9ae58cf559" => :high_sierra
|
|
sha256 "df46dc3087f46d95dedc4731c9caf0d431496b4d410659cf973d256b41da4479" => :sierra
|
|
sha256 "6a766d2791855fab19139c8c6cd7b9426b4a0adbc9afdb3c1b4cefded58a9cc9" => :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/alexellis/faas-cli").install buildpath.children
|
|
cd "src/github.com/alexellis/faas-cli" do
|
|
commit = Utils.popen_read("git rev-list -1 HEAD").chomp
|
|
system "go", "build", "-ldflags", "-s -w -X github.com/alexellis/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.
|
|
200 OK
|
|
URL: http://localhost:#{port}/function/dummy_function
|
|
EOS
|
|
|
|
begin
|
|
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml")
|
|
assert_equal expected, output.chomp
|
|
|
|
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
|