forked from RamenDR/ramen
-
Notifications
You must be signed in to change notification settings - Fork 0
489 lines (411 loc) · 14 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
# SPDX-FileCopyrightText: The RamenDR authors
# SPDX-License-Identifier: Apache-2.0
---
# yamllint disable rule:line-length
name: CI
# This workflow will run when developer push a topic branch to their
# fork in github, minimizing noise for maintainers. This
# workflow also runs on nightly basis at 12:00 AM (00:00 UTC)
on: # yamllint disable-line rule:truthy
push:
pull_request:
schedule:
- cron: '0 0 * * *'
env:
# Values can be overriden by repository variables.
IMAGE_TAG_BASE: ${{ vars.IMAGE_TAG_BASE || 'quay.io/ramendr/ramen' }}
IMAGE_REPOSITORY: ${{ vars.IMAGE_REPOSITORY || 'ramendr' }}
IMAGE_NAME: ${{ vars.IMAGE_NAME || 'ramen' }}
OPERATOR_SUGGESTED_NAMESPACE: ${{ vars.OPERATOR_SUGGESTED_NAMESPACE || 'ramen-system' }}
# Constants
GO_VERSION: "1.22"
IMAGE_REGISTRY: "quay.io"
IMAGE_TAG: "ci"
DOCKERCMD: "podman"
defaults:
run:
shell: bash
jobs:
lint:
name: Linters
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install prereqs
run: |
echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip ruby
sudo gem install mdl
sudo pip3 install yamllint
- name: Run linters
run: ./hack/pre-commit.sh
- name: Check that generated files were not modified
run: |
make generate
make manifests
go mod tidy
git --no-pager diff
git diff-index --quiet HEAD
golangci:
name: Golangci Lint
runs-on: ubuntu-20.04
strategy:
matrix:
directory: [., api, e2e]
# golangci-lint has a limitation that it doesn't lint subdirectories if
# they are a different module.
# see https://github.com/golangci/golangci-lint/issues/828
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
# when the files to be extracted are already present,
# tar extraction in Golangci Lint fails with the "File exists"
# errors. These files appear to be present because of
# cache in setup-go, on disabling the cache we are no more seeing
# such error. Cache is to be enabled once the fix is available for
# this issue.
go-version: ${{ env.GO_VERSION }}
cache: false
- name: GolangCI Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
working-directory: ${{ matrix.directory }}
unit-test:
name: Unit tests
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run unit tests
run: make test
drenv-linux:
name: drenv
strategy:
matrix:
os:
- ubuntu-22.04
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13-dev"
runs-on: ${{ matrix.os }}
env:
DRIVER: "container"
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install minikube
run: |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube version
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install ./kubectl /usr/local/bin/
kubectl version --client --output=yaml
- name: Install tools
run: pip install -r requirements.txt
- name: Enable coverage for child processes
run: cp coverage.pth $(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
- name: Install drenv
run: pip install -e test
- name: Run flake8
run: make flake8
working-directory: test
- name: Run pylint
run: make pylint
working-directory: test
- name: Run black
run: make black
working-directory: test
- name: Start test cluster
run: make cluster
working-directory: test
- name: Run tests
run: make test
working-directory: test
- name: Report test coverage
run: make coverage
working-directory: test
- name: Clean up
run: make clean
working-directory: test
drenv-macos:
name: drenv
strategy:
matrix:
os:
# amd64, 4 cpus, 14 GiB RAM, nested virtalization
- macos-13
python-version:
- "3.12"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout ramen
uses: actions/checkout@v4
- name: Checkout lima
uses: actions/checkout@v4
with:
repository: lima-vm/lima
path: lima
- name: Checkout socket_vmnet
uses: actions/checkout@v4
with:
repository: lima-vm/socket_vmnet
path: socket_vmnet
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup go for lima
uses: actions/setup-go@v5
with:
go-version-file: lima/go.mod
- name: Install lima
run: |
cd lima
# Miniaml build is 3 times faster than full make..
make minimal
# But it adds only the default template, so lets fix it:
rm -rf _output/share/lima/templates
cp -aL examples _output/share/lima/templates
ln -sf templates _output/share/lima/examples
# And install
sudo make install
limactl --version
- name: Install socket_vmnet
run: |
cd socket_vmnet
make
sudo make install.bin
sudo make install.launchd
/opt/socket_vmnet/bin/socket_vmnet --version
- name: Install Homebrew packages
run: brew install kubectl
- name: Install python packages
run: pip install -r requirements.txt
- name: Enable coverage for child processes
run: cp coverage.pth $(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
- name: Install drenv
run: pip install -e test
- name: Run flake8
run: make flake8
working-directory: test
- name: Run pylint
run: make pylint
working-directory: test
- name: Run black
run: make black
working-directory: test
- name: Start lima vmc
run: limactl start --tty=false --vm-type vz --plain template://vmnet
working-directory: test
- name: Show logs on error
if: failure()
run: |
export DIR=$(limactl list --format '{{.Dir}}')
cat $DIR/ha.stdout.log
cat $DIR/ha.stderr.log
cat $DIR/copied-from-guest/kubectl.yaml || true
ramenctl:
name: ramenctl
strategy:
matrix:
os:
- ubuntu-22.04
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13-dev"
include:
# arm64, 3 cpus (M1), 7 GiB RAM, no nested virtalization.
- os: macos-14
python-version: "3.12"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install python packages
run: pip install -r requirements.txt
- name: Install drenv
run: pip install -e test
- name: Run flake8
run: make flake8
working-directory: ramenctl
- name: Run pylint
run: make pylint
working-directory: ramenctl
- name: Run black
run: make black
working-directory: ramenctl
build-image:
name: Build image
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build image
run: make docker-build
- name: Export image
run: ${{env.DOCKERCMD}} save -o /tmp/ramen-operator.tar ${IMAGE_TAG_BASE}-operator:${IMAGE_TAG}
- name: Save image artifact
uses: actions/upload-artifact@v4
with:
name: ramen-operator
path: /tmp/ramen-operator.tar
retention-days: 1
deploy-check:
name: Check artifacts and operator deployment
needs: [build-image]
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
kubernetes_version: ["1.29.1"]
include:
- kubernetes_version: "1.29.1"
kind_image: "1.29.1@sha256:a0cc28af37cf39b019e2b448c54d1a3f789de32536cb5a5db61a49623e527144"
kind_version: "v0.21.0"
env:
KUBERNETES_VERSION: ${{ matrix.kubernetes_version }}
KIND_VERSION: ${{ matrix.kind_version }}
KIND_IMAGE: ${{ matrix.kind_image }}
KIND_CLUSTER_NAME: "ci"
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install kubectl
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
sudo install ./kubectl /usr/local/bin/
- name: Create Kind kubernetes cluster
run: ./hack/setup-kind-cluster.sh
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: ramen-operator
path: /tmp
- name: Load image artifact
run: |
kind load image-archive /tmp/ramen-operator.tar --name ${KIND_CLUSTER_NAME}
- name: Deploy dependent CRDs
run: |
kubectl apply -f hack/test/
- name: Deploy operator
run: |
make deploy
kubectl get deployment -n ramen-system
kubectl -n ramen-system wait --for=condition=Available --timeout=60s deploy/ramen-hub-operator
kubectl -n ramen-system wait --for=condition=Available --timeout=60s deploy/ramen-dr-cluster-operator
- name: Display failure logs
if: ${{ failure() }}
run: |
echo "===> BEGIN failure details <==="
echo "===> NODE details <==="
kubectl get node -o yaml
echo "===> Ramen POD details <==="
kubectl get pods -n ramen-system -o yaml
echo "===> Ramen POD describe <==="
kubectl describe pods -n ramen-system
echo "===> Ramen DR Orchestrator POD logs <==="
kubectl logs -n ramen-system deployment/ramen-hub-operator -c manager
echo "===> Ramen DR Manager POD logs <==="
kubectl logs -n ramen-system deployment/ramen-dr-cluster-operator -c manager
echo "===> END failure details <==="
publish-image:
name: Publish built image
needs: [deploy-check, lint, golangci, unit-test, build-image]
if: >
(vars.PUBLISH_IMAGES == 'true') &&
(github.event_name == 'push') &&
(github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release-') ||
startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-20.04
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: ramen-operator
path: /tmp
- name: Load image artifact
run: |
${{env.DOCKERCMD}} load -i /tmp/ramen-operator.tar
- name: Login to Quay
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
- name: Determine image tag
run: |
[[ "${{ github.ref }}" =~ ^refs\/(heads|tags)\/(release-)?(.*) ]]
echo "heads or tags? ${BASH_REMATCH[1]}"
echo "release? ${BASH_REMATCH[2]}"
echo "version? ${BASH_REMATCH[3]}"
TAG=""
if test "${BASH_REMATCH[1]}" = "heads"; then
if test "${BASH_REMATCH[2]}" = "" && test "${BASH_REMATCH[3]}" = "main"; then
TAG="canary"
elif test "${BASH_REMATCH[2]}" = "release-"; then
TAG="${BASH_REMATCH[3]}-canary"
fi
elif test "${BASH_REMATCH[1]}" == "tags" && test "${BASH_REMATCH[2]}" = ""; then
TAG="${BASH_REMATCH[3]}"
fi
test "${TAG}" = "" && exit 1
echo "Publish image tag ${TAG}"
echo "publish_image_tag=${TAG}" >> $GITHUB_ENV
- name: Push operator image to Quay
run: |
${{env.DOCKERCMD}} tag "${IMAGE_TAG_BASE}-operator:${IMAGE_TAG}" "${IMAGE_TAG_BASE}-operator:${{ env.publish_image_tag }}"
${{env.DOCKERCMD}} push "${IMAGE_TAG_BASE}-operator:${{ env.publish_image_tag }}"
# TODO: We do not need to build bundles and catalogs each time, fix once we reach alpha
- name: Checkout source
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build and push bundle images to Quay
run: |
IMAGE_TAG="${{ env.publish_image_tag }}" make bundle-build bundle-push
- name: Build and push catalog image to Quay
run: |
IMAGE_TAG="${{ env.publish_image_tag }}" make catalog-build catalog-push
# TODO: Test built bundles and catalog based install