Skip to content

Commit

Permalink
Make sure the latest release and stable tags match. Closes #56
Browse files Browse the repository at this point in the history
- Moved the push script into a standalone file - scripts/docker-push.sh
  • Loading branch information
lmakarov committed Jun 22, 2018
1 parent 3f1e897 commit 6512263
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 23 deletions.
24 changes: 1 addition & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 80 additions & 0 deletions scripts/docker-push.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6512263

Please sign in to comment.