-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
196 lines (172 loc) · 6 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
# Copyright (C) 2020 Magenta ApS, http://magenta.dk.
# Contact: info@magenta.dk.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/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 `docker push` to work, the following envionment variables have to set in
# the Gitlab UI.
# RELEASE_REGISTRY_USER
# RELEASE_REGISTRY_PASSWORD
stages:
- lint
- build-base
- build
- test
- release
- deploy
variables:
# Project variables
RELEASE_REGISTRY: docker.io
IMAGE_SHA_BASE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
OS2MO_RELEASE_REGISTRY_IMAGE: index.docker.io/magentaaps/postgres-os2mo
OS2MO_IMAGE_TAG_BASE: ${OS2MO_RELEASE_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
KEYCLOAK_RELEASE_REGISTRY_IMAGE: index.docker.io/magentaaps/postgres-keycloak-init
KEYCLOAK_IMAGE_TAG_BASE: ${KEYCLOAK_RELEASE_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
# Lint stage
############
Lint Dockerfile:
stage: lint
image: hadolint/hadolint:latest-alpine
needs: []
before_script:
- apk add fd
script:
- echo "Running Hadolint, a Dockerfile linter"
- echo "For more information about reported errors, visit the Hadolint wiki on https://github.com/hadolint/hadolint/wiki"
# Run fd without exec arg to produce a list of files to be linted
- fd Dockerfile
# Run hadolint on every Dockerfile
- fd Dockerfile --exec hadolint
# Build-base stage
##################
.build_docker_base:
stage: build-base
needs: []
image:
# We use the `:debug` image as it contains `sh` needed by gitlab-ci.
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- cat postgres-versions.txt | xargs -I PGV sh -c '
echo "===== Building ${IMAGE_SHA_BASE}-base-${TARGET}-PGV =====";
/kaniko/executor
--context=${CI_PROJECT_DIR}
--dockerfile=${CI_PROJECT_DIR}/docker/Dockerfile.base
--target=${TARGET}
--build-arg POSTGRES_VERSION=PGV
--destination=${IMAGE_SHA_BASE}-base-${TARGET}-PGV
--cache=true
'
Build base production image:
extends: .build_docker_base
before_script:
- export TARGET="production"
Build base test image:
extends: .build_docker_base
before_script:
- export TARGET="test"
# Build stage
#############
.build_docker_image:
stage: build
extends: .build_docker_base
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- cat postgres-versions.txt | xargs -I PGV sh -c '
echo "===== Building ${IMAGE_SHA_BASE}-${TYPE}-${TARGET}-PGV =====";
/kaniko/executor
--context=${CI_PROJECT_DIR}
--dockerfile=${CI_PROJECT_DIR}/docker/Dockerfile.${TYPE}
--build-arg BASE_IMAGE=${IMAGE_SHA_BASE}-base-${TARGET}-PGV
--destination=${IMAGE_SHA_BASE}-${TYPE}-${TARGET}-PGV
--cache=true
'
Build OS2mo production image:
extends: .build_docker_image
needs:
- Build base production image
before_script:
- export TYPE="mox"
- export TARGET="production"
Build OS2mo test image:
extends: .build_docker_image
needs:
- Build base test image
before_script:
- export TYPE="mox"
- export TARGET="test"
Build Keycloak production image:
extends: .build_docker_image
needs:
- Build base production image
before_script:
- export TYPE="keycloak"
- export TARGET="production"
Build Keycloak test image:
extends: .build_docker_image
needs:
- Build base test image
before_script:
- export TYPE="keycloak"
- export TARGET="test"
# Release stage
###############
.release-default:
stage: release
needs:
- Lint Dockerfile
- Build OS2mo production image
- Build OS2mo test image
- Build Keycloak production image
- Build Keycloak test image
image: alpine
before_script:
- apk add skopeo
Release OS2mo master:
extends: .release-default
rules:
- if: $CI_COMMIT_TAG
script:
- cat postgres-versions.txt | xargs -I PGV sh -c '
echo "===== Tagging ${OS2MO_IMAGE_TAG_BASE}-mox-PGV =====";
skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_BUILD_TOKEN}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA_BASE}-mox-production-PGV"
"docker://${OS2MO_IMAGE_TAG_BASE}-PGV"
'
- cat postgres-versions.txt | xargs -I PGV sh -c '
echo "===== Tagging ${OS2MO_IMAGE_TAG_BASE}-mox-test-PGV =====";
skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_BUILD_TOKEN}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA_BASE}-mox-test-PGV"
"docker://${OS2MO_IMAGE_TAG_BASE}-PGV-test"
'
Release Keycloak master:
extends: .release-default
rules:
- if: $CI_COMMIT_TAG
script:
- cat postgres-versions.txt | xargs -I PGV sh -c '
echo "===== Tagging ${KEYCLOAK_IMAGE_TAG_BASE}-keycloak-PGV =====";
skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_BUILD_TOKEN}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA_BASE}-keycloak-production-PGV"
"docker://${KEYCLOAK_IMAGE_TAG_BASE}-PGV"
'
- cat postgres-versions.txt | xargs -I PGV sh -c '
echo "===== Tagging ${KEYCLOAK_IMAGE_TAG_BASE}-keycloak-test-PGV =====";
skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_BUILD_TOKEN}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA_BASE}-keycloak-test-PGV"
"docker://${KEYCLOAK_IMAGE_TAG_BASE}-PGV-test"
'