93 lines
3.1 KiB
Ruby
93 lines
3.1 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.7.3",
|
|
:revision => "54dc4d4499f9e9698ad1a9c459f60643a2b096a4"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "fdcc994ad2bed41b6340643c18b0b23a72e5cbb358b2584c356699a1be94b569" => :mojave
|
|
sha256 "6735cfd97df01b91a160d853d64adb82b26a2dceff6ec6fdc3a346731f3a860b" => :high_sierra
|
|
sha256 "f04ef5f4e0bd8a3460116738ad29d91ec0afc6e95f6d1de5dd50268b23f3a3c7" => :sierra
|
|
sha256 "d482170c04b2601c7dea09cf475af447fcfdd87379b310297c4f3ff06b762389" => :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
|
|
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: faas
|
|
gateway: http://localhost:#{port}
|
|
network: "func_functions"
|
|
|
|
functions:
|
|
dummy_function:
|
|
lang: python
|
|
handler: ./dummy_function
|
|
image: dummy_image
|
|
EOS
|
|
|
|
expected = <<~EOS
|
|
Deploying: dummy_function.
|
|
Function dummy_function already exists, attempting rolling-update.
|
|
|
|
Deployed. 200 OK.
|
|
URL: http://localhost:#{port}/function/dummy_function
|
|
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_equal expected, output.chomp
|
|
|
|
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
|