homebrew-core/Formula/kubeless.rb
2017-12-01 09:25:15 -08:00

84 lines
2.4 KiB
Ruby

class Kubeless < Formula
desc "Kubernetes Native Serverless Framework"
homepage "https://github.com/kubeless/kubeless"
url "https://github.com/kubeless/kubeless.git",
:tag => "v0.3.0",
:revision => "3103df24bccf67a71bef2ce792592d4ba9f09293"
bottle do
cellar :any_skip_relocation
sha256 "086108685fa144fbb9022e96c9a57122d5f44927f9839250f9a0666f3c3369d4" => :high_sierra
sha256 "37cad5fff6aae50658cbbd111b60a2fdfa7e635f036a8bfa6a233251b53ef203" => :sierra
sha256 "253c1467bd838ab1d545853c51c5b5baf439f7015dd7cd15da2ca6b30bdb2205" => :el_capitan
end
depends_on "go" => :build
depends_on "kubernetes-cli" => :recommended
def install
commit = Utils.popen_read("git rev-parse --short HEAD").chomp
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/kubeless/kubeless").install buildpath.children
cd "src/github.com/kubeless/kubeless" do
ldflags = %W[
-w -X github.com/kubeless/kubeless/version.VERSION=v#{version}
-X github.com/kubeless/kubeless/version.GITCOMMIT=#{commit}
]
system "go", "build", "-o", bin/"kubeless", "-ldflags", ldflags.join(" "),
"./cmd/kubeless"
prefix.install_metafiles
end
end
test do
require "socket"
server = TCPServer.new("127.0.0.1", 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/"kube-config").write <<~EOS
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: test
server: http://127.0.0.1:#{port}
name: test
contexts:
- context:
cluster: test
user: test
name: test
current-context: test
kind: Config
preferences: {}
users:
- name: test
user:
token: test
EOS
(testpath/"test.py").write "function_code"
begin
ENV["KUBECONFIG"] = testpath/"kube-config"
system bin/"kubeless", "function", "deploy", "--from-file", "test.py",
"--runtime", "python2.7", "--handler", "test.foo",
"test"
ensure
Process.kill("TERM", pid)
Process.wait(pid)
end
end
end