-
Notifications
You must be signed in to change notification settings - Fork 30
498 lines (415 loc) · 15.2 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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
name: CI
on:
push:
# Run on the main branch
branches:
- main
# Releases are tags named 'v<version>', and must have the "major.minor.micro", for example: "0.1.0".
# Release candidates are tagged as `v<version>-rc<num>`, for example: "0.1.0-rc1".
tags:
- "v*"
# Also on PRs, just be careful not to publish anything
pull_request:
env:
VERSION_HELM: "v3.9.3"
CONTAINER: docker
jobs:
prepare:
runs-on: ubuntu-22.04
outputs:
do-build: ${{steps.changed-files-irrelevant.outputs.only_modified != 'true' || steps.state.outputs.release == 'true'}}
do-publish: ${{steps.state.outputs.do-publish}}
release: ${{steps.state.outputs.release}}
version: ${{steps.version.outputs.version}}
prerelease: ${{steps.state.outputs.prerelease}}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
# Gather information for build
- name: Evaluate state
id: state
run: |
test -z "${{github.head_ref}}" && (echo 'do-publish=true' >> $GITHUB_OUTPUT )
if [[ "${{ github.event.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "release=true" >> $GITHUB_OUTPUT
echo "prerelease=false" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.ref }}" =~ ^refs/tags/v.*$ ]]; then
echo "release=true" >> $GITHUB_OUTPUT
echo "prerelease=true" >> $GITHUB_OUTPUT
fi
- name: Set version
if: ${{github.head_ref == ''}}
id: version
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
echo VERSION=$VERSION
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_ENV
# evaluate changed files
- name: Evaluate non-relevant changed files
id: changed-files-irrelevant
uses: tj-actions/changed-files@v34
with:
files: |
docs/**
info:
name: info
runs-on: ubuntu-22.04
needs: [prepare]
steps:
- run: |
echo "do-build: ${{needs.prepare.outputs.do-build}}"
echo "do-publish: ${{needs.prepare.outputs.do-publish}}"
echo "release: ${{steps.state.outputs.release}}"
echo "version: ${{steps.version.outputs.version}}"
echo "prerelease: ${{steps.state.outputs.prerelease}}"
check:
runs-on: ubuntu-22.04
needs: [prepare]
if: needs.prepare.outputs.do-build == 'true'
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
.cargo-container-home
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check
run: make host-check
test:
name: test
runs-on: ubuntu-22.04
needs: [prepare, check]
if: needs.prepare.outputs.do-build == 'true'
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
.cargo-container-home
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
env:
RUST_BACKTRACE: "1"
run: |
make test
build:
name: build
runs-on: ubuntu-22.04
needs: [prepare, check]
if: needs.prepare.outputs.do-build == 'true'
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
.cargo-container-home
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/cache@v3
with:
path: console-frontend/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('console-frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Run build
run: |
make build build-images SKIP_SERVER=1
- name: Save images
run: |
make save-images SKIP_SERVER=1
- name: Upload images
uses: actions/upload-artifact@v3
with:
name: container-images
path: build/images/all.tar
if-no-files-found: error
server-linux:
runs-on: ubuntu-22.04
needs: [prepare, check]
if: needs.prepare.outputs.do-build == 'true'
env:
VERSION: ${{needs.prepare.outputs.version}}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-server-${{ hashFiles('**/Cargo.lock') }}
- name: Install dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt update
sudo apt install -y build-essential curl tzdata libssl-dev pkg-config libsasl2-dev librdkafka-dev libpq-dev libpqxx-dev
- name: Build binary
run: |
PQ_LIB_STATIC=1 SASL2_STATIC=1 OPENSSL_STATIC=1 cargo build --release --features static -p drogue-cloud-server
- name: Build frontend
run: |
make host-frontend
- name: Build container image
run: |
# we have a pre-built binary, so we can skip the main build step
make SKIP_BUILD=1 'build-image(server)'
- name: Export container image
run: |
make -C server save-images
mv build/images/all.tar build/images/server.tar
- name: Upload server binary
uses: actions/upload-artifact@v3
with:
name: drogue-server-linux-amd64
path: target/release/drogue-cloud-server
if-no-files-found: error
- name: Upload images
uses: actions/upload-artifact@v3
with:
name: container-image-server
path: build/images/server.tar
if-no-files-found: error
server-macos:
runs-on: macos-12
needs: [prepare, check]
if: needs.prepare.outputs.do-build == 'true'
env:
VERSION: ${{needs.prepare.outputs.version}}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-server-${{ hashFiles('**/Cargo.lock') }}
- name: Fixup brew
run: |
# Unlink and re-link to prevent errors when github mac runner images
# install python outside of brew, for example:
# https://github.com/orgs/Homebrew/discussions/3895
# https://github.com/actions/setup-python/issues/577
# https://github.com/actions/runner-images/issues/6459
# https://github.com/actions/runner-images/issues/6507
# https://github.com/actions/runner-images/issues/2322
brew list -1 | grep python | while read formula; do brew unlink $formula; brew link --overwrite $formula; done
- run: brew update
- name: Install dependencies
shell: bash
run: |
brew install librdkafka openssl
- name: Build postgres
shell: bash
run: |
# Build and install postgresql dep
curl -fsSL -o postgresql-11.13.tar.gz https://ftp.postgresql.org/pub/source/v11.13/postgresql-11.13.tar.gz
tar xvf postgresql-11.13.tar.gz
cd postgresql-11.13
./configure --prefix=$PWD/../libpq
make
make install
cd ..
- name: Build binary
shell: bash
run: |
PQ_LIB_STATIC=1 PQ_LIB_DIR=$PWD/libpq/lib SASL2_STATIC=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/local/opt/openssl DEP_OPENSSL_DIR=/usr/local/opt/openssl RUSTFLAGS="-C target-feature=+crt-static" cargo build --release -p drogue-cloud-server --features static
- name: Upload server binary
uses: actions/upload-artifact@v3
with:
name: drogue-server-macos-amd64
path: target/release/drogue-cloud-server
if-no-files-found: error
#- name: Build binary for Windows
# if: ${{ matrix.os == 'windows-2019' }}
# run: |
# git clone https://github.com/microsoft/vcpkg
# .\vcpkg\bootstrap-vcpkg.bat
# .\vcpkg\vcpkg install openssl
# .\vcpkg\vcpkg install libpq
# .\vcpkg\vcpkg install librdkafka
# .\vcpkg\vcpkg integrate install
# #$env:VCPKG_ROOT = "vcpkg"
# $env:PQ_LIB_STATIC = "1"
# $env:SASL2_STATIC = "1"
# $env:OPENSSL_STATIC = "1"
# $env:RUSTFLAGS = "-C target-feature=+crt-static"
# cargo build --release -p drogue-cloud-server --features static
deploy:
name: deploy on kind
runs-on: ubuntu-22.04
needs: [prepare, build]
if: needs.prepare.outputs.do-build == 'true'
env:
CLUSTER: "kind"
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: ${{ env.VERSION_HELM }}
- name: Fetch container images
uses: actions/download-artifact@v3
with:
name: container-images
- name: Create k8s kind Cluster
uses: helm/kind-action@v1.4.0
with:
wait: 300s
cluster_name: kind
config: deploy/kind/cluster-config.yaml
- name: Load images in docker
run: docker load -i all.tar
- name: Tag images
run: |
make tag-images CONTAINER_REGISTRY=dev.local IMAGE_TAG=${{ github.sha }} SKIP_SERVER=1 SKIP_BUILD=1 SKIP_BUILD_IMAGES=1
- name: Load images in kind
run: make kind-load CONTAINER_REGISTRY=dev.local IMAGE_TAG=${{ github.sha }} SKIP_SERVER=1
- name: Delete loaded images
run: rm all.tar
- name: List all images in kind
run: docker exec -t kind-control-plane crictl images
- name: Deploy drogue
env:
DEBUG: "true"
run: |
./scripts/drgadm deploy \
-m \
-e \
-s drogueCloudCore.defaults.images.repository=dev.local \
-S drogueCloudCore.defaults.images.tag=${{ github.sha }} \
-s drogueCloudCore.defaults.images.pullPolicy=Never \
-s drogueCloudExamples.defaults.images.repository=dev.local \
-S drogueCloudExamples.defaults.images.tag=${{ github.sha }} \
-s drogueCloudExamples.defaults.images.pullPolicy=Never
timeout-minutes: 30
- name: Collect logs
if: failure()
run: |
mkdir -p /tmp/logs/kind
kind export logs /tmp/logs/kind
mkdir -p /tmp/logs/ns
for ns in kafka kourier-system knative-serving knative-eventing drogue-iot; do
./.github/scripts/collect_logs.sh /tmp/logs/ns/$ns $ns
done
- name: Upload artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: drogue-iot-logs
path: /tmp/logs
publish:
needs: [prepare, deploy, test, server-linux, server-macos]
if: (needs.prepare.outputs.do-build == 'true') && (needs.prepare.outputs.do-publish == 'true')
runs-on: ubuntu-22.04
env:
CONTAINER_REGISTRY: ghcr.io/${{ github.repository_owner }}
VERSION: ${{needs.prepare.outputs.version}}
steps:
- name: Dump state
run: |
echo "Tag/version: ${VERSION} / ${{needs.prepare.outputs.version}}"
echo "Should we publish artifacts? - do-publish = ${{needs.prepare.outputs.do-publish}}"
echo "Release? - release = ${{needs.prepare.outputs.release}}"
echo "Pre-release? - prerelease = ${{needs.prepare.outputs.prerelease}}"
# Start the actual build
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: ${{ env.VERSION_HELM }}
- name: Create installer archives
run: |
make -C installer VERSION=$VERSION
- uses: actions/upload-artifact@v3
with:
name: installers
path: installer/build/drogue-install-*.zip
if-no-files-found: error
- name: Fetch container images
uses: actions/download-artifact@v3
with:
name: container-images
- name: Fetch container image server
uses: actions/download-artifact@v3
with:
name: container-image-server
- name: Fetch static server binary (linux-amd64)
uses: actions/download-artifact@v3
with:
name: drogue-server-linux-amd64
path: drogue-server-linux-amd64
- name: Fetch static server binary (macos-amd64)
uses: actions/download-artifact@v3
with:
name: drogue-server-macos-amd64
path: drogue-server-macos-amd64
- name: Rename static server binaries
run: |
mkdir server-binaries
mv drogue-server-linux-amd64/drogue-cloud-server server-binaries/drogue-cloud-server-linux-amd64
mv drogue-server-macos-amd64/drogue-cloud-server server-binaries/drogue-cloud-server-macos-amd64
- name: Load images in docker
run: |
docker load -i all.tar
docker load -i server.tar
docker images
- name: Login to github container repository
run: echo "${{ secrets.GHCR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Tag and push images
run: |
make push "IMAGE_TAG=$VERSION" SKIP_SERVER=1 SKIP_BUILD=1 SKIP_BUILD_IMAGES=1
sleep 10 # delay a bit for API rate limiting issues
- name: Create release notes
run: |
# I know it feels like overkill to use cat and redirect, but it's a pattern for future extension of the
# release notes file. We could just add stuff.
cat installer/README.md > /tmp/notes.md
- name: Create Release
if: needs.prepare.outputs.release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: v${{ needs.prepare.outputs.version }}
run: |
# we need to create and upload in a single step, otherwise the GitHub API might return "not found" on releases
OPTS=""
if [[ "${{ needs.prepare.outputs.prerelease }}" == "true" ]]; then
OPTS="${OPTS} -p"
fi
INSTALLERS=$(find installer/build -type f -name "drogue-install-*.zip" -printf "%p ")
SERVER_BINS=$(find server-binaries -type f -printf "%p ")
gh release create \
$OPTS \
--title "${{ needs.prepare.outputs.version }}" \
-F /tmp/notes.md \
$TAG \
$INSTALLERS \
$SERVER_BINS