-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
229 lines (196 loc) · 5.33 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
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
# SPDX-FileCopyrightText: 2019-2020 Magenta ApS
# SPDX-License-Identifier: MPL-2.0
################################################################################
# Changes to this file requires approval from Labs. Please add a person from #
# Labs as required approval to your MR if you have any changes. #
################################################################################
# For pushing of release images to work, the following envionment variables have
# to set in the Gitlab UI.
# RELEASE_REGISTRY_USER
# RELEASE_REGISTRY_PASSWORD
variables:
# Project variables
RELEASE_REGISTRY: index.docker.io/magentaaps
# CI images
PROXY_IMAGE: ${CI_REGISTRY_IMAGE}/proxy:${CI_COMMIT_SHA}
FRONTEND_IMAGE: ${CI_REGISTRY_IMAGE}/frontend:${CI_COMMIT_SHA}
BACKEND_IMAGE: ${CI_REGISTRY_IMAGE}/backend:${CI_COMMIT_SHA}
# Release image names
PROXY_RELEASE_IMAGE_NAME: ${RELEASE_REGISTRY}/os2phonebook-proxy
FRONTEND_RELEASE_IMAGE_NAME: ${RELEASE_REGISTRY}/os2phonebook-frontend
BACKEND_RELEASE_IMAGE_NAME: ${RELEASE_REGISTRY}/os2phonebook-backend
stages:
- lint
- build
- test
- prerelease
- release
# Lint stage
#############
.lint-default:
stage: lint
needs: []
image: python:3
services: []
tags:
- docker
Lint Python:
extends: .lint-default
before_script:
- pip3 install -r os2phonebook_backend/requirements/lint.txt
script:
- cd os2phonebook_backend
- flake8 --version
- flake8
- black --version
- black --check --line-length 79 .
Lint Dockerfiles:
extends: .lint-default
image: hadolint/hadolint:latest-debian
before_script:
- apt-get -y update
- apt-get -y install --no-install-recommends git
script:
- git ls-files --exclude='Dockerfile*' --ignored | xargs --max-lines=1 hadolint
# Disabled for now
.REUSE compliance:
extends: .lint-default
image:
name: fsfe/reuse:latest
entrypoint: [""]
script:
- reuse lint
Lint shell scripts:
extends: .lint-default
image: koalaman/shellcheck-alpine:latest
before_script:
- apk update
- apk add git
script:
- git ls-files --exclude='*.sh' --ignored | xargs shellcheck
# Disabled for now
.Lint frontend:
extends: .lint-default
image: node:14-slim
before_script:
- cd os2phonebook_frontend
- npm install
script:
- npm run lint
# Build stage
#############
.build_docker_base:
stage: build
needs: []
image:
# We use the `:debug` image as it contains `sh` needed by gitlab-ci.
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
services: []
tags:
- docker
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- cat /kaniko/.docker/config.json
- /kaniko/executor
--context=${CI_PROJECT_DIR}
--dockerfile=${DOCKERFILE}
--destination=${CI_IMAGE}
--cache=true
build_proxy_docker:
extends: .build_docker_base
before_script:
- export DOCKERFILE="docker/Dockerfile.proxy"
- export CI_IMAGE="${PROXY_IMAGE}"
rules:
# Only ever create release containers on git tags
- if: $CI_COMMIT_TAG
when: on_success
- when: never
build_frontend_docker:
extends: .build_docker_base
before_script:
- export DOCKERFILE="docker/Dockerfile.frontend"
- export CI_IMAGE="${FRONTEND_IMAGE}"
build_backend_docker:
extends: .build_docker_base
before_script:
- export DOCKERFILE="docker/Dockerfile.backend"
- export CI_IMAGE="${BACKEND_IMAGE}"
# Test stage
############
test_backend:
stage: test
needs:
- build_backend_docker
image:
name: ${BACKEND_IMAGE}
entrypoint: [""]
tags:
- docker
before_script:
- pip3 install -r os2phonebook_backend/requirements/test.txt
script:
- pytest
# Prerelease stage
##################
generate_tags:
stage: prerelease
needs: []
image: magentaaps/semantic-versioning-image-builder:latest
tags:
- docker
script:
- python3 -m semvertool "${CI_COMMIT_TAG}" > tags.txt
- cat tags.txt
artifacts:
paths:
- tags.txt
rules:
# Only ever create release containers on git tags
- if: $CI_COMMIT_TAG
when: on_success
- when: never
# Release stage
###############
.release_base:
stage: release
image: alpine
script:
- apk add skopeo
- cat tags.txt | xargs -I TAG skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_BUILD_TOKEN}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${CI_IMAGE}"
"docker://${RELEASE_IMAGE_NAME}:TAG"
rules:
# Only ever create release containers on git tags
- if: $CI_COMMIT_TAG
when: on_success
- when: never
tags:
- docker
release_proxy:
extends: .release_base
before_script:
- export CI_IMAGE="${PROXY_IMAGE}"
- export RELEASE_IMAGE_NAME="${PROXY_RELEASE_IMAGE_NAME}"
dependencies:
- build_proxy_docker
- generate_tags
release_frontend:
extends: .release_base
before_script:
- export CI_IMAGE="${FRONTEND_IMAGE}"
- export RELEASE_IMAGE_NAME="${FRONTEND_RELEASE_IMAGE_NAME}"
dependencies:
- build_frontend_docker
- generate_tags
release_backend:
extends: .release_base
before_script:
- export CI_IMAGE="${BACKEND_IMAGE}"
- export RELEASE_IMAGE_NAME="${BACKEND_RELEASE_IMAGE_NAME}"
dependencies:
- build_backend_docker
- generate_tags