From 0ed27ad2d99b7b927bd5d9e660fd1820c938e652 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Mon, 13 May 2019 21:00:03 +0200 Subject: [PATCH 1/6] fix version name --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4bb9cde44b0..cabb4b6e4e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -306,17 +306,17 @@ jobs: branch: staging - stage: deployment name: production - if: branch = staging git: depth: false - script: echo "Deploy production" + script: echo "Deploy production version $TRAVIS_TAG" deploy: - provider: script skip_cleanup: true script: ops/travis/deploy/production.sh on: - branch: staging + all_branches: true tags: true + condition: $TRAVIS_TAG =~ ^v[1-9][0-9]*.[0-9]+.[0-9]+$ notifications: email: on_success: never From 90ec2d949250f7039f41ce4795e1f6c4e3ab0778 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Mon, 13 May 2019 21:13:38 +0200 Subject: [PATCH 2/6] pass the correct TAG --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cabb4b6e4e0..f2e8b452768 100644 --- a/.travis.yml +++ b/.travis.yml @@ -316,7 +316,7 @@ jobs: on: all_branches: true tags: true - condition: $TRAVIS_TAG =~ ^v[1-9][0-9]*.[0-9]+.[0-9]+$ + condition: $TRAVIS_TAG =~ ^staging-\d{4}-[01][1-9]-[0123]\d.\d+.\b[0-9a-f]{5,40}\b$ notifications: email: on_success: never From 99f46780531ea08b0b04b82d7b41522cb599137e Mon Sep 17 00:00:00 2001 From: Sylvain <35365065+sanderegg@users.noreply.github.com> Date: Tue, 14 May 2019 08:08:30 +0200 Subject: [PATCH 3/6] clean up --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f2e8b452768..6d2b2fc58d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -288,7 +288,6 @@ jobs: script: echo "Deploy master" deploy: - provider: script - skip_cleanup: true script: bash ops/travis/deploy/master.sh on: branch: master @@ -300,18 +299,16 @@ jobs: script: echo "Deploy staging" deploy: - provider: script - skip_cleanup: true script: bash ops/travis/deploy/staging.sh on: branch: staging - stage: deployment - name: production + name: production/release git: depth: false script: echo "Deploy production version $TRAVIS_TAG" deploy: - provider: script - skip_cleanup: true script: ops/travis/deploy/production.sh on: all_branches: true From 8d17ee840a5d878455edfc296084adb93a9702f4 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Tue, 14 May 2019 08:27:12 +0200 Subject: [PATCH 4/6] add script to find docker tag from release version --- ops/travis/helpers/find_staging_version.sh | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ops/travis/helpers/find_staging_version.sh diff --git a/ops/travis/helpers/find_staging_version.sh b/ops/travis/helpers/find_staging_version.sh new file mode 100644 index 00000000000..339c58eef44 --- /dev/null +++ b/ops/travis/helpers/find_staging_version.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Usage: find_staging_version.sh +# returns the full image tag corresponding to the git tag name that shall be used + +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + +GIT_COMMIT_SHA=$(git show-ref -s ${TRAVIS_TAG}) +ORG=${DOCKER_REGISTRY} +REPO="webserver" + +# get token +echo "Retrieving token ..." +TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${DOCKER_USERNAME}'", "password": "'${DOCKER_PASSWORD}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) + +# get list of repositories +echo "Retrieving repository list ..." +REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/?page_size=100 | jq -r '.results|.[]|.name') + +# output images & tags +echo +echo "Images and tags for organization: ${ORG}" +echo +IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${REPO}/tags/?page_size=100 | jq -r '.results|.[]|.name') +for j in ${IMAGE_TAGS} +do +echo " - ${j}" +done \ No newline at end of file From 834c8cbb45952503a73af1b90ff8ba30bf9e5f51 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Tue, 14 May 2019 10:27:46 +0200 Subject: [PATCH 5/6] find the corresponding docker image from git tag --- ops/travis/deploy/production.sh | 6 +++++- ops/travis/helpers/find_staging_version.sh | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ops/travis/deploy/production.sh b/ops/travis/deploy/production.sh index 54a323e036a..6be1cf47108 100755 --- a/ops/travis/deploy/production.sh +++ b/ops/travis/deploy/production.sh @@ -5,7 +5,11 @@ IFS=$'\n\t' # pull the tagged staging build export DOCKER_IMAGE_PREFIX=${DOCKER_REGISTRY}/ -export DOCKER_IMAGE_TAG="${TRAVIS_TAG}" +# find the docker image tag +export TAG="${TRAVIS_TAG}" +export ORG=${DOCKER_REGISTRY} +export REPO="webserver" +export DOCKER_IMAGE_TAG=$(exec ops/travis/helpers/find_staging_version.sh) make pull # show current images on system diff --git a/ops/travis/helpers/find_staging_version.sh b/ops/travis/helpers/find_staging_version.sh index 339c58eef44..5a03814ce4a 100644 --- a/ops/travis/helpers/find_staging_version.sh +++ b/ops/travis/helpers/find_staging_version.sh @@ -1,29 +1,29 @@ #!/bin/bash # Usage: find_staging_version.sh +# # returns the full image tag corresponding to the git tag name that shall be used # http://redsymbol.net/articles/unofficial-bash-strict-mode/ set -euo pipefail IFS=$'\n\t' -GIT_COMMIT_SHA=$(git show-ref -s ${TRAVIS_TAG}) -ORG=${DOCKER_REGISTRY} -REPO="webserver" +echo "Retrieving SHA for tag ${TAG}" +GIT_COMMIT_SHA=$(git show-ref -s ${TAG}) +echo "Found SHA for tag ${GIT_COMMIT_SHA}" # get token echo "Retrieving token ..." TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${DOCKER_USERNAME}'", "password": "'${DOCKER_PASSWORD}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) -# get list of repositories -echo "Retrieving repository list ..." -REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/?page_size=100 | jq -r '.results|.[]|.name') - # output images & tags echo echo "Images and tags for organization: ${ORG}" -echo +echo "in repo ${REPO}" IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${REPO}/tags/?page_size=100 | jq -r '.results|.[]|.name') for j in ${IMAGE_TAGS} do -echo " - ${j}" -done \ No newline at end of file +if [[ ${j} =~ ${GIT_COMMIT_SHA} ]]; then +echo "${j}" +exit 0 +fi +done From eabd69522d08e4935709a376edebb4ead49a3ad5 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Tue, 14 May 2019 10:30:07 +0200 Subject: [PATCH 6/6] set travis tag to semantic version name --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6d2b2fc58d2..f659c295896 100644 --- a/.travis.yml +++ b/.travis.yml @@ -313,7 +313,7 @@ jobs: on: all_branches: true tags: true - condition: $TRAVIS_TAG =~ ^staging-\d{4}-[01][1-9]-[0123]\d.\d+.\b[0-9a-f]{5,40}\b$ + condition: $TRAVIS_TAG =~ ^v\d+.\d+.\d+$ notifications: email: on_success: never