Created
June 30, 2021 23:00
-
-
Save JacobJohansen/e32507e8cedaba062b1741afb34aa931 to your computer and use it in GitHub Desktop.
Generic Gitlab Pipeline to For Docker Image
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
--- | |
variables: | |
DEFAULT_DOCKER_FILE: "Dockerfile" | |
DOCKER_IMAGE_NAME: "{{ imageName }}" | |
stages: | |
- build | |
build-n-push-latest: | |
stage: build | |
image: docker:stable | |
rules: | |
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH | |
services: | |
- docker:dind | |
script: | |
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY | |
- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/$DOCKER_IMAGE_NAME:latest -f $DEFAULT_DOCKER_FILE . | |
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/$DOCKER_IMAGE_NAME:latest | |
build-n-push-version: | |
stage: build | |
image: docker:stable | |
rules: | |
- if: $CI_COMMIT_TAG =~ /[v][0-9]+[.][0-9]+[.][0-9]+/ | |
services: | |
- docker:dind | |
script: | |
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY | |
- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/$DOCKER_IMAGE_NAME:CI_COMMIT_TAG -f $DEFAULT_DOCKER_FILE . | |
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/$DOCKER_IMAGE_NAME:$CI_COMMIT_TAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment