114 lines
3.7 KiB
Ruby
114 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/archive/v1.0.0-alpha.8.tar.gz"
|
|
sha256 "a03c69d9a3e9abd4378628b35e8e3364011d51eeded5b1b31d879d22ef3da31d"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "acc63f3785304f4315f1081fa85a3716fa238c1037ffe6e5dbbd260c1ae07864" => :mojave
|
|
sha256 "bb6998e774e37318701a6a66c90946b0715eb02e28e824aeda6093e83cba988e" => :high_sierra
|
|
sha256 "2b3cb765a118f41d26459d3488ff848c1304bac2b40c7a7e499e854b65dff11e" => :sierra
|
|
sha256 "d8e5e3453bc4a1a2d18e3f65d9d7ca5ca59246c7bcf9fe39f066282b826cc859" => :el_capitan
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "kubernetes-cli" => :recommended
|
|
|
|
def install
|
|
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/pkg/version.Version=v#{version}
|
|
]
|
|
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
|