Skip to content

Instantly share code, notes, and snippets.

@qoomon
Last active July 20, 2022 23:18
Show Gist options
  • Save qoomon/22edb16a5e725762f7fdd5083498a64f to your computer and use it in GitHub Desktop.
Save qoomon/22edb16a5e725762f7fdd5083498a64f to your computer and use it in GitHub Desktop.
GitLab CI - build and push docker image to GitLab registry
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