CI/CD: add alternative version tag

This commit is contained in:
Glenn Y. Rolland 2021-07-01 12:56:28 +02:00
parent 7147f1019d
commit 2d65ae1fb7

View file

@ -35,19 +35,27 @@ build-docker-image: # This job runs in the build stage, which runs first.
-u "$CI_REGISTRY_USER"
-p "$CI_REGISTRY_PASSWORD"
$CI_REGISTRY
- export VERSION="$(echo
"${CI_COMMIT_BRANCH}_$(date +%Y%m%dT%H%M%S)_${CI_COMMIT_SHA:0:8}"
|sed 's,/,--,g')"
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker build
--pull
--file Docker
--tag "$CI_REGISTRY_IMAGE${tag}" .
--tag "$CI_REGISTRY_IMAGE:$VERSION" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
- docker push "$CI_REGISTRY_IMAGE:$VERSION"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH