Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Add proxy to ballerina service
Browse files Browse the repository at this point in the history
  • Loading branch information
anuruddhal committed Jun 5, 2018
1 parent 482aed8 commit 76ca944
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
6 changes: 5 additions & 1 deletion docker/runtime/ballerina/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ USER 1000

WORKDIR /kubeless

CMD [ "ballerina", "run", "kubeless_run.balx"]
ENV FUNC_PROCESS="ballerina run kubeless_run.balx"

ADD proxy /

CMD [ "/proxy" ]
2 changes: 1 addition & 1 deletion docker/runtime/ballerina/Dockerfile.init
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ballerina/ballerina-platform:0.970.1

USER 1000

# Install controller
# Install controller & Kubeless type definitions
ADD kubeless_run.tpl.bal /ballerina/files/src/
ADD kubeless/kubeless.bal /ballerina/files/kubeless/

Expand Down
1 change: 1 addition & 0 deletions docker/runtime/ballerina/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ init-image:
docker build -f Dockerfile.init -t kubeless/ballerina-init:0.970.1 .

runtime-image:
env GOOS=linux GOARCH=amd64 go build $$GOPATH/src/github.com/kubeless/kubeless/pkg/function-proxy/proxy.go
docker build -f Dockerfile -t kubeless/ballerina:0.970.1 .

push-init:
Expand Down
30 changes: 14 additions & 16 deletions docker/runtime/ballerina/kubeless_run.tpl.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2017 Bitnami
// Copyright (c) 2017-2018 Bitnami

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,30 +20,30 @@ import kubeless;

// A service endpoint represents a listener
endpoint http:Listener listener {
// Read listner port via ENV.
port:config: getAsInt("FUNC_PORT", default = 8080)
//Listner port is 8090 redirected by proxy
port: 8090
};

@http:ServiceConfig {
basePath: "/"
basePath: "/",
compression: "NEVER"
}

service<http:Service> controller bind listener {
//Initialize context from environment variables
kubeless:Context context = {
function_name: config:getAsString("FUNC_HANDLER"),
time_out: config:getAsString("FUNC_TIMEOUT"),
runtime: config:getAsString("FUNC_RUNTIME"),
memory_limit: config:getAsString("FUNC_MEMORY_LIMIT")
};

@http:ResourceConfig {
methods: ["GET", "POST", "DELETE", "PATCH"],
methods: ["GET", "POST", "DELETE", "PATCH", "PUT"],
path: "/"
}
handler(endpoint caller, http:Request request) {
kubeless:Context context = {};
kubeless:Event event = {};

//Read environment variables and set them to context
context.function_name = config:getAsString("FUNC_HANDLER");
context.time_out = config:getAsString("FUNC_TIMEOUT");
context.runtime = config:getAsString("FUNC_RUNTIME");
context.memory_limit = config:getAsString("FUNC_MEMORY_LIMIT");

//Read requests and set them to event
match request.getPayloadAsString() {
string payload => {
Expand Down Expand Up @@ -80,8 +80,7 @@ service<http:Service> controller bind listener {
response_payload = e.message;
}
}
response.setTextPayload(response_payload);

response.setPayload(response_payload);
// Send a response back to caller
// Errors are ignored with '_'
// -> indicates a synchronous network-bound call
Expand All @@ -103,5 +102,4 @@ service<http:Service> controller bind listener {
// -> indicates a synchronous network-bound call
_ = caller->respond(response);
}

}
4 changes: 3 additions & 1 deletion pkg/langruntime/langruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
"google.golang.org/appengine/file"
)

// Langruntimes struct for getting configmap
Expand Down Expand Up @@ -313,9 +314,10 @@ func (l *Langruntimes) GetCompilationContainer(runtime, funcName string, install
"mvn package > /dev/termination-log 2>&1 && mvn install > /dev/termination-log 2>&1"
case strings.Contains(runtime, "ballerina"):
command = fmt.Sprintf(
"mkdir -p /kubeless/kubeless/ && mkdir -p /kubeless/func/ && "+
"mkdir -p /kubeless/kubeless/ /kubeless/func/ && "+
"cp -r /ballerina/files/kubeless/*.bal /kubeless/kubeless/ && "+
"cp -r /kubeless/*.bal /kubeless/func/ && "+
"touch /kubeless/kubeless.toml && "+
"cp -r /ballerina/files/src/kubeless_run.tpl.bal /kubeless/ && "+
"sed 's/<<FUNCTION>>/%s/g' /kubeless/kubeless_run.tpl.bal > /kubeless/kubeless_run.bal && "+
"rm /kubeless/kubeless_run.tpl.bal && "+
Expand Down

0 comments on commit 76ca944

Please sign in to comment.