From 131e7c6d5773fcebdbfc10548f0d26a6eff9fcb2 Mon Sep 17 00:00:00 2001 From: Jonas Leder <jonas@jonasled.de> Date: Fri, 8 Nov 2019 22:13:00 +0100 Subject: [PATCH] tag release pushes with version --- .gitlab-ci.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bd6af31..44cc000 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,25 +8,30 @@ stages: - build-release - deploy -build-release: #This will be executed if you oush on master, it makes a new release (latest) image + +build: #This will be executed on every push. With this script the beta image will be build stage: build - only: - - master script: - echo "building for branch $CI_COMMIT_REF_NAME" - sudo docker image prune -f #Delete old unused images - - sudo docker build -t gitlab.jonasled.de/jonasled/url_shorter_docker . #Build the image with the name already set to push + - sudo docker build -t gitlab.jonasled.de/jonasled/url_shorter_docker:beta . #Build the image with the name already set to push - sudo docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY #Login to docker registry, username and password will be filled while executing - - sudo docker push gitlab.jonasled.de/jonasled/url_shorter_docker #Push the image onto the Docker registry. + - sudo docker push gitlab.jonasled.de/jonasled/url_shorter_docker:beta #Push the image onto the Docker registry. -build: #This will be executed on every push. With this script the beta image will be build + +build-release: #This will be executed if you oush on master, it makes a new release (latest) image stage: build + only: + - master script: - - echo "building for branch $CI_COMMIT_REF_NAME" + - export version='cat VERSION' + - echo "building branch $CI_COMMIT_REF_NAME, Version $version" + - curl -X POSRT --silen --show-error --fail "https://gitlab.jonasled.de/api/v4/projects/${CI_PROJECT_ID}/repository/tags?tag_name=$version&ref=${CI_COMMIT_SHS}&private_token=${GITLAB_TOKEN}" #Tag the current commit with the version. - sudo docker image prune -f #Delete old unused images - - sudo docker build -t gitlab.jonasled.de/jonasled/url_shorter_docker:beta . #Build the image with the name already set to push + - sudo docker build -t gitlab.jonasled.de/jonasled/url_shorter_docker . #Build the image with the name already set to push - sudo docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY #Login to docker registry, username and password will be filled while executing - - sudo docker push gitlab.jonasled.de/jonasled/url_shorter_docker:beta #Push the image onto the Docker registry. + - sudo docker push gitlab.jonasled.de/jonasled/url_shorter_docker #Push the image onto the Docker registry. + deploy: stage: deploy -- GitLab