85 lines
2.8 KiB
Ruby
85 lines
2.8 KiB
Ruby
class FaasCli < Formula
|
|
desc "CLI for templating and/or deploying FaaS functions"
|
|
homepage "https://docs.get-faas.com/"
|
|
url "https://github.com/openfaas/faas-cli.git",
|
|
:tag => "0.11.6",
|
|
:revision => "49d9f888a6e06b4e2cfdf542cfbf6dde2ebed7d7"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "b055f71ed48683b2292900b58a0c0d0d72daedf37b8b4bc1207d9bfa262db2a3" => :catalina
|
|
sha256 "6d6ccf1942e72b3ba0faf00392a7669c0997bdf79d2ad1183e2e53db79a16ad2" => :mojave
|
|
sha256 "62efdac6b03844208c319d20e9a861e65b741671644e85b7e1b8f38da1bb9072" => :high_sierra
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
|
|
def install
|
|
ENV["XC_OS"] = "darwin"
|
|
ENV["XC_ARCH"] = "amd64"
|
|
ENV["GOPATH"] = buildpath
|
|
(buildpath/"src/github.com/openfaas/faas-cli").install buildpath.children
|
|
cd "src/github.com/openfaas/faas-cli" do
|
|
project = "github.com/openfaas/faas-cli"
|
|
commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp
|
|
system "go", "build", "-ldflags",
|
|
"-s -w -X #{project}/version.GitCommit=#{commit} -X #{project}/version.Version=#{version}", "-a",
|
|
"-installsuffix", "cgo", "-o", bin/"faas-cli"
|
|
bin.install_symlink "faas-cli" => "faas"
|
|
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 <<~EOS
|
|
provider:
|
|
name: openfaas
|
|
gateway: http://localhost:#{port}
|
|
network: "func_functions"
|
|
|
|
functions:
|
|
dummy_function:
|
|
lang: python
|
|
handler: ./dummy_function
|
|
image: dummy_image
|
|
EOS
|
|
|
|
begin
|
|
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml 2>&1", 1)
|
|
assert_match "stat ./template/python/template.yml", output
|
|
|
|
assert_match "ruby", shell_output("#{bin}/faas-cli template pull 2>&1")
|
|
assert_match "node", shell_output("#{bin}/faas-cli new --list")
|
|
|
|
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml")
|
|
assert_match "Function dummy_function already exists, attempting rolling-update", output
|
|
assert_match "Deployed. 200 OK", output
|
|
|
|
stable_resource = stable.instance_variable_get(:@resource)
|
|
commit = stable_resource.instance_variable_get(:@specs)[:revision]
|
|
faas_cli_version = shell_output("#{bin}/faas-cli version")
|
|
assert_match /\s#{commit}$/, faas_cli_version
|
|
assert_match /\s#{version}$/, faas_cli_version
|
|
ensure
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|