-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
156 lines (140 loc) · 3.84 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
variables:
REMOTE_IMAGE: index.docker.io/fintechstudios/davical
CI_IMAGE: $CI_REGISTRY_IMAGE/davical
GIT_DEPTH: 10
DOCKER_BUILDKIT: 1
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#docker-in-docker-with-tls-enabled-in-the-docker-executor
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
DOCKER_TLS_VERIFY: 1
DOCKER_HOST: tcp://docker:2376
DOCKER_DRIVER: overlay2
stages:
- build
- deploy
.docker-job:
image: docker:20
services:
- docker:20-dind
before_script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
.use-build-matrix:
parallel:
matrix:
- PHP_VERSION: ["8.1.21", "8.2.8"]
DISTRO: ["bullseye", "bookworm"]
.build-image:
stage: build
extends:
- .docker-job
- .use-build-matrix
variables:
BUILD_PREFIX: "" #required
DOCKER_BUILD_FLAGS: ""
script:
- |
docker build \
--tag built_image \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg PHP_VERSION \
--build-arg DISTRO \
--cache-from $CI_IMAGE:php$PHP_VERSION-$DISTRO \
--cache-from $CI_IMAGE:php$PHP_VERSION-$DISTRO-$CI_COMMIT_REF_SLUG \
$DOCKER_BUILD_FLAGS \
.
- |
export IMAGE_TAGS="\
php$PHP_VERSION-$DISTRO \
php$PHP_VERSION-$DISTRO-$CI_COMMIT_REF_SLUG \
$BUILD_PREFIX-php$PHP_VERSION-$DISTRO-$CI_COMMIT_SHA \
"
- |
for TAG in $(echo $IMAGE_TAGS)
do
printf "Publishing %s\n" "$CI_IMAGE:$TAG"
docker tag built_image "$CI_IMAGE:$TAG"
docker push "$CI_IMAGE:$TAG"
done
.release-image:
stage: deploy
extends:
- .docker-job
- .use-build-matrix
variables:
BUILD_PREFIX: "" # required
script:
- echo $DOCKER_HUB_ACCESS_TOKEN | docker login -u $DOCKER_HUB_USERNAME --password-stdin
- export RELEASE_TAG="$CI_IMAGE:$BUILD_PREFIX-php$PHP_VERSION-$DISTRO-$CI_COMMIT_SHA"
- echo "Preparing $RELEASE_TAG"
- docker pull $RELEASE_TAG
- export IMAGE_TAGS=$(./helpers/get-image-tags.sh "$RELEASE_TAG" "$PHP_VERSION" "$DISTRO" "$CI_COMMIT_SHA" "$BUILD_PREFIX")
- |
for TAG in $(echo $IMAGE_TAGS)
do
printf "Publishing %s\n" "$REMOTE_IMAGE:$TAG"
docker tag $RELEASE_TAG "$REMOTE_IMAGE:$TAG"
docker push "$REMOTE_IMAGE:$TAG"
done
##
## Commit pipelines
##
.build-prefix-latest:
variables:
# this string is used in ./helpers/get-image-tags.sh and must be synced if changed
BUILD_PREFIX: "latest"
.only-commits:
rules:
- if: "$CI_PIPELINE_SOURCE != 'schedule'"
build:
extends:
- .build-image
- .build-prefix-latest
- .only-commits
release:
extends:
- .release-image
- .build-prefix-latest
rules:
- if: "$CI_COMMIT_BRANCH == 'main' && $CI_PIPELINE_SOURCE != 'schedule'"
##
## Nightly pipelines
##
.only-nightly:
rules:
- if: "$CI_PIPELINE_SOURCE == 'schedule'"
prepare-nightly:
extends:
- .only-nightly
stage: build
image: alpine
script:
# needed for get-release-sha
- apk add --no-cache curl jq
# sets DAVICAL_VERSION, DAVICAL_SHA512, AWL_VERSION, and AWL_SHA512 to the latest master commit of DAViCal and AWL
- ./helpers/get-release-sha.sh master master
artifacts:
reports:
dotenv: .versions.env
.after-nightly-prepared:
extends:
- .only-nightly
needs:
- job: prepare-nightly
artifacts: true
variables:
DOCKER_BUILD_FLAGS: "--build-arg DAVICAL_VERSION --build-arg DAVICAL_SHA512 --build-arg AWL_VERSION --build-arg AWL_SHA512"
BUILD_PREFIX:
value: "$DAVICAL_VERSION-awl$AWL_VERSION"
expand: true
build-nightly:
extends:
- .build-image
- .after-nightly-prepared
release-nightly:
extends:
- .release-image
- .after-nightly-prepared
needs:
- job: prepare-nightly
artifacts: true
- build-nightly