diff --git a/.travis.yml b/.travis.yml index f2e8b452768..f659c295896 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,23 +299,21 @@ 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 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 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