77 lines
2.2 KiB
Ruby
77 lines
2.2 KiB
Ruby
class FaasCli < Formula
|
|
desc "CLI for templating and/or deploying FaaS functions"
|
|
homepage "http://docs.get-faas.com/"
|
|
url "https://github.com/alexellis/faas-cli.git",
|
|
:tag => "0.4.9",
|
|
:revision => "b877c56f07d5b0ab6c417cb9eeeb06126e58031a"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "20233f2d004b05fb7a25ecf7f5b0b9ebe6918ba9d4508a9ea05c1b544d86e90c" => :sierra
|
|
sha256 "c80c6d26e117314751efea6e6d8bb01b54e6ef5a28ef147fb9bd8ea9ebce3eb3" => :el_capitan
|
|
sha256 "8b47b9a439beab9950e16a5ae43145753a70270347e0d53d808bb1f1c633543c" => :yosemite
|
|
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", "-X main.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 -action deploy -yaml test.yml")
|
|
assert_equal expected, output.chomp
|
|
ensure
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|