-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTaskfile.yml
326 lines (292 loc) · 10.2 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
version: "3"
dotenv: [.env]
vars:
DRY: ""
PUSH: ""
BASETAG: ""
REPO_PATH: apache
BASEIMG: registry.hub.docker.com/{{.REPO_PATH}}
COMMON_VER: common1.17.1
COMMON: "{{.BASEIMG}}/openserverless-runtime-common:{{.COMMON_VER}}"
EXPERIMENTAL_COMMON_VER: common1.18.4
EXPERIMENTAL_COMMON: "{{.BASEIMG}}/openserverless-runtime-common:{{.EXPERIMENTAL_COMMON_VER}}"
TAG:
sh: git describe --tags --abbrev=0 2>/dev/null || echo latest
J: "{}"
RUNTIMES: "go,nodejs,php,python,java"
EXPERIMENTAL_RUNTIMES: "python"
COMMIT_ID:
sh: git rev-parse --short HEAD
tasks:
default:
- task --list-all
setup:
# check we are running in ubuntu
- grep '^ID=' /etc/os-release | grep -i ubuntu
- if ! which python3 | grep python3 ; then echo "python3 not found" ; exit 1; fi
- sudo apt-get -y install python3-pip python3-virtualenv
- python3 -m pip install ipython watchdog requests cram
image-tag:
silent: true
cmds:
- git tag -d $(git tag)
- |
if test -n "{{.RT}}"
then git tag -f {{.RT}}.$(date +%y%m%d%H%M)
else git tag -f $(date +%y%m%d%H%M)
fi
- env PAGER= git tag
common-tag:
silent: true
cmds:
- git tag -d $(git tag)
- git tag -f common-$(date +%y%m%d%H%M)
- env PAGER= git tag
experimental-tag:
silent: true
cmds:
- git tag -d $(git tag)
- git tag -f experimental-$(date +%y%m%d%H%M)
- env PAGER= git tag
compile: go build -o proxy
test:
dir: openwhisk
cmds:
- go test -v
docker-login:
ignore_error: true
cmds:
- echo ${MY_DOCKER_HUB_TOKEN:-$DOCKER_HUB_TOKEN} | docker login -u ${MY_DOCKER_HUB_USER:-$DOCKER_HUB_USER} --password-stdin registry.hub.docker.com
- >
{{.DRY}} docker run -it --rm --privileged tonistiigi/binfmt --install all
- >
{{.DRY}} docker buildx create --name mybuilder --bootstrap --use
clean-images:
- docker images -a | grep ghcr.io/nuvolaris | awk '{print $3}' | xargs docker rmi -f
- yes | docker buildx prune
build-common:
dir: "runtime/common/{{.COMMON_VER}}"
cmds:
- |
if test -n "{{.PUSH}}"
then {{.DRY}} docker buildx build -t "{{.COMMON}}" --platform linux/amd64,linux/arm64 . --push
else {{.DRY}} docker buildx build -t "{{.COMMON}}" . --load
fi
build-runtime:
requires: { vars: [RT, VER] }
dir: "runtime/{{.RT}}/{{.VER}}"
cmds:
- |
BASEIMG=$(echo "${MY_DOCKER_HUB_REGISTRY:-$DOCKER_HUB_REGISTRY}")
RUNTIME="{{.BASEIMG}}/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}"
if test -n "{{.PUSH}}"
then
{{.DRY}} docker buildx build -t "$RUNTIME" --build-arg COMMON="{{.COMMON}}" --platform linux/amd64,linux/arm64 . --push
else {{.DRY}} docker buildx build -t "$RUNTIME" --build-arg COMMON="{{.COMMON}}" . --load
fi
echo "Built $RUNTIME"
build-lang:
desc: build images for one runtime
requires: { vars: [RT] }
vars:
DIRS:
sh: ls -d runtime/{{.RT}}/v* || echo ""
cmds:
- for: { var: DIRS }
task: build-runtime
vars:
VER: "{{base .ITEM}}"
build:
silent: true
requires: { vars: [TAG, RUNTIMES] }
vars:
RT_REGEX:
sh: echo "{{.RUNTIMES}}" | tr ',' '|'
SPECIFIC_RT:
sh: echo "{{.TAG}}" | grep -E -o '({{.RT_REGEX}})' || echo ''
cmds:
- |
if [ -z "{{.SPECIFIC_RT}}" ];
then
echo "==> BUILDING RUNTIMES {{.RUNTIMES}}"
for ITEM in `echo {{.RUNTIMES}} | tr ',' ' '`; do
echo "==> BUILDING $ITEM:{{.TAG}}"
task build-lang RT=$ITEM PUSH="{{.PUSH}}" DRY={{.DRY}}
done
else echo "Build {{.SPECIFIC_RT}}"
task build-lang RT={{.SPECIFIC_RT}} PUSH="{{.PUSH}}" DRY={{.DRY}}
fi
build-and-push:
- task build PUSH=y DRY={{.DRY}}
run:
desc: run a runtime
requires: { vars: [RT, VER] }
dir: "runtime/{{.RT}}/{{.VER}}"
cmds:
- >
{{.DRY}} docker run -p 8080:8080 -ti "{{.BASEIMG}}/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}"
debug:
desc: debug a runtime
requires: { vars: [RT, VER] }
dir: "runtime/{{.RT}}/{{.VER}}"
cmds:
- >
{{.DRY}} docker run -p 8080:8080 -ti
--entrypoint=/bin/bash -v $PWD:/mnt
-e OW_COMPILER=/mnt/bin/compile
"{{.BASEIMG}}/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}"
debug-experimental:
desc: debug a runtime
requires: { vars: [RT, VER] }
dir: "runtime/experimental/{{.RT}}/{{.VER}}"
cmds:
- >
BASEIMG="${MY_DOCKER_HUB_REGISTRY:-$DOCKER_HUB_REGISTRY}" ;
{{.DRY}} docker run -p 8080:8080 -ti
--entrypoint=/bin/bash -v $PWD:/mnt
-e OW_COMPILER=/mnt/bin/compile
"${BASEIMG}/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}"
init:
desc: intialize a runtime with a test
requires: { vars: [RT, VER, T] }
cmds:
- python3 packages/invoke.py init packages/{{.RT}}/{{.T}}.zip
invoke:
desc: invoke a runtime listening in port 8080, optionally with J=<json>
cmds:
- python3 packages/invoke.py run '{{.J}}'
render-runtime:
requires: { vars: [RT, VER] }
dir: "runtime/{{.RT}}/{{.VER}}"
cmds:
- |
BASEIMG=$(echo "${MY_DOCKER_HUB_REGISTRY:-$DOCKER_HUB_REGISTRY}")
RUNTIME="{{.BASEIMG}}/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}"
ENVVER=$(echo "{{.VER}}" | tr '.' '_' | tr '[:upper:][:lower:]' '[:lower:][:upper:]')
ENVRT=$(echo "{{.RT}}" | tr '[a-zA-Z]' '[A-Za-z]')
if test -n "{{.PUSH}}"
then
{{.DRY}} echo "OPS_RUNTIME_TAG_${ENVRT}_${ENVVER}={{.VER}}-{{.TAG}}" >> {{.BASE_DIR}}/runtimes.env
else {{.DRY}} echo "OPS_RUNTIME_TAG_${ENVRT}_${ENVVER}={{.VER}}-{{.TAG}}"
fi
echo "Rendered $RUNTIME"
render-lang:
desc: render images for one runtime
requires: { vars: [RT, BASE_DIR] }
vars:
DIRS:
sh: ls -d runtime/{{.RT}}/v* || echo ""
cmds:
- for: { var: DIRS }
task: render-runtime
vars:
VER: "{{base .ITEM}}"
BASE_DIR: "{{.BASE_DIR}}"
render:
silent: true
requires: { vars: [TAG, RUNTIMES] }
vars:
RT_REGEX:
sh: echo "{{.RUNTIMES}}" | tr ',' '|'
SPECIFIC_RT:
sh: echo "{{.TAG}}" | grep -E -o '({{.RT_REGEX}})' || echo ''
BASE_DIR:
sh: pwd
cmds:
- |
rm -f runtimes.env
echo "OPS_RUNTIME_PREFIX={{.REPO_PATH}}" >> runtimes.env
echo "==> RENDERING RUNTIMES {{.RUNTIMES}}"
for ITEM in `echo {{.RUNTIMES}} | tr ',' ' '`; do
echo "==> RENDERINGG $ITEM:{{.TAG}}"
task render-lang RT=$ITEM PUSH="{{.PUSH}}" DRY={{.DRY}} BASE_DIR="{{.BASE_DIR}}"
done
generate-runtimes:
silent: true
dotenv:
- runtimes.env
cmds:
- cat runtimes.json.tpl | envsubst > runtimes.json
render-runtimes:
silent: true
desc: generate a runtimes.json file with all the runtime corresponding to the current TAG
cmds:
- |
task render PUSH=y
task generate-runtimes
build-experimental-runtime:
requires: { vars: [RT, VER] }
dir: "runtime/experimental/{{.RT}}/{{.VER}}"
cmds:
- |
BASEIMG=$(echo "${MY_DOCKER_HUB_REGISTRY:-$DOCKER_HUB_REGISTRY}")
RUNTIME="$BASEIMG/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}"
PLATFORMS=$(cat platforms.txt)
if test -n "{{.PUSH}}"
then
{{.DRY}} docker buildx build -t "$RUNTIME" --build-arg COMMON="{{.EXPERIMENTAL_COMMON}}" --platform "$PLATFORMS" . --push
else {{.DRY}} docker buildx build -t "$RUNTIME" --build-arg COMMON="{{.EXPERIMENTAL_COMMON}}" . --load
fi
echo "Built $RUNTIME on platforms $PLATFORMS"
build-experimental-lang:
desc: build images for experimental runtimes
requires: { vars: [RT] }
vars:
DIRS:
sh: ls -d runtime/experimental/{{.RT}}/v* || echo ""
cmds:
- for: { var: DIRS }
task: build-experimental-runtime
vars:
VER: "{{base .ITEM}}"
build-experimental-runtimes:
silent: true
requires: { vars: [TAG, EXPERIMENTAL_RUNTIMES] }
vars:
RT_REGEX:
sh: echo "{{.EXPERIMENTAL_RUNTIMES}}" | tr ',' '|'
SPECIFIC_RT:
sh: echo "{{.TAG}}" | grep -E -o '({{.RT_REGEX}})' || echo ''
cmds:
- |
if [ -z "{{.SPECIFIC_RT}}" ];
then
echo "==> BUILDING RUNTIMES {{.EXPERIMENTAL_RUNTIMES}}"
for ITEM in `echo {{.EXPERIMENTAL_RUNTIMES}} | tr ',' ' '`; do
echo "==> BUILDING $ITEM:{{.TAG}}"
task build-experimental-lang RT=$ITEM PUSH="{{.PUSH}}" DRY={{.DRY}}
done
else echo "Build {{.SPECIFIC_RT}}"
task build-experimental-lang RT={{.SPECIFIC_RT}} PUSH="{{.PUSH}}" DRY={{.DRY}}
fi
debug-experimental-proxied-runtime:
desc: debug a runtime
requires: { vars: [RT, VER] }
cmds:
- >
BASEIMG="${MY_DOCKER_HUB_REGISTRY:-$DOCKER_HUB_REGISTRY}" ;
{{.DRY}} docker run -p 8081:8080 -e OW_ACTIVATE_PROXY_SERVER=1 -ti
--entrypoint=/mnt/proxy-experimental -v $PWD:/mnt
"${BASEIMG}/openserverless-runtime-{{.RT}}:{{.VER}}-{{.TAG}}" -debug
debug-experimental-proxy:
desc: debug a runtime
requires: { vars: [RT, VER] }
cmds:
- export GOOS=linux; go build -o proxy-experimental
- task: debug-experimental-proxied-runtime