Skip to content

Commit 90d408f

Browse files
authored
Add Golang 1.21 Runtime (#193)
* Add Golang 1.21 Runtime * rename test cases Signed-off-by: Luke Roy <luke.roy@ibm.com> --------- Signed-off-by: Luke Roy <luke.roy@ibm.com>
1 parent 2cf75df commit 90d408f

11 files changed

Lines changed: 486 additions & 2 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ jobs:
9494
./gradlew :golang1.19:distDocker -PdockerRegistry=docker.io -PdockerImagePrefix=openwhisk -PdockerImageTag=$SHORT_COMMIT
9595
./gradlew :golang1.20:distDocker -PdockerRegistry=docker.io -PdockerImagePrefix=openwhisk -PdockerImageTag=nightly
9696
./gradlew :golang1.20:distDocker -PdockerRegistry=docker.io -PdockerImagePrefix=openwhisk -PdockerImageTag=$SHORT_COMMIT
97+
./gradlew :golang1.21:distDocker -PdockerRegistry=docker.io -PdockerImagePrefix=openwhisk -PdockerImageTag=nightly
98+
./gradlew :golang1.21:distDocker -PdockerRegistry=docker.io -PdockerImagePrefix=openwhisk -PdockerImageTag=$SHORT_COMMIT
9799
- name: Push Release Images
98100
if: ${{ env.PUSH_RELEASE == 'true' }}
99101
working-directory: runtime

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ vendor/
1717
# Go binary proxy
1818
common/proxy
1919
actionloop/proxy
20-
golang1.13/proxy
21-
golang1.15/proxy
20+
golang1.19/proxy
21+
golang1.20/proxy
22+
golang1.21/proxy
2223

2324
# Go test transient files
2425
openwhisk/_test/exec

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# limitations under the License.
1717
#
1818
-->
19+
# Latest
20+
- Add support for golang 1.21
21+
1922
# 1.22.0
2023
- Add tar.gz support to the go Proxy (#191)
2124
- Update net Package as temporary vulnerability fix (#190)

golang1.21/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# Do not fix the patch level for golang:1.21 to automatically get security fixes.
19+
FROM golang:1.21-bookworm
20+
21+
RUN echo "deb http://deb.debian.org/debian buster-backports main contrib non-free" \
22+
>>/etc/apt/sources.list &&\
23+
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections &&\
24+
apt-get update &&\
25+
# Upgrade installed packages to get latest security fixes if the base image does not contain them already.
26+
apt-get upgrade -y --no-install-recommends &&\
27+
apt-get install -y apt-utils &&\
28+
apt-get install -y \
29+
curl \
30+
jq \
31+
git \
32+
zip \
33+
vim && \
34+
apt-get -y install \
35+
librdkafka1 \
36+
librdkafka++1 &&\
37+
apt-get -y install \
38+
librdkafka-dev &&\
39+
# Cleanup apt data, we do not need them later on.
40+
apt-get clean && rm -rf /var/lib/apt/lists/* &&\
41+
go install github.com/go-delve/delve/cmd/dlv@latest &&\
42+
mkdir /action
43+
#make python 3 react as python
44+
RUN ln -s /usr/bin/python3 /usr/bin/python
45+
46+
WORKDIR /action
47+
ADD proxy /bin/proxy
48+
ADD bin/compile /bin/compile
49+
ADD lib/launcher.go /lib/launcher.go
50+
ENV OW_COMPILER=/bin/compile
51+
ENV OW_LOG_INIT_ERROR=1
52+
ENV OW_WAIT_FOR_ACK=1
53+
ENV OW_EXECUTION_ENV=openwhisk/action-golang-v1.21
54+
ENTRYPOINT [ "/bin/proxy" ]

golang1.21/Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
IMG=action-golang-v1.21
18+
19+
build:
20+
../gradlew distDocker
21+
22+
localbuild:
23+
GOOS=linux GOARCH=amd64 go build -o proxy -a -ldflags '-extldflags "-static"' ../main/proxy.go
24+
docker build -t $(IMG) .
25+
docker tag $(IMG) whisk/$(IMG)
26+
27+
push: build
28+
docker tag $(IMG) actionloop/$(IMG)
29+
docker push actionloop/$(IMG):nightly
30+
31+
clean:
32+
docker rmi -f whisk/$(IMG) actionloop/$(IMG)
33+
34+
debug: build
35+
docker run -p 8080:8080 \
36+
--name go-action --rm -ti --entrypoint=/bin/bash \
37+
-e OW_COMPILER=/mnt/bin/compile \
38+
-v $(PWD):/mnt whisk/$(IMG)
39+
40+
enter:
41+
docker exec -ti go-action bash
42+
43+
44+
.PHONY: build push clean debug enter

golang1.21/bin/compile

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/python -u
2+
"""Golang Action Compiler
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
"""
20+
from __future__ import print_function
21+
import os, os.path, sys, re, shutil, subprocess, traceback, codecs
22+
from os.path import dirname, exists
23+
from time import sleep
24+
25+
# write a file creating intermediate directories
26+
def write_file(file, body, executable=False):
27+
try: os.makedirs(dirname(file), mode=0o755)
28+
except: pass
29+
with open(file, mode="wb") as f:
30+
f.write(body)
31+
if executable:
32+
os.chmod(file, 0o755)
33+
34+
# copy a file eventually replacing a substring
35+
def copy_replace(src, dst, match=None, replacement=""):
36+
with open(src, 'rb') as s:
37+
body = s.read()
38+
if match:
39+
body = body.replace(match, replacement)
40+
write_file(dst, body)
41+
42+
43+
def sources(launcher, source_dir, main):
44+
func = main.capitalize()
45+
has_main = None
46+
47+
# copy the exec to exec.go
48+
# also check if it has a main in it
49+
src = "%s/exec" % source_dir
50+
dst = "%s/exec__.go" % source_dir
51+
if os.path.isfile(src):
52+
with codecs.open(src, 'r', 'utf-8') as s:
53+
with codecs.open(dst, 'w', 'utf-8') as d:
54+
body = s.read()
55+
has_main = re.match(r".*package\s+main\W.*func\s+main\s*\(\s*\)", body, flags=re.DOTALL)
56+
d.write(body)
57+
58+
# copy the launcher fixing the main
59+
if not has_main:
60+
dst = "%s/main__.go" % source_dir
61+
if os.path.isdir("%s/main" % source_dir):
62+
dst = "%s/main/main__.go" % source_dir
63+
with codecs.open(dst, 'w', 'utf-8') as d:
64+
with codecs.open(launcher, 'r', 'utf-8') as e:
65+
code = e.read()
66+
code = code.replace("Main", func)
67+
d.write(code)
68+
69+
def build(source_dir, target_dir):
70+
# compile...
71+
source_dir = os.path.abspath(source_dir)
72+
parent = dirname(source_dir)
73+
target = os.path.abspath("%s/exec" % target_dir)
74+
if os.environ.get("__OW_EXECUTION_ENV"):
75+
write_file("%s.env" % target, str.encode(os.environ["__OW_EXECUTION_ENV"]))
76+
77+
env = {
78+
"GOROOT": "/usr/local/go",
79+
"GOPATH": "/home/go",
80+
"PATH": os.environ["PATH"],
81+
"GOCACHE": "/tmp",
82+
"GO111MODULE": "on"
83+
}
84+
85+
gomod = "%s/go.mod" % source_dir
86+
with open(os.devnull, "w") as dn:
87+
if exists(gomod):
88+
ret = subprocess.call(["go", "mod", "download"], cwd=source_dir, env=env, stderr=dn, stdout=dn)
89+
if ret != 0:
90+
print("cannot download modules")
91+
return
92+
else:
93+
ret = subprocess.call(["go", "mod", "init", "exec"], cwd=source_dir, env=env, stdout=dn, stderr=dn)
94+
if ret != 0:
95+
print("cannot init modules")
96+
return
97+
98+
ldflags = "-s -w"
99+
gobuild = ["go", "build", "-o", target, "-ldflags", ldflags]
100+
if os.environ.get("__OW_EXECUTION_ENV"):
101+
ldflags += " -X main.OwExecutionEnv=%s" % os.environ["__OW_EXECUTION_ENV"]
102+
ret = subprocess.call(gobuild, cwd=source_dir, env=env)
103+
if ret != 0:
104+
print("failed", " ".join(gobuild), "\nin", source_dir, "\nenv", env)
105+
106+
def debug(source_dir, target_dir, port):
107+
source_dir = os.path.abspath(source_dir)
108+
target = os.path.abspath("%s/exec" % target_dir)
109+
if os.environ.get("__OW_EXECUTION_ENV"):
110+
write_file("%s/exec.env" % source_dir, os.environ["__OW_EXECUTION_ENV"])
111+
shutil.rmtree(target_dir)
112+
shutil.move(source_dir, target_dir)
113+
write_file(target, """#!/bin/bash
114+
cd "$(dirname $0)"
115+
export GOCACHE=/tmp
116+
export PATH=%s
117+
exec script -q -c '/go/bin/dlv debug --headless --listen=127.0.0.1:%s --continue --accept-multiclient --log-dest /tmp/delve.log'
118+
""" % (os.environ["PATH"], port) , True)
119+
120+
def main(argv):
121+
if len(argv) < 4:
122+
print("usage: <main-file> <source-dir> <target-dir>")
123+
sys.exit(1)
124+
125+
main = argv[1]
126+
source_dir = argv[2]
127+
target_dir = argv[3]
128+
launcher = dirname(dirname(argv[0]))+"/lib/launcher.go"
129+
sources(launcher, source_dir, main)
130+
131+
# if the debug port is present and not empty build with debug
132+
if os.environ.get("__OW_DEBUG_PORT"):
133+
debug(source_dir, target_dir, os.environ["__OW_DEBUG_PORT"])
134+
else:
135+
build(source_dir, target_dir)
136+
137+
if __name__ == '__main__':
138+
main(sys.argv)

golang1.21/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
ext.dockerImageName = 'action-golang-v1.21'
19+
apply from: '../gradle/docker.gradle'
20+
21+
distDocker.dependsOn 'staticBuildProxy'
22+
distDocker.finalizedBy('cleanup')
23+
24+
task staticBuildProxy(type: Exec) {
25+
environment CGO_ENABLED: "0"
26+
environment GOOS: "linux"
27+
environment GOARCH: "amd64"
28+
environment GO111MODULE: "on"
29+
30+
commandLine 'go', 'build',
31+
'-o', 'proxy', '-a',
32+
'-ldflags', '-extldflags "-static"',
33+
'../main/proxy.go'
34+
}
35+
36+
task cleanup(type: Delete) {
37+
delete 'proxy'
38+
}

0 commit comments

Comments
 (0)