Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit bda5601

Browse files
author
Sameer Naik
authored
Merge pull request #57 from triggermesh/add-ci
implement ci
2 parents aa3b33b + 0ef778e commit bda5601

40 files changed

+324
-125
lines changed

.circleci/config.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: 2.1
2+
3+
orbs:
4+
go: circleci/go@1
5+
gcp-cli: circleci/gcp-cli@1
6+
7+
jobs:
8+
build:
9+
executor:
10+
name: gcp-cli/default
11+
steps:
12+
- checkout
13+
- gcp-cli/install
14+
- gcp-cli/initialize
15+
- run:
16+
name: Building docker image
17+
command: make -j6 cloudbuild-test
18+
19+
publish-image:
20+
executor:
21+
name: gcp-cli/google
22+
steps:
23+
- checkout
24+
- gcp-cli/initialize
25+
- run:
26+
name: Publishing docker image
27+
command: IMAGE_SHA=${CIRCLE_SHA1} IMAGE_TAG=${CIRCLE_TAG:-latest} make -j6 cloudbuild
28+
29+
release:
30+
executor:
31+
name: go/default
32+
tag: '1.15'
33+
steps:
34+
- checkout
35+
- run:
36+
name: Installing github-release tool
37+
command: go get github.com/meterup/github-release
38+
- run:
39+
name: Creating github release
40+
command: |
41+
PRE_RELEASE=${CIRCLE_TAG/${CIRCLE_TAG%-rc[0-9]*}/}
42+
github-release delete -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} 2>/dev/null ||:
43+
./scripts/release-notes.sh ${CIRCLE_TAG} | github-release release ${PRE_RELEASE:+-p} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} -d -
44+
45+
workflows:
46+
build-test-and-publish:
47+
jobs:
48+
- build:
49+
context: production
50+
filters:
51+
tags:
52+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
53+
- publish-image:
54+
context: production
55+
requires:
56+
- build
57+
filters:
58+
tags:
59+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
60+
branches:
61+
only: master
62+
- release:
63+
context: production
64+
requires:
65+
- publish-image
66+
filters:
67+
tags:
68+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
69+
branches:
70+
ignore: /.*/

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
REPO = knative-lambda-runtime
2+
REPO_DESC = TriggerMesh Knative Lambda Runtime
3+
RUNTIMES = java8 node10 node4 python27 python37 ruby25
4+
5+
BASE_DIR ?= $(CURDIR)
6+
7+
DOCKER ?= docker
8+
IMAGE_REPO ?= gcr.io/triggermesh
9+
IMAGE_TAG ?= latest
10+
IMAGE_SHA ?= $(shell git rev-parse HEAD)
11+
12+
.PHONY: help images cloudbuild-test cloudbuild
13+
14+
all: images
15+
16+
help: ## Display this help
17+
@awk 'BEGIN {FS = ":.*?## "; printf "\n$(REPO_DESC)\nUsage:\n make \033[36m<source>\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
18+
19+
IMAGES = $(foreach r,$(RUNTIMES),$(r).image)
20+
images: $(IMAGES) ## Build the Docker images
21+
$(IMAGES): %.image:
22+
docker build -t $(IMAGE_REPO)/knative-lambda-$* $*
23+
24+
CLOUDBUILD_TEST = $(foreach r,$(RUNTIMES),$(r).cloudbuild-test)
25+
cloudbuild-test: $(CLOUDBUILD_TEST) ## Test container image build with Google Cloud Build
26+
$(CLOUDBUILD_TEST): %.cloudbuild-test:
27+
gcloud builds submit $* --config cloudbuild.yaml --substitutions _RUNTIME=knative-lambda-$*,COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=_
28+
29+
CLOUDBUILD = $(foreach r,$(RUNTIMES),$(r).cloudbuild)
30+
cloudbuild: $(CLOUDBUILD) ## Build and publish image to GCR
31+
$(CLOUDBUILD): %.cloudbuild:
32+
gcloud builds submit $* --config cloudbuild.yaml --substitutions _RUNTIME=knative-lambda-$*,COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=${IMAGE_TAG}

README.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ equivalent to adding `--registry-host knative.registry.svc.cluster.local` to the
1818
so that builds can run without registry authentication.
1919
To override, set `--registry-secret` according to [tm docs](https://github.com/triggermesh/tm#docker-registry).
2020

21-
### Concurrency
21+
### Concurrency
2222

2323
Concurrency in KLR represented by two components: parallel running [bootstrap](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) processes per container and Knative [container concurrency](https://github.com/knative/serving/blob/master/docs/spec/spec.md#revision) model. By default [AWS runtime interface](https://github.com/triggermesh/aws-custom-runtime) fires up 4 bootstrap processes (functions, in other words) and allows multiple concurrent requests (`containerConcurrency: 0`) to be handled by each container. Default concurrency configuration can be changed on function deployment or update using `tm deploy service` command parameters:
2424

@@ -38,7 +38,7 @@ NOTE: all examples below work with [Local Registry](https://github.com/triggerme
3838
1. Install runtime
3939

4040
```
41-
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/python-3.7/runtime.yaml
41+
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/python37/runtime.yaml
4242
```
4343

4444
2. Deploy [function](https://github.com/serverless/examples/tree/master/aws-python-simple-http-endpoint)
@@ -60,15 +60,15 @@ curl python-test.default.dev.triggermesh.io
6060
```
6161

6262

63-
To use Python 2.7 runtime simply replace version tag in step 1 and 2 with `python-2.7` and `knative-python27-runtime` accordingly.
63+
To use Python 2.7 runtime simply replace version tag in step 1 and 2 with `python27` and `knative-python27-runtime` accordingly.
6464

6565

6666
#### Nodejs
6767

6868
1. Install node 4.3 runtime
6969

7070
```
71-
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node-4.x/runtime.yaml
71+
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node4/runtime.yaml
7272
```
7373

7474
2. Deploy example function
@@ -110,10 +110,10 @@ EOF
110110
node -e "require('./handler').sayHelloAsync({}).then(h => console.log(h))"
111111
```
112112

113-
2. Install node-10.x runtime
113+
2. Install node10 runtime
114114

115115
```
116-
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node-10.x/runtime.yaml
116+
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node10/runtime.yaml
117117
```
118118

119119
3. Deploy function
@@ -171,7 +171,7 @@ func main() {
171171
2. Install Go runtime
172172

173173
```
174-
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/go-1.x/runtime.yaml
174+
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/go/runtime.yaml
175175
```
176176

177177
3. Deploy function
@@ -202,7 +202,7 @@ where `~/.ssh/id_rsa` is a path to SSH private key associated with your git acco
202202
1. Install Ruby 2.5 runtime
203203

204204
```
205-
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/ruby-2.5/runtime.yaml
205+
tm deploy task -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/ruby25/runtime.yaml
206206
```
207207

208208
2. Deploy example function
@@ -258,18 +258,17 @@ curl http://aws-java-sample-java-function.default.dev.triggermesh.io -d '{"event
258258
{"message":"Hello, the current time is Tue Apr 07 13:59:17 GMT 2020"}
259259
```
260260

261-
### Run in Docker
261+
### Run in Docker
262262

263263
For cases in which the use of additional components (tm CLI, Tekton, Knative, k8s) is undesirable, it is possible to build a KLR function as a standalone Docker container and run it in any environment. To do this, you should extract the Dockerfile from the runtime you are interested in, put it in the directory with your function, update the handler variable, and build the container. Here are Dockerfile definitions for all runtimes:
264264

265-
- [go](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/go-1.x/runtime.yaml#L44-L68)
266-
- [java](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/java8/runtime.yaml#L43-L53)
267-
- [node-10](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/node-10.x/runtime.yaml#L43-L48)
268-
- [node-4](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/node-4.x/runtime.yaml#L43-L48)
269-
- [python-2](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-2.7/runtime.yaml#L43-L50)
270-
- [python-3](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-3.7/runtime.yaml#L43-L50)
271-
- [ruby-2](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/ruby-2.5/runtime.yaml#L43-L47)
272-
265+
- [go](https://github.com/triggermesh/knative-lambda-runtime/blob/master/go/runtime.yaml#L44-L68)
266+
- [java](https://github.com/triggermesh/knative-lambda-runtime/blob/master/java8/runtime.yaml#L43-L53)
267+
- [node-10](https://github.com/triggermesh/knative-lambda-runtime/blob/master/node10/runtime.yaml#L43-L48)
268+
- [node-4](https://github.com/triggermesh/knative-lambda-runtime/blob/master/node4/runtime.yaml#L43-L48)
269+
- [python-2](https://github.com/triggermesh/knative-lambda-runtime/blob/master/python27/runtime.yaml#L43-L50)
270+
- [python-3](https://github.com/triggermesh/knative-lambda-runtime/blob/master/python37/runtime.yaml#L43-L50)
271+
- [ruby-2](https://github.com/triggermesh/knative-lambda-runtime/blob/master/ruby25/runtime.yaml#L43-L47)
273272

274273
Let's build a Python 3.7 function as an example:
275274

@@ -294,7 +293,7 @@ def endpoint(event, context):
294293
EOF
295294
```
296295

297-
2. Extract the runtime's [Dockerfile](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-3.7/runtime.yaml#L43-L50), store it in the same directory, and update the `_HANDLER` variable:
296+
2. Extract the runtime's [Dockerfile](https://github.com/triggermesh/knative-lambda-runtime/blob/master/python37/runtime.yaml#L43-L50), store it in the same directory, and update the `_HANDLER` variable:
298297

299298
```
300299
cat > Dockerfile <<EOF
@@ -313,11 +312,11 @@ The `_HANDLER` variable in most cases consists of the filename without the file
313312
```
314313
docker build -t python-klr-image .
315314
docker run -d --rm --name python-klr-container python-klr-image
316-
# following command will work if you use Docker bridge network and you have jq tool
317-
# otherwise, you should get the container address manually
315+
# following command will work if you use Docker bridge network and you have jq tool
316+
# otherwise, you should get the container address manually
318317
curl $(docker inspect python-klr-container | jq .[].NetworkSettings.Networks.bridge.IPAddress -r):8080
319318
```
320-
319+
321320
The response will contain a JSON document with the current time.
322321

323322
4. Cleanup:

cloudbuild.yaml

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
steps:
2-
## Build python37 runtime
3-
- name: 'gcr.io/cloud-builders/docker'
4-
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-python37:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-python37:latest', '-f' ,'./python-3.7/Dockerfile', '.' ]
52

6-
## Build python27 runtime
7-
- name: 'gcr.io/cloud-builders/docker'
8-
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-python27:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-python27:latest', '-f' ,'./python-2.7/Dockerfile', '.' ]
3+
- name: gcr.io/kaniko-project/executor:latest
4+
args:
5+
- --dockerfile=Dockerfile
6+
- --build-arg=VERSION=${_KANIKO_IMAGE_TAG}
7+
- --destination=gcr.io/$PROJECT_ID/${_RUNTIME}:${COMMIT_SHA}
8+
- --destination=gcr.io/$PROJECT_ID/${_RUNTIME}:${_KANIKO_IMAGE_TAG}
9+
- --cache-repo=gcr.io/$PROJECT_ID/${_RUNTIME}/cache
10+
- --cache=${_KANIKO_USE_BUILD_CACHE}
11+
- --no-push=${_KANIKO_NO_PUSH}
12+
- ${_KANIKO_EXTRA_ARGS}
13+
waitFor: ['-']
914

10-
## Build node4 runtime
11-
- name: 'gcr.io/cloud-builders/docker'
12-
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-node4:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-node4:latest', '-f' ,'./node-4.x/Dockerfile', '.' ]
15+
timeout: 600s
1316

14-
## Build node10 runtime
15-
- name: 'gcr.io/cloud-builders/docker'
16-
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-node10:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-node10:latest', '-f' ,'./node-10.x/Dockerfile', '.' ]
17+
substitutions:
18+
_RUNTIME:
19+
_KANIKO_IMAGE_TAG: latest
20+
_KANIKO_NO_PUSH: 'false'
21+
_KANIKO_USE_BUILD_CACHE: 'true'
22+
_KANIKO_EXTRA_ARGS:
1723

18-
## Build ruby25 runtime
19-
- name: 'gcr.io/cloud-builders/docker'
20-
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-ruby25:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-ruby25:latest', '-f' ,'./ruby-2.5/Dockerfile', '.' ]
24+
options:
25+
substitution_option: ALLOW_LOOSE
2126

22-
## Build java8 runtime
23-
- name: 'gcr.io/cloud-builders/docker'
24-
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-java8:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/knative-lambda-java8:latest', 'java8' ]
25-
26-
images:
27-
- 'gcr.io/$PROJECT_ID/knative-lambda-python37'
28-
- 'gcr.io/$PROJECT_ID/knative-lambda-python27'
29-
- 'gcr.io/$PROJECT_ID/knative-lambda-node4'
30-
- 'gcr.io/$PROJECT_ID/knative-lambda-node10'
31-
- 'gcr.io/$PROJECT_ID/knative-lambda-ruby25'
32-
- 'gcr.io/$PROJECT_ID/knative-lambda-java8'
27+
tags:
28+
- knative-lambda-runtime
File renamed without changes.

go-1.x/runtime.yaml renamed to go/runtime.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
- name: IMAGE
2222
description: Where to store resulting image
2323
- name: SSH_KEY
24-
description: SSH key
24+
description: SSH key
2525
default: "placeholder"
2626
- name: DIRECTORY
2727
description: The subdirectory of the workspace/repo
@@ -42,11 +42,11 @@ spec:
4242
cd /workspace/workspace/$(inputs.params.DIRECTORY)
4343
cat <<EOF > Dockerfile
4444
FROM golang:alpine
45-
# Skip known public key check to be able to pull from private repositories
45+
# Skip known public key check to be able to pull from private repositories
4646
ENV GIT_SSH_COMMAND "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
4747
RUN apk --no-cache add git ca-certificates openssh \
4848
&& go get github.com/triggermesh/aws-custom-runtime \
49-
&& go get github.com/triggermesh/knative-lambda-runtime/go-1.x \
49+
&& go get github.com/triggermesh/knative-lambda-runtime/go \
5050
&& go get github.com/golang/dep/...
5151
WORKDIR /go/src/handler
5252
COPY . .
@@ -63,7 +63,7 @@ spec:
6363
ENV LAMBDA_TASK_ROOT "/opt"
6464
ENV _HANDLER "handler"
6565
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
66-
COPY --from=0 /go/bin/go-1.x /opt/bootstrap
66+
COPY --from=0 /go/bin/go /opt/bootstrap
6767
COPY --from=0 /go/bin/ /opt
6868
ENTRYPOINT ["/opt/aws-custom-runtime"]
6969
EOF
@@ -73,8 +73,8 @@ spec:
7373
- --context=/workspace/workspace/$(inputs.params.DIRECTORY)
7474
- --dockerfile=Dockerfile
7575
- --destination=$(inputs.params.IMAGE)
76-
# Workaround not to use default config which requires gcloud credentials
77-
# to pull base image from public gcr registry
76+
# Workaround not to use default config which requires gcloud credentials
77+
# to pull base image from public gcr registry
7878
# https://groups.google.com/d/msg/kaniko-users/r5yoP_Ejm_c/ExoEXksDBAAJ
7979
env:
8080
- name: DOCKER_CONFIG

java8/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
.dockerignore
3+
4+
**/*.md
5+
**/.gitignore

java8/Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
FROM alpine:3 as downloader
2+
3+
RUN apk --no-cache add curl \
4+
&& DOWNLOAD_URL=$(curl -sSf https://api.github.com/repos/triggermesh/aws-custom-runtime/releases/latest | grep "browser_download_url.*-linux-amd64" | cut -d: -f 2,3 | tr -d \") \
5+
&& curl -sSfL ${DOWNLOAD_URL} -o /opt/aws-custom-runtime \
6+
&& chmod +x /opt/aws-custom-runtime
7+
18
FROM openjdk:8-jre-alpine
29

3-
COPY runtime /var/runtime
10+
RUN apk add --no-cache libc6-compat
411

5-
RUN apk update && apk add --no-cache libc6-compat curl \
6-
&& API_VERSION=$(curl -sI https://github.com/triggermesh/aws-custom-runtime/releases/latest | grep -i "Location:" | awk -F "/" '{print $NF}' | tr -d "\r") \
7-
&& curl -sL https://github.com/triggermesh/aws-custom-runtime/releases/download/${API_VERSION}/aws-custom-runtime > /var/runtime/mockserver \
8-
&& chmod +x /var/runtime/mockserver
12+
COPY runtime /var/runtime
13+
COPY --from=downloader /opt/aws-custom-runtime /var/runtime/mockserver
914

1015
ENV LD_LIBRARY_PATH /lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
1116
ENV LAMBDA_RUNTIME_DIR /var/runtime
@@ -23,4 +28,4 @@ ENTRYPOINT ["/usr/bin/java", \
2328
"-Xshare:auto", \
2429
"-XX:-TieredCompilation", \
2530
"-jar", \
26-
"/var/runtime/lib/LambdaJavaRTEntry-1.0.jar"]
31+
"/var/runtime/lib/LambdaJavaRTEntry-1.0.jar"]

node-10.x/Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

node-4.x/Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)