-
Notifications
You must be signed in to change notification settings - Fork 19
/
.gitlab-ci-check-docker-release-indep.yml
62 lines (58 loc) · 2.2 KB
/
.gitlab-ci-check-docker-release-indep.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
# .gitlab-ci-check-docker-release-indep.yml
#
# This gitlab-ci template publishes Docker images on tags for independent
# components
#
# It depends on .gitlab-ci-check-docker-build.yml, so both need to be
# included for the process to work.
#
# Add it to the project in hand through Gitlab's include functionality
#
# include:
# - project: 'Northern.tech/Mender/mendertesting'
# file: '.gitlab-ci-check-docker-release-indep.yml'
#
# It does not has explicit requirements. It assumes that the requirements
# for .gitlab-ci-check-docker-build.yml are satisfied.
#
# On release candidate tag, it publishes the image after successful build and test
# On final release rag, it re-tags the last release candidate as final release
#
stages:
- build
- publish
.docker_login_registries: &docker_login_registries |
docker login -u "$REGISTRY_MENDER_IO_USERNAME" -p "$REGISTRY_MENDER_IO_PASSWORD" registry.mender.io || \
echo "Warning: registry.mender.io credentials unavailable or invalid"
docker login -u "$DOCKER_HUB_USERNAME" -p "$DOCKER_HUB_PASSWORD" || \
echo "Warning: Docker credentials unavailable or invalid"
# Override rules for parent publish:image job to publish release candidates
publish:image:
rules:
- if: '$CI_COMMIT_BRANCH =~ /^(master|staging|production|feature-.+)$/'
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+\-build[0-9]+$/'
# Specific job for final tag to re-tag last release candidate as final
# It assumes that release candidate(s) has been build and published on the same CI_COMMIT_SHA
publish:image:final-tag:
tags:
- mender-qa-worker-generic-light
stage: publish
rules:
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/'
image: docker
services:
- docker:20.10.21-dind
before_script:
- DOCKER_PUBLISH_TAG=${CI_COMMIT_REF_NAME}
- SERVICE_IMAGE=${DOCKER_REPOSITORY}:${DOCKER_PUBLISH_TAG}
- *docker_login_registries
- apk add --no-cache git
script:
- last_release_candidate=$(
git tag --contains ${CI_COMMIT_SHA} |
sort -t 'd' -k 2,2n |
tail -n 1
)
- docker pull $DOCKER_REPOSITORY:$last_release_candidate
- docker tag $DOCKER_REPOSITORY:$last_release_candidate $SERVICE_IMAGE
- docker push $SERVICE_IMAGE