-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
201 lines (185 loc) · 5.48 KB
/
.gitlab-ci.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
# SPDX-FileCopyrightText: 2023 - 2024 GESIS - Leibniz-Institut für Sozialwissenschaften
# SPDX-FileContributor: Raniere Gaia Costa da Silva <Raniere.CostadaSilva@gesis.org>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
variables:
MYBINDER_URL: https://notebooks.gesis.org/binder
stages:
- test
- release
- update-integration
- deploy-integration
- update-acceptance
- deploy-acceptance
- update-production
- deploy-production
# Build documentation
include:
- component: $CI_SERVER_FQDN/rse/docker/images/sphinx-doc/sphinx-doc@2.3.0
inputs:
stage: release
dir: docs
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- docs/source/**/*
pages:
stage: .post
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
script:
- mv docs/build/html public
artifacts:
paths:
- public
Build container:
stage: release
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
variables:
DOCKER_REGISTRY: docker-private-releases.gesis.intra/gesis
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == 'main'
variables:
DOCKER_REGISTRY: docker-private-snapshots.gesis.intra/gesis
image: docker-private.gesis.intra/gesis/dc:5.7
services:
- name: docker-private.gesis.intra/gesis/dind:5.5
alias: docker
variables:
DOCKER_TARGET: prod
DOCKER_CONTAINER_NAME: ${DOCKER_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}
DOCKER_IMAGE_TAG: $CI_COMMIT_SHA
script:
- |
docker \
build \
--no-cache \
--pull \
--target ${DOCKER_TARGET} \
--tag ${DOCKER_CONTAINER_NAME}:${DOCKER_IMAGE_TAG} \
.
- |
docker \
push \
${DOCKER_CONTAINER_NAME}:${DOCKER_IMAGE_TAG}
Verify code style:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == 'main'
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
changes:
- "**/*.py"
image: python:3.12.6-alpine3.20
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
before_script:
- python -V
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- python -m pip install black
script:
- black .
Run test:
tags:
- shell
- methodshub
- stage
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == 'main'
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
changes:
- "**/*.py"
variables:
MAGDALENA_SHARED_DIR: /tmp/magdalena-shared-volume
script:
- poetry install --with dev
- |
poetry run pytest \
--verbose \
--showlocals \
-o log_cli=true \
-o log_cli_level=INFO \
.
Release new version:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
script:
- echo "running release_job"
release:
tag_name: '$CI_COMMIT_TAG'
description: '$CI_COMMIT_TAG'
.Update container tag downstream:
variables:
TARGET_ENVIRONMENT: env
script:
- |
curl \
--globoff \
--request PUT \
--header "PRIVATE-TOKEN: $GITLAB_REST_API_TOKEN" \
"https://git.gesis.org/api/v4/projects/methods-hub%2Fmethodshub.gesis.org/variables/MAGDALENA_IMAGE_TAG?filter[environment_scope]=${TARGET_ENVIRONMENT}" --form "value=$CI_COMMIT_SHA"
Update container tag downstream into integration environment:
extends: .Update container tag downstream
stage: update-integration
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == 'main'
variables:
TARGET_ENVIRONMENT: integration
Update container tag downstream into acceptance environment:
extends: .Update container tag downstream
stage: update-acceptance
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
variables:
TARGET_ENVIRONMENT: acceptance
Update container tag downstream into production environment:
extends: .Update container tag downstream
stage: update-production
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
when: manual
variables:
TARGET_ENVIRONMENT: production
.Deploy new version downstream:
trigger:
project: methods-hub/methodshub.gesis.org
branch: main
strategy: depend
Deploy new version downstream into integration environment:
extends: .Deploy new version downstream
stage: deploy-integration
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == 'main'
variables:
UPSTREAM_PROJECT_NAMESPACE: $CI_PROJECT_NAMESPACE
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
TARGET_ENVIRONMENT: integration
Deploy new version downstream into acceptance environment:
extends: .Deploy new version downstream
stage: deploy-acceptance
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
variables:
UPSTREAM_PROJECT_NAMESPACE: $CI_PROJECT_NAMESPACE
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
TARGET_ENVIRONMENT: acceptance
Deploy new version downstream into production environment:
extends: .Deploy new version downstream
stage: deploy-production
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG
when: manual
variables:
UPSTREAM_PROJECT_NAMESPACE: $CI_PROJECT_NAMESPACE
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
TARGET_ENVIRONMENT: production