homebrew-core/Formula/kubeless.rb
2018-04-20 10:23:12 +10:00

116 lines
3.7 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.6.0",
:revision => "3bec4b65f29d830bd6709abb07e00f11fe54d646"
bottle do
cellar :any_skip_relocation
sha256 "98cf8441e9266b034e2fd70a9fca2cf0d39fe9800b9ff652d41ada035aa4932d" => :high_sierra
sha256 "2fdce4174d8be72c65ab44752c934f801e5583871a555b4e04900a60fc46058c" => :sierra
sha256 "4e6dd1c7aed374a7f41f88d59e2e0a623f5bb54255055112df03a28a0ad1b278" => :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/cmd/kubeless/version.VERSION=v#{version}
-X github.com/kubeless/kubeless/cmd/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
request = socket.gets
request_path = request.split(" ")[1]
if request_path == "/api/v1/namespaces/kubeless/configmaps/kubeless-config"
response = '{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": { "name": "kubeless-config", "namespace": "kubeless" },
"data": {
"runtime-images": "[{' \
'\"ID\": \"python\",' \
'\"versions\": [{' \
'\"name\": \"python27\",' \
'\"version\": \"2.7\",' \
'\"httpImage\": \"kubeless/python\"' \
"}]" \
'}]"
}
}'
elsif request_path == "/apis/kubeless.io/v1beta1/namespaces/default/functions"
response = '{
"apiVersion": "kubeless.io/v1beta1",
"kind": "Function",
"metadata": { "name": "get-python", "namespace": "default" }
}'
elsif request_path == "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/functions.kubeless.io"
response = '{
"apiVersion": "apiextensions.k8s.io/v1beta1",
"kind": "CustomResourceDefinition",
"metadata": { "name": "functions.kubeless.io" }
}'
else
response = "OK"
end
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