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" -u "$CI_REGISTRY_USER"
-p "$CI_REGISTRY_PASSWORD" -p "$CI_REGISTRY_PASSWORD"
$CI_REGISTRY $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) # Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug) # All other branches are tagged with the escaped branch name (commit ref slug)
script: script:
- | - |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
tag="" tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else else
tag=":$CI_COMMIT_REF_SLUG" tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi 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${tag}"
- docker push "$CI_REGISTRY_IMAGE:$VERSION"
# Run this job in a branch where a Dockerfile exists # Run this job in a branch where a Dockerfile exists
rules: rules:
- if: $CI_COMMIT_BRANCH - if: $CI_COMMIT_BRANCH