forked from nuclio/nuclio
-
Notifications
You must be signed in to change notification settings - Fork 0
429 lines (352 loc) · 12.7 KB
/
ci.yaml
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# Copyright 2023 The Nuclio Authors.
#
# Licensed 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.
#
name: CI
on:
pull_request:
branches:
- development
- "[0-9]+.[0-9]+.x"
paths-ignore:
- 'docs/**'
- 'README.md'
- 'README_zh.md'
# Run CI also on push to master
push:
branches:
- master
env:
REPO: quay.io
CACHE_REPO: ghcr.io
REPO_NAME: nuclio
CACHE_REPO_NAME: ${{ github.repository_owner }}
NUCLIO_LABEL: ${{ github.run_number }}
NAMESPACE: nuclio
NUCLIO_GO_TEST_TIMEOUT: "30m"
DOCKER_BUILDKIT: 1
GITHUB_ACTIONS_BOT_NAME: github-actions[bot]
GITHUB_ACTIONS_BOT_EMAIL: github-actions[bot]@users.noreply.github.com
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- name: Ensure go test files are build annotated
run: make ensure-test-files-annotated
- name: Lint
run: make lint
check-nuctl-docs:
name: Check Nuctl Docs
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- name: Generate Nuctl docs
run: make generate-nuctl-docs
- name: Get Nuctl docs path
id: get-nuctl-docs-path
run: echo "NUCTL_DOCUMENTATION_PATH=$(make print-nuctl-docs-path | tail -n 1)" >> $GITHUB_ENV
- name: Check Nuctl docs changes
run: |
git config --global user.name ${{ env.GITHUB_ACTIONS_BOT_NAME }}
git config --global user.email ${{ env.GITHUB_ACTIONS_BOT_EMAIL }}
if [[ -n $(git status --porcelain ${{ env.NUCTL_DOCUMENTATION_PATH }}) ]]; then
echo "::error::Documentation needs to be regenerated. Please run 'make generate-nuctl-docs' and commit the changes."
echo "Differences between current and generated state:"
git diff ${{ env.NUCTL_DOCUMENTATION_PATH }}
exit 1
else
echo "No changes in nuctl documentation."
fi
check-copyright-license:
name: Check copyright and license
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Check License Lines
run: |
deno run --allow-read https://deno.land/x/[email protected]/main.ts
- name: Instructions For Adding Copyright
if: ${{ failure() }}
run: |
echo "
Please add the following lines to the top of your code as a comment:
/*
Copyright 2023 The Nuclio Authors.
Licensed 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.
*/
"
test_short:
name: Test short
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- name: Run unit test
run: |
make test-unit
build_nuctl:
name: Build nuctl
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- name: Build
run: |
make nuctl
# make nuctl-bin
env:
NUCLIO_NUCTL_CREATE_SYMLINK: false
# TODO: uncomment once a fix for make nuctl-bin is found
# - name: Ensure version
# run: |
# ./nuctl-$NUCLIO_LABEL-linux-amd64 version
build_docker_images:
name: Build docker images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.CACHE_REPO }}
username: ${{ env.CACHE_REPO_NAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Freeing up disk space
run: "${GITHUB_WORKSPACE}/hack/scripts/ci/free-space.sh"
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- name: Build
run: |
make docker-images
env:
NUCLIO_DOCKER_REPO: ${{ env.REPO }}/${{ env.REPO_NAME }}
NUCLIO_CACHE_REPO: ${{ env.CACHE_REPO }}/${{ env.CACHE_REPO_NAME }}
# Clean build leftovers
- name: Post build cleanup
run: docker system prune --force
- name: Save
run: make save-docker-images
- name: Upload
uses: actions/upload-artifact@v3
with:
name: nuclio-docker-images
path: nuclio-docker-images-*.tar.gz
test_k8s_nuctl:
name: Test Kubernetes nuctl
runs-on: ubuntu-latest
needs:
- build_docker_images
steps:
- uses: actions/checkout@v3
- name: Freeing up disk space
run: "${GITHUB_WORKSPACE}/hack/scripts/ci/free-space.sh"
- uses: azure/setup-helm@v3
with:
version: "v3.6.3"
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- uses: manusa/[email protected]
with:
minikube version: "v1.31.2"
kubernetes version: "v1.27.5"
driver: docker
github token: ${{ github.token }}
start args: "--addons registry --addons ingress"
# TODO: run on containerd as well
container runtime: docker
- name: Post minikube setup
run: |
# redirect $(minikube ip):5000 -> localhost:5000
docker run --rm --detach --network=host alpine ash -c "apk add socat && socat TCP-LISTEN:5000,reuseaddr,fork TCP:$(minikube ip):5000"
minikube kubectl -- config view --flatten > kubeconfig_flatten
- name: Fetch nuclio docker images
uses: actions/download-artifact@v3
with:
name: nuclio-docker-images
- name: Load nuclio docker images
run: |
# load nuclio docker images to host docker
make load-docker-images
# activate minikube docker
eval $(minikube -p minikube docker-env)
# load nuclio docker images to minikube
make load-docker-images
rm nuclio-docker-images*.tar.gz
- name: Export env
run: |
echo "NUCTL_EXTERNAL_IP_ADDRESSES=$(minikube ip)" >> $GITHUB_ENV
echo "NUCTL_REGISTRY=localhost:5000" >> $GITHUB_ENV
echo "NUCLIO_DASHBOARD_DEFAULT_ONBUILD_REGISTRY_URL=$REPO" >> $GITHUB_ENV
echo "NUCTL_NAMESPACE=$NAMESPACE" >> $GITHUB_ENV
echo "KUBECONFIG=$(pwd)/kubeconfig_flatten" >> $GITHUB_ENV
echo "NUCLIO_TEST_KUBE_DEFAULT_INGRESS_HOST=nuclio-test-function-host.info" >> $GITHUB_ENV
echo "NUCTL_DEFAULT_SERVICE_TYPE=NodePort" >> $GITHUB_ENV
echo "PULL_POLICY=Never" >> $GITHUB_ENV
- name: Install nuclio helm chart
run: |
minikube kubectl -- create namespace ${NAMESPACE}
cat test/k8s/ci_assets/helm_values.yaml \
| envsubst \
| helm install --debug --wait --namespace ${NAMESPACE} -f - nuclio hack/k8s/helm/nuclio/
- name: Run nuctl k8s tests
run: |
# write function host to /etc/hosts
echo "${NUCTL_EXTERNAL_IP_ADDRESSES} ${NUCLIO_TEST_KUBE_DEFAULT_INGRESS_HOST}" | sudo tee -a /etc/hosts
# run test
make test-k8s-nuctl
- name: Output some logs in case of failure
if: ${{ failure() }}
# add set -x to print commands before executing to make logs reading easier
run: |
set -x
minikube ip
minikube logs
minikube kubectl -- --namespace ${NAMESPACE} logs -l app=nuclio,release=nuclio --tail=-1
minikube kubectl -- --namespace ${NAMESPACE} get all
minikube kubectl -- --namespace ${NAMESPACE} get all -o yaml
minikube kubectl -- --namespace ${NAMESPACE} describe pods
minikube kubectl -- --namespace ${NAMESPACE} get cm
minikube kubectl -- --namespace ${NAMESPACE} get cm -o yaml
minikube kubectl -- --namespace ${NAMESPACE} get secrets
minikube kubectl -- --namespace ${NAMESPACE} get secrets -o yaml
minikube kubectl -- --namespace ${NAMESPACE} get pvc
minikube kubectl -- --namespace ${NAMESPACE} get pv
set +x
test_docker_nuctl:
name: Test Docker nuctl
runs-on: ubuntu-latest
needs:
- build_docker_images
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- name: Fetch nuclio docker images
uses: actions/download-artifact@v3
with:
name: nuclio-docker-images
- name: Load nuclio docker images
run: |
make load-docker-images
rm nuclio-docker-images*.tar.gz
- name: Run nuctl docker tests
run: |
make test-docker-nuctl
test_k8s:
runs-on: ubuntu-latest
needs:
- build_docker_images
strategy:
fail-fast: false
matrix:
test-target: [test-functions-k8s-undockerized, test-k8s-undockerized]
name: ${{ matrix.test-target == 'test-functions-k8s-undockerized' && 'Test Functions Kubernetes' || 'Test Kubernetes' }}
steps:
- uses: actions/checkout@v3
- uses: azure/setup-helm@v3
with:
version: "v3.6.3"
- uses: actions/setup-go@v3
with:
cache: true
go-version-file: go.mod
- uses: manusa/[email protected]
with:
minikube version: "v1.31.2"
kubernetes version: "v1.27.5"
driver: docker
github token: ${{ github.token }}
start args: "--addons registry --addons ingress"
# TODO: run on containerd as well
container runtime: docker
- name: Post minikube setup
run: |
# redirect $(minikube ip):5000 -> localhost:5000
docker run --rm --detach --network=host alpine ash -c "apk add socat && socat TCP-LISTEN:5000,reuseaddr,fork TCP:$(minikube ip):5000"
minikube kubectl -- config view --flatten > kubeconfig_flatten
- name: Fetch nuclio docker images
uses: actions/download-artifact@v3
with:
name: nuclio-docker-images
- name: Load nuclio docker images
run: |
make load-docker-images
rm nuclio-docker-images*.tar.gz
- name: Export env
run: |
echo "NUCLIO_EXTERNAL_IP_ADDRESS=$(minikube ip)" >> $GITHUB_ENV
echo "NUCLIO_TEST_REGISTRY_URL=localhost:5000" >> $GITHUB_ENV
echo "NUCLIO_TEST_KUBECONFIG=$(pwd)/kubeconfig_flatten" >> $GITHUB_ENV
echo "NUCLIO_TEST_KUBE_DEFAULT_INGRESS_HOST=nuclio-test-function-host.info" >> $GITHUB_ENV
- name: Install nuclio helm chart
run: |
# create namespace
minikube kubectl -- create namespace ${NAMESPACE}
# install helm chart
./test/k8s/ci_assets/install_nuclio_crds.sh
- name: Write ingress host to /etc/hosts
run: |
echo "${NUCLIO_EXTERNAL_IP_ADDRESS} ${NUCLIO_TEST_KUBE_DEFAULT_INGRESS_HOST}" | sudo tee -a /etc/hosts
- name: Run k8s tests
run: NUCLIO_K8S_TEST_MAKE_TARGET=${{ matrix.test-target }} make test-k8s
test_python:
name: Test python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run python test
run: |
make test-python
test_nodejs:
name: Test NodeJS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run NodeJS test
run: |
make test-nodejs