homebrew-core/Formula/kubeless.rb
2017-12-28 01:39:00 -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.2",
:revision => "fef344fc1f9f0233bb6585953f802bfe906e51cd"
bottle do
cellar :any_skip_relocation
sha256 "b741dd3c6edd9533b02e40a7acbb682883a8ba9cc7bcc5bdc074834e0b9ad25d" => :high_sierra
sha256 "2b4ab4c3a1c853b9f9deb46c2320f36ea60aa9bb5ff35567382549255eb64ed4" => :sierra
sha256 "f15554f970c92445a5700b6925e3d63c3e69282142f6e54d18cd821ed4fed8ad" => :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