Skip to content

Commit

Permalink
find the corresponding docker image from git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed May 14, 2019
1 parent 8d17ee8 commit 834c8cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion ops/travis/deploy/production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions ops/travis/helpers/find_staging_version.sh
Original file line number Diff line number Diff line change
@@ -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
if [[ ${j} =~ ${GIT_COMMIT_SHA} ]]; then
echo "${j}"
exit 0
fi
done

0 comments on commit 834c8cb

Please sign in to comment.