homebrew-core/Formula/faas-cli.rb

88 lines
2.8 KiB
Ruby

class FaasCli < Formula
desc "CLI for templating and/or deploying FaaS functions"
homepage "https://www.openfaas.com/"
url "https://github.com/openfaas/faas-cli.git",
tag: "0.13.6",
revision: "6b5e7a14a598527063c7c05fb4187739b6eb6d38"
license "MIT"
head "https://github.com/openfaas/faas-cli.git"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "84f5b5e6ffb0d4c685e015f72cf0167616873d37186d9483c372c65c2dde9232"
sha256 cellar: :any_skip_relocation, big_sur: "5aca9417e0d30b91227504796f05ee29b5dfd06eaed231d82370653f527e6532"
sha256 cellar: :any_skip_relocation, catalina: "723c6ba6da5ee6061e2ddac21893e7802bbc63382ff3b84439155429e2b1a9f2"
sha256 cellar: :any_skip_relocation, mojave: "7711834078bd3455e264fb518ca7aeb1fd1493ac7e91de312d16a48d37a4180a"
end
depends_on "go" => :build
def install
ENV["XC_OS"] = "darwin"
ENV["XC_ARCH"] = "amd64"
project = "github.com/openfaas/faas-cli"
ldflags = %W[
-s -w
-X #{project}/version.GitCommit=#{Utils.git_head}
-X #{project}/version.Version=#{version}
]
system "go", "build", "-ldflags", ldflags.join(" "), "-a", "-installsuffix", "cgo", "-o", bin/"faas-cli"
bin.install_symlink "faas-cli" => "faas"
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: https://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 --tls-no-verify -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 --tls-no-verify -yaml test.yml", 1)
assert_match "Deploying: dummy_function.", output
commit_regex = /[a-f0-9]{40}/
faas_cli_version = shell_output("#{bin}/faas-cli version")
assert_match commit_regex, faas_cli_version
assert_match version.to_s, faas_cli_version
ensure
Process.kill("TERM", pid)
Process.wait(pid)
end
end
end