From 65122639833fbc27c7121224393ae500a3eb3581 Mon Sep 17 00:00:00 2001 From: Leonid Makarov Date: Fri, 22 Jun 2018 15:41:17 -0700 Subject: [PATCH] Make sure the latest release and stable tags match. Closes #56 - Moved the push script into a standalone file - scripts/docker-push.sh --- .travis.yml | 24 +------------ scripts/docker-push.sh | 80 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 23 deletions(-) create mode 100755 scripts/docker-push.sh diff --git a/.travis.yml b/.travis.yml index ee8d56cf..1ca4040d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,29 +32,7 @@ script: after_success: - docker image ls - - | - if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then - [[ "${TRAVIS_BRANCH}" == "develop" ]] && TAG="edge-php${VERSION}" - [[ "${TRAVIS_BRANCH}" == "master" ]] && TAG="php${VERSION}" - [[ "${TRAVIS_TAG}" != "" ]] && TAG="${TRAVIS_TAG:1:3}-php${VERSION}" - - if [[ "$TAG" != "" ]]; then - docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}" - # Push edge, stable and release tags - # Base image - docker tag ${REPO}:build-${VERSION} ${REPO}:${TAG} - docker push ${REPO}:${TAG} - # Cloud9 flavor - docker tag ${REPO}:build-${VERSION}-ide ${REPO}:${TAG}-ide - docker push ${REPO}:${TAG}-ide - - # Push "latest" tag - if [[ "${TRAVIS_BRANCH}" == "master" ]] && [[ "${VERSION}" == "${LATEST_VERSION}" ]]; then - docker tag ${REPO}:build-${VERSION} ${REPO}:latest - docker push ${REPO}:latest - fi - fi - fi + - scripts/docker-push.sh after_failure: - cd ${TRAVIS_BUILD_DIR}/${VERSION} && make logs diff --git a/scripts/docker-push.sh b/scripts/docker-push.sh new file mode 100755 index 00000000..3a890e0b --- /dev/null +++ b/scripts/docker-push.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +# ----- Helper functions ----- # + +is_edge () +{ + [[ "${TRAVIS_BRANCH}" == "develop" ]] +} + +is_stable () +{ + [[ "${TRAVIS_BRANCH}" == "master" ]] +} + +is_release () +{ + [[ "${TRAVIS_TAG}" != "" ]] +} + +# Check whether the current build is for a pull request +is_pr () +{ + [[ "${TRAVIS_PULL_REQUEST}" == "false" ]] +} + +is_lates () +{ + [[ "${VERSION}" == "${LATEST_VERSION}" ]] +} + +# Tag and push an image +tag_and_push () +{ + local source=$1 + local target=$2 + + # Base image + docker tag ${source} ${target} + docker push ${target} + + # Cloud9 flavor + docker tag ${source}-ide ${target}-ide + docker push ${target}-ide +} + +# ---------------------------- # + +# Skip pull request builds +is_pr && exit + +# Figure out docker image tag +IMAGE_TAG_EDGE="edge-php${VERSION}" +IMAGE_TAG_STABLE="php${VERSION}" +IMAGE_TAG_RELEASE="${TRAVIS_TAG:1:3}-php${VERSION}" + +if is_edge; then + IMAGE_TAG=${IMAGE_TAG_EDGE} +elif is_stable; then + IMAGE_TAG=${IMAGE_TAG_STABLE} +elif is_release; then + IMAGE_TAG=${IMAGE_TAG_RELEASE} +else + # Exit if not on develop, master or release tag + exit +fi + +docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}" + +# Push images +tag_and_push ${REPO}:build-${VERSION} ${REPO}:${IMAGE_TAG} + +# For releases - push the stable image tags again to have them match the release tag +if is_release; then + tag_and_push ${REPO}:build-${VERSION} ${REPO}:${IMAGE_TAG} +fi + +# Push the "latest" tag for stable and release builds +if is_lates && (is_stable || is_release); then + tag_and_push ${REPO}:build-${VERSION} ${REPO}:latest +fi