Last active
July 20, 2022 23:18
-
-
Save qoomon/22edb16a5e725762f7fdd5083498a64f to your computer and use it in GitHub Desktop.
GitLab CI - build and push docker image to GitLab registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stages: | |
- pack | |
### Pack ###################################################################### | |
docker: | |
stage: pack | |
environment: production | |
image: docker:18 | |
script: | |
# replace '/' with '-' to make it a valid docker tag | |
- IMAGE_TAG=${CI_COMMIT_REF_NAME//\//-} | |
- | # remove leading 'v' for version tags | |
if [[ "$CI_COMMIT_TAG" = v[0-9]* ]]; then | |
IMAGE_TAG=${IMAGE_TAG#v} | |
fi | |
- echo -n $CI_REGISTRY_PASSWORD | docker login --username $CI_REGISTRY_USER --password-stdin $CI_REGISTRY | |
- docker build . -t $CI_REGISTRY_IMAGE:$IMAGE_TAG | |
- | # push docker image for version tags | |
if [[ "$CI_COMMIT_TAG" = v[0-9]* ]]; then | |
docker push $CI_REGISTRY_IMAGE:$IMAGE_TAG | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment