forked from ScaDS/cicd-ga-scadsai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
103 lines (95 loc) · 2.98 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
103 lines (95 loc) · 2.98 KB
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
# Gitlab CICD
workflow:
rules:
# Pushes to develop or main
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH =~ /^(develop|main)$/'
# Merge Requests targeting develop or main
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(develop|main)$/'
- when: never
stages: [lint, test, deploy]
# Global envs
variables:
CONDA_ENV_FILE: devops-conda-env.yml
CONDA_ENV_NAME: devops-env
REGISTRY: docker.scadsai.uni-leipzig.de
PROJECT: library
IMAGE: ${REGISTRY}/${PROJECT}/analysis-app
# Prefer interruptible jobs to auto-cancel older pipelines on new pushes
default:
interruptible: true
# Reusable cache for micromamba
.cache_mamba: &cache_mamba
key:
files: [$CONDA_ENV_FILE]
prefix: "$CI_COMMIT_REF_SLUG"
paths:
- /opt/conda/pkgs
- "/opt/conda/envs/${CONDA_ENV_NAME}"
policy: pull-push
# Jobs
linting:
stage: lint
image: mambaorg/micromamba:1
cache: *cache_mamba
script:
- micromamba --version
- micromamba create -y -n "$CONDA_ENV_NAME" -f "$CONDA_ENV_FILE"
- micromamba run -n "$CONDA_ENV_NAME" ruff check
artifacts:
when: always
expire_in: 1 week
tests:
stage: test
image: mambaorg/micromamba:1
needs: ["linting"]
cache: *cache_mamba
script:
- micromamba create -y -n "$CONDA_ENV_NAME" -f "$CONDA_ENV_FILE"
- micromamba run -n "$CONDA_ENV_NAME" pytest --cov=app --cov-report=xml
- micromamba run -n "$CONDA_ENV_NAME" python scripts/check_test_coverage.py
artifacts:
when: always
expire_in: 1 week
paths:
- coverage.xml
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
deploy:
stage: deploy
image: docker:24
services: [ "docker:24-dind" ]
needs: ["tests"]
rules:
# Only for *push* on main
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
- when: never
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
before_script:
# Enable Docker Buildx with QEMU
- docker run --privileged --rm tonistiigi/binfmt --install all
- docker buildx create --use --name builder || docker buildx use builder
# Login to Harbor Docker registry
- echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USERNAME" "$REGISTRY" --password-stdin
script:
# Extract version from pyproject.toml
- |
set -euo pipefail
VERSION="$(grep -E '^[[:space:]]*version[[:space:]]*=[[:space:]]*\"[^\"]+\"' pyproject.toml | head -1 | sed -E 's/.*version[[:space:]]*=[[:space:]]*\"([^\"]+)\".*/\1/')"
[ -n "$VERSION" ] || { echo "Version not found in pyproject.toml"; exit 1; }
echo "Found version: $VERSION"
# Build + push multi-arch, tag with version and latest
- |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t "$IMAGE:$VERSION" \
-t "$IMAGE:latest-gl" \
--push \
.
echo "Pushed:"
echo " $IMAGE:$VERSION"
echo " $IMAGE:latest-gl"