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] 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