2017-11-24 12:30:36 +00:00
|
|
|
class Kubeless < Formula
|
|
|
|
desc "Kubernetes Native Serverless Framework"
|
|
|
|
homepage "https://github.com/kubeless/kubeless"
|
|
|
|
url "https://github.com/kubeless/kubeless.git",
|
2018-02-19 10:59:02 +00:00
|
|
|
:tag => "v0.4.0",
|
|
|
|
:revision => "4f4f531f6a1b685bf3842b26cfff5ca7eee533cc"
|
2017-11-24 12:30:36 +00:00
|
|
|
|
2017-12-01 17:17:11 +00:00
|
|
|
bottle do
|
|
|
|
cellar :any_skip_relocation
|
2018-02-19 11:41:59 +00:00
|
|
|
sha256 "121bc585de3fc20277f9ed7ca084be1204cc5f6c2d64ffe0cd0ff2d4e280e279" => :high_sierra
|
|
|
|
sha256 "100648f5201422b1ce7d6005384e338e03d7899ea4ad273f8fe5c4fe4d51f512" => :sierra
|
|
|
|
sha256 "a6042ea97e4729fd0171c81adf343d5d819832dae1c3cce2a759d1516443b30d" => :el_capitan
|
2017-12-01 17:17:11 +00:00
|
|
|
end
|
|
|
|
|
2017-11-24 12:30:36 +00:00
|
|
|
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[
|
2018-01-04 08:05:54 +00:00
|
|
|
-w -X github.com/kubeless/kubeless/cmd/kubeless/version.VERSION=v#{version}
|
|
|
|
-X github.com/kubeless/kubeless/cmd/kubeless/version.GITCOMMIT=#{commit}
|
2017-11-24 12:30:36 +00:00
|
|
|
]
|
|
|
|
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
|
2018-02-19 10:59:02 +00:00
|
|
|
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" }
|
|
|
|
}'
|
|
|
|
else
|
|
|
|
response = "OK"
|
|
|
|
end
|
2017-11-24 12:30:36 +00:00
|
|
|
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
|