This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
376 lines (348 loc) · 12.6 KB
/
build.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
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
name: 🚀 Project build
on:
push:
pull_request:
release:
types: [published]
env:
CARGO_TERM_COLOR: always
jobs:
# ------------------ COMMON JOBS ------------------
build-core:
name: 🔨 Build Core
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/cache@v2
with:
path: |
core/.cache
key: build-core-${{ github.event_name }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build core in debug configuration
if: github.event_name != 'release'
run: make core-debug
- name: Build core in release configuration
if: github.event_name == 'release'
run: make core
- name: Fix permission for cache
run: sudo chmod -R 777 core/.cache
- uses: actions/upload-artifact@v2
with:
name: core-documentation
path: .artifacts/core-documentation
- uses: actions/upload-artifact@v2
with:
name: core-executable
path: .artifacts/core-executable
build-dashboard:
name: 🔨 Build Dashboard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: "14"
- name: Build dashboard
run: make dashboard
- uses: actions/upload-artifact@v2
with:
name: web-root
path: .artifacts/web-root
bundle-core:
name: 🐳 Push Core to GHCR
runs-on: ubuntu-latest
needs: [build-core, build-dashboard]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: core-executable
path: .artifacts/core-executable
- uses: actions/download-artifact@v2
with:
name: web-root
path: .artifacts/web-root
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/tilblechschmidt/webgrid/core
TAGS="${DOCKER_IMAGE}:sha-${GITHUB_SHA::7}"
echo "tags=${TAGS}" >> $GITHUB_ENV
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
chmod +x .artifacts/core-executable/webgrid
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push webgrid/core Docker image
uses: docker/build-push-action@v2
with:
context: .
file: distribution/docker/images/core/Dockerfile
tags: ${{ env.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ env.created }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Export docker image as artifact
run: |
docker save ${{ env.tags }} | gzip > core.tar.gz
- uses: actions/upload-artifact@v2
with:
name: docker-core
path: core.tar.gz
bundle-node:
name: 🐳 Push Node to GHCR
runs-on: ubuntu-latest
needs: build-core
strategy:
matrix:
browser: ["chrome", "firefox"]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: core-executable
path: .artifacts/core-executable
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/tilblechschmidt/webgrid/node-${{ matrix.browser }}
TAGS="${DOCKER_IMAGE}:sha-${GITHUB_SHA::7}"
echo "tags=${TAGS}" >> $GITHUB_ENV
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
chmod +x .artifacts/core-executable/webgrid
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push webgrid/node-${{ matrix.browser }} Docker image
uses: docker/build-push-action@v2
with:
context: .
file: distribution/docker/images/node/Dockerfile
build-args: browser=${{ matrix.browser }}
tags: ${{ env.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ env.created }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Export docker image as artifact
run: |
docker save ${{ env.tags }} | gzip > node-${{ matrix.browser }}.tar.gz
- uses: actions/upload-artifact@v2
with:
name: docker-node-${{ matrix.browser }}
path: node-${{ matrix.browser }}.tar.gz
docker-integration:
name: 🐳 Docker integration test
runs-on: ubuntu-latest
needs:
- bundle-core
- bundle-node
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: docker-core
path: ./
- uses: actions/download-artifact@v2
with:
name: docker-node-firefox
path: ./
- uses: actions/download-artifact@v2
with:
name: docker-node-chrome
path: ./
- name: Import docker images
run: |
docker load --input core.tar.gz
docker load --input node-firefox.tar.gz
docker load --input node-chrome.tar.gz
- name: Run integration test in Docker
run: |
export REPOSITORY=ghcr.io/tilblechschmidt/webgrid
export IMAGE_TAG="sha-${GITHUB_SHA::7}"
echo "Using $REPOSITORY/core:$IMAGE_TAG"
pip install selenium
make install
docker-compose -f distribution/docker/docker-compose.yml logs -f &
sleep 15
docker run --rm --network host -e ENDPOINT=http://localhost:8080 -e FORKS=2 -e BROWSER=firefox ghcr.io/tilblechschmidt/parallelseleniumtest:sha-fa30ad9
docker run --rm --network host -e ENDPOINT=http://localhost:8080 -e FORKS=2 -e BROWSER=chrome ghcr.io/tilblechschmidt/parallelseleniumtest:sha-fa30ad9
kubernetes-integration:
name: ☸️ Kubernetes integration test
runs-on: ubuntu-latest
needs:
- bundle-core
- bundle-node
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: docker-core
path: ./
- uses: actions/download-artifact@v2
with:
name: docker-node-firefox
path: ./
- uses: actions/download-artifact@v2
with:
name: docker-node-chrome
path: ./
- name: Import docker images
run: |
docker load --input core.tar.gz
docker load --input node-firefox.tar.gz
docker load --input node-chrome.tar.gz
- name: Install dependencies
run: |
curl -fLO https://github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64
chmod +x stern_linux_amd64
sudo mv stern_linux_amd64 /usr/local/bin/stern
pip install selenium
- name: Start K8s cluster
run: |
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=777 sh -s - --docker
mkdir -p ~/.kube
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
- name: Deploy WebGrid instance
run: |
stern --color always test-webgrid* &
helm install test ./distribution/kubernetes/demo/charts/webgrid --wait --set image.repository=ghcr.io/tilblechschmidt/webgrid,image.tag=sha-${GITHUB_SHA::7},image.pullPolicy=IfNotPresent
kubectl apply -f test/node-port.yml
- name: Print debug information
if: always()
run: |
kubectl cluster-info
kubectl get nodes
kubectl get jobs
kubectl get pods
kubectl get services
echo "------------------------ DESCRIBE ON PODS ------------------------"
kubectl describe pods
- name: Run integration test
run: |
docker run --rm --network host -e ENDPOINT=http://localhost:30007 -e FORKS=2 -e BROWSER=firefox ghcr.io/tilblechschmidt/parallelseleniumtest:sha-fa30ad9
docker run --rm --network host -e ENDPOINT=http://localhost:30007 -e FORKS=2 -e BROWSER=chrome ghcr.io/tilblechschmidt/parallelseleniumtest:sha-fa30ad9
# ------------------ RELEASE ONLY JOBS ------------------
docker-hub:
if: github.event_name == 'release'
name: 🐳 Publish Images to DockerHub
runs-on: ubuntu-latest
needs:
- bundle-core
- bundle-node
- kubernetes-integration
- docker-integration
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: webgrid
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Prepare environment
run: |
echo "SRC_REPOSITORY=ghcr.io/tilblechschmidt/webgrid" >> $GITHUB_ENV
echo "SRC_TAG=sha-${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "DST_REPOSITORY=webgrid" >> $GITHUB_ENV
echo "DST_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Cross-push core
run: |
SRC_IMAGE=${{ env.SRC_REPOSITORY }}/core:${{ env.SRC_TAG }}
DST_IMAGE=${{ env.DST_REPOSITORY }}/core:${{ env.DST_TAG }}
echo "Pushing $SRC_IMAGE to $DST_IMAGE"
docker pull $SRC_IMAGE
docker tag $SRC_IMAGE $DST_IMAGE
docker push $DST_IMAGE
- name: Cross-push node-firefox
run: |
SRC_IMAGE=${{ env.SRC_REPOSITORY }}/node-firefox:${{ env.SRC_TAG }}
DST_IMAGE=${{ env.DST_REPOSITORY }}/node-firefox:${{ env.DST_TAG }}
echo "Pushing $SRC_IMAGE to $DST_IMAGE"
docker pull $SRC_IMAGE
docker tag $SRC_IMAGE $DST_IMAGE
docker push $DST_IMAGE
- name: Cross-push node-chrome
run: |
SRC_IMAGE=${{ env.SRC_REPOSITORY }}/node-chrome:${{ env.SRC_TAG }}
DST_IMAGE=${{ env.DST_REPOSITORY }}/node-chrome:${{ env.DST_TAG }}
echo "Pushing $SRC_IMAGE to $DST_IMAGE"
docker pull $SRC_IMAGE
docker tag $SRC_IMAGE $DST_IMAGE
docker push $DST_IMAGE
publish-docs:
if: github.event_name == 'release'
name: 📚 Publish Docs to GitHub Pages
runs-on: ubuntu-latest
needs: [build-core, docker-hub]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/download-artifact@v2
with:
name: core-documentation
path: .artifacts/core-documentation
- uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install mkdocs theme & plugins
run: |
pip3 install --no-cache \
'mkdocs-git-revision-date-localized-plugin>=0.4' \
'mkdocs-material' \
'mkdocs-mermaid2-plugin' \
'mkdocs-codeinclude-plugin' \
'mkdocs-material-extensions' \
'mkdocs-simple-hooks' \
'git+http://github.com/TilBlechschmidt/mkdocs-helm'
- name: Build & deploy documentation
env:
HELM_USE_GIT_TAG: true
run: |
mkdocs --version
mkdocs gh-deploy --force
github-release:
if: github.event_name == 'release'
name: 🐙 Update GitHub Release
needs: [build-core]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: core-executable
path: .artifacts/core-executable
- name: Build release asset upload url
run: |
RELEASE_ID=$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)
if [[ -z "${RELEASE_ID}" ]]; then
echo "There was no release ID in the GitHub event."
exit 1
fi
RELEASE_ASSET_UPLOAD_URL="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets"
echo "$RELEASE_ASSET_UPLOAD_URL"
echo "RELEASE_ASSET_UPLOAD_URL=$RELEASE_ASSET_UPLOAD_URL" >> $GITHUB_ENV
- name: Attach Core executable
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_ASSET_UPLOAD_URL }}?name=webgrid-core-linux
asset_path: .artifacts/core-executable/webgrid
asset_name: webgrid-core-linux
asset_content_type: application/octet-stream