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

Commit

Permalink
Go Runtime with go mod (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
thspinto authored Jun 5, 2020
1 parent 61027c0 commit 4fcef10
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 169 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ kubecfg:
fi

kubeless: kubecfg
export BUILD_NUM=`curl -s https://circleci.com/api/v1.1/project/github/kubeless/kubeless/tree/master\?limit\=20\&offset\=5\&filter\=completed | jq '.[] | select(.workflows.job_name == "build") | .build_num' | head -n 1`; \
export KUBELESS_BIN_URL=`curl -s https://circleci.com/api/v1.1/project/github/kubeless/kubeless/$$BUILD_NUM/artifacts | jq -r '.[] | select(.path == "home/circleci/.go_workspace/bin/kubeless") | .url'`; \
curl -LO $$KUBELESS_BIN_URL; \
export LATEST_RELEASE=`curl -s https://api.github.com/repos/kubeless/kubeless/releases | jq -r '.[0].tag_name'`; \
curl -LO https://github.com/kubeless/kubeless/releases/download/$$LATEST_RELEASE/kubeless_linux-amd64.zip; \
unzip -p kubeless_linux-amd64.zip bundles/kubeless_linux-amd64/kubeless > kubeless
chmod +x kubeless; \
sudo mv kubeless /usr/local/bin; \
mkdir -p $$GOPATH/src/github.com/kubeless/; \
Expand All @@ -26,6 +26,6 @@ kubeless: kubecfg
kubecfg show -J $$HOME/project -o yaml kubeless.jsonnet > $$HOME/project/kubeless.yaml;

bootstrap: kubectl kubeless

test:
./script/integration-tests
27 changes: 0 additions & 27 deletions stable/golang/Dockerfile.1.11.init

This file was deleted.

27 changes: 0 additions & 27 deletions stable/golang/Dockerfile.1.12.init

This file was deleted.

11 changes: 11 additions & 0 deletions stable/golang/Dockerfile.1.13.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.13

# Prepare function environment
COPY /compile-function.sh /

# Install controller
COPY server /server
RUN chown 1000:1000 /server -R
WORKDIR /server

USER 1000
11 changes: 11 additions & 0 deletions stable/golang/Dockerfile.1.14.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.14

# Prepare function environment
COPY /compile-function.sh /

# Install controller
COPY server /server
RUN chown 1000:1000 /server -R
WORKDIR /server

USER 1000
27 changes: 0 additions & 27 deletions stable/golang/Dockerfile.init

This file was deleted.

6 changes: 0 additions & 6 deletions stable/golang/Gopkg.toml

This file was deleted.

59 changes: 29 additions & 30 deletions stable/golang/Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
init-image:
git clone https://github.com/kubeless/kubeless || true
git -C kubeless pull || true
docker build --no-cache -f Dockerfile.init -t kubeless/go-init:1.10 .
# Init images
init-image-1.13:
docker build --no-cache -f Dockerfile.1.14.init -t kubeless/go-init:1.13 .

init-image-1.11:
git clone https://github.com/kubeless/kubeless || true
git -C kubeless pull || true
docker build --no-cache -f Dockerfile.1.11.init -t kubeless/go-init:1.11 .
init-image-1.14:
docker build --no-cache -f Dockerfile.1.14.init -t kubeless/go-init:1.14 .

init-image-1.12:
git clone https://github.com/kubeless/kubeless || true
git -C kubeless pull || true
docker build --no-cache -f Dockerfile.1.12.init -t kubeless/go-init:1.12 .
init-image: init-image-1.13 init-image-1.14

runtime-image:
docker build --no-cache -f Dockerfile -t kubeless/go:1.10 .
# Runtime images
runtime-image-1.14:
docker build --no-cache -f Dockerfile -t kubeless/go:1.14 .

push-init:
docker push kubeless/go-init:1.10
runtime-image: runtime-image-1.14

push-init-1.11:
docker push kubeless/go-init:1.11
# Push images
push-init-1.13:
docker push kubeless/go-init:1.13

push-init-1.12:
docker push kubeless/go-init:1.12
push-init-1.14:
docker push kubeless/go-init:1.14

push-runtime:
docker push kubeless/go:1.10
push-init: push-init-1.13 push-init-1.14

push-runtime-1.14:
docker push kubeless/go:1.14

push-runtime: push-runtime-1.14

# Mandatory jobs
build-all: init-image runtime-image init-image-1.11 init-image-1.12
push-all: push-init push-runtime push-init-1.11 push-init-1.12
build-all: init-image runtime-image
push-all: push-init push-runtime

# Testing jobs
deploy: get-go get-go-custom-port timeout-go get-go-deps post-go
test: get-go-verify get-go-custom-port-verify timeout-go-verify get-go-deps-verify post-go-verify

get-go:
kubeless function deploy get-go --runtime go1.12 --handler handler.Foo --from-file examples/helloget.go
kubeless function deploy get-go --runtime go1.14 --handler handler.Foo --from-file examples/helloget.go

get-go-verify:
kubectl rollout status deployment/get-go && sleep 2
kubeless function call get-go |egrep Hello.world
kubeless function call get-go | egrep Hello.world

get-go-custom-port:
kubeless function deploy get-go-custom-port --runtime go1.10 --handler helloget.Foo --from-file examples/helloget.go --port 8083
kubeless function deploy get-go-custom-port --runtime go1.14 --handler helloget.Foo --from-file examples/helloget.go --port 8083

get-go-custom-port-verify:
kubectl rollout status deployment/get-go-custom-port && sleep 2
Expand All @@ -54,7 +53,7 @@ get-go-custom-port-verify:
timeout-go:
$(eval TMPDIR := $(shell mktemp -d))
printf 'package kubeless\nimport "github.com/kubeless/kubeless/pkg/functions"\nfunc Foo(event functions.Event, context functions.Context) (string, error) {\nfor{\n}\nreturn "", nil\n}' > $(TMPDIR)/hello-loop.js
kubeless function deploy timeout-go --runtime go1.10 --handler helloget.Foo --from-file $(TMPDIR)/hello-loop.js --timeout 4
kubeless function deploy timeout-go --runtime go1.14 --handler helloget.Foo --from-file $(TMPDIR)/hello-loop.js --timeout 4
rm -rf $(TMPDIR)

timeout-go-verify:
Expand All @@ -63,15 +62,15 @@ timeout-go-verify:
echo $(MSG) | egrep Request.timeout.exceeded

get-go-deps:
kubeless function deploy get-go-deps --runtime go1.10 --handler helloget.Hello --from-file examples/hellowithdeps.go --dependencies examples/Gopkg.toml
kubeless function deploy get-go-deps --runtime go1.14 --handler helloget.Hello --from-file examples/hellowithdeps.go --dependencies examples/go.mod

get-go-deps-verify:
kubectl rollout status deployment/get-go-deps && sleep 2
kubeless function call get-go-deps --data '{"hello": "world"}'
kubectl logs --tail=1000 -l function=get-go-deps | grep -q 'level=info msg=.*hello.*world'

post-go:
kubeless function deploy post-go --runtime go1.10 --handler hellowithdata.Handler --from-file examples/hellowithdata.go
kubeless function deploy post-go --runtime go1.14 --handler hellowithdata.Handler --from-file examples/hellowithdata.go

post-go-verify:
kubectl rollout status deployment/post-go && sleep 2
Expand Down
26 changes: 26 additions & 0 deletions stable/golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Golang runtime with go mod dependency management

Implement go runtime using go mod for dependencies.

## ☕ Usage

When used, `go.mod` must declare the module kubeless. Example:

```
module function
go 1.14
require (
...
)
```
## Braking change notice

This breaks compatibility with Go functions that use dep as package manager.

To use legacy version, replace the config map with the definition in `golang_legacy.jsonnet`

## TODO

- [ ] Release official docker images and update `golang.jsonnet`
14 changes: 10 additions & 4 deletions stable/golang/compile-function.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash
GO_VERSION="1.14"

set -e

# Copy function
if [ ! -s "/kubeless/go.mod" ]; then
rm /kubeless/go.mod
fi
cp /kubeless/* /server/function/

# Replace FUNCTION placeholder
sed "s/<<FUNCTION>>/${KUBELESS_FUNC_NAME}/g" $GOPATH/src/controller/kubeless.tpl.go > $GOPATH/src/controller/kubeless.go
# Remove vendored version of kubeless if exists
rm -rf $GOPATH/src/kubeless/vendor/github.com/kubeless/kubeless
sed "s/<<FUNCTION>>/${KUBELESS_FUNC_NAME}/g" /server/kubeless.go.tpl > /server/kubeless.go
# Build command
go build -o $KUBELESS_INSTALL_VOLUME/server $GOPATH/src/controller/kubeless.go > /dev/termination-log 2>&1
cd /server
GOOS=linux GOARCH=amd64 go build -o $KUBELESS_INSTALL_VOLUME/server .
4 changes: 0 additions & 4 deletions stable/golang/examples/Gopkg.toml

This file was deleted.

7 changes: 7 additions & 0 deletions stable/golang/examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module function

go 1.14

require (
github.com/sirupsen/logrus v1.6.0
)
48 changes: 9 additions & 39 deletions stable/golang/golang.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,36 @@
ID: "go",
versions: [
{
name: "go1.10",
version: "1.10",
name: "go1.13",
version: "1.13",
images: [{
phase: "compilation",
image: "kubeless/go-init@sha256:163f46d781301490436db334ed34845a08f9b5c39746932a5d93b4c11c4ad43b",
command: "/compile-function.sh"
}, {
phase: "installation",
image: "kubeless/go-init@sha256:163f46d781301490436db334ed34845a08f9b5c39746932a5d93b4c11c4ad43b",
command: "cd $GOPATH/src/kubeless && dep ensure > /dev/termination-log 2>&1"
}, {
phase: "runtime",
image: "kubeless/go@sha256:d2c5cfd3b7b31276d02ca22ddc7961aebe6050add4482b695ae3a686c76bad35"
}],
},
{
name: "go1.11",
version: "1.11",
images: [{
phase: "compilation",
image: "kubeless/go-init@sha256:e3592e7605608b620bc8f313c9b1e0e3ae4795bab8bdf1c01d53dd992ef316cd",
image: "kubeless/go-init:1.14@sha256:6dddf087c51c723511261ecc854efcf187ca395e499075a221f0459e79b6337d",
command: "/compile-function.sh",
env: {
GOCACHE: "$(KUBELESS_INSTALL_VOLUME)/.cache",
},
}, {
phase: "installation",
image: "kubeless/go-init@sha256:e3592e7605608b620bc8f313c9b1e0e3ae4795bab8bdf1c01d53dd992ef316cd",
command: "cd $GOPATH/src/kubeless && dep ensure > /dev/termination-log 2>&1",
env: {
GOCACHE: "$(KUBELESS_INSTALL_VOLUME)/.cache",
},
}, {
phase: "runtime",
image: "kubeless/go@sha256:d2c5cfd3b7b31276d02ca22ddc7961aebe6050add4482b695ae3a686c76bad35"
image: "kubeless/go@sha256:55759228714d7080b3dd858e56530d4e1f539d071906e88d88b454ee3b3c9b16"
}],
},
{
name: "go1.12",
version: "1.12",
name: "go1.14",
version: "1.14",
images: [{
phase: "compilation",
image: "kubeless/go-init@sha256:a669748f121755966e884455c9b6a978f1b92dca85f5bf53c1cf0aff76acb6b6",
image: "kubeless/go-init:1.14@sha256:403164254efabf735e98e73b7f6f65f14333ed792798c7c3d3d9a33ca91acf7a",
command: "/compile-function.sh",
env: {
GOCACHE: "$(KUBELESS_INSTALL_VOLUME)/.cache",
},
}, {
phase: "installation",
image: "kubeless/go-init@sha256:a669748f121755966e884455c9b6a978f1b92dca85f5bf53c1cf0aff76acb6b6",
command: "cd $GOPATH/src/kubeless && dep ensure > /dev/termination-log 2>&1",
env: {
GOCACHE: "$(KUBELESS_INSTALL_VOLUME)/.cache",
},
}, {
phase: "runtime",
image: "kubeless/go@sha256:d2c5cfd3b7b31276d02ca22ddc7961aebe6050add4482b695ae3a686c76bad35"
image: "kubeless/go@sha256:55759228714d7080b3dd858e56530d4e1f539d071906e88d88b454ee3b3c9b16"
}],
},
],
depName: "Gopkg.toml",
depName: "go.mod",
fileNameSuffix: ".go"
}
Loading

0 comments on commit 4fcef10

Please sign in to comment.