From e271837accebd30d16d6f33e2f48d54803b69538 Mon Sep 17 00:00:00 2001 From: Andres Date: Fri, 24 Nov 2017 13:30:36 +0100 Subject: [PATCH] kubeless 0.3.0 (new formula) Closes #19506. Signed-off-by: ilovezfs --- Formula/kubeless.rb | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Formula/kubeless.rb diff --git a/Formula/kubeless.rb b/Formula/kubeless.rb new file mode 100644 index 0000000000..d19e283ed6 --- /dev/null +++ b/Formula/kubeless.rb @@ -0,0 +1,77 @@ +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" + + 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