Skip to content

Commit

Permalink
Be more strict on docker tag checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesage committed Aug 24, 2017
1 parent f1971ba commit 2ae1f85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 10 additions & 7 deletions hooks/post_push
Expand Up @@ -18,14 +18,17 @@ echo "Environment variables:
IMAGE_VERSION=$IMAGE_VERSION
"

if [[ "$DOCKER_TAG" =~ -alpha[0-9]*$ ]]; then
DOCKER_NEWTAG="alpha"
elif [[ "$DOCKER_TAG" =~ -beta[0-9]*$ ]]; then
DOCKER_NEWTAG="beta"
elif [[ "$DOCKER_TAG" =~ -rc[0-9]*$ ]]; then
DOCKER_NEWTAG="rc"
else
if [[ "$DOCKER_TAG" =~ v[0-9]+\.[0-9]+\.[0-9]+-alpha[0-9]+$ ]]; then
DOCKER_NEWTAG="$(echo "$DOCKER_TAG" | sed 's/-alpha[0-9]\+$/-alpha/')"
elif [[ "$DOCKER_TAG" =~ v[0-9]+\.[0-9]+\.[0-9]+-beta[0-9]+$ ]]; then
DOCKER_NEWTAG="$(echo "$DOCKER_TAG" | sed 's/-beta[0-9]\+$/-beta/')"
elif [[ "$DOCKER_TAG" =~ v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then
DOCKER_NEWTAG="$(echo "$DOCKER_TAG" | sed 's/-rc[0-9]\+$/-rc/')"
elif [[ "$DOCKER_TAG" =~ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
DOCKER_NEWTAG="latest"
else
echo "ERROR: Invalid docker tag."
exit 1
fi

echo "Adding tag '$DOCKER_NEWTAG' to image..."
Expand Down
5 changes: 2 additions & 3 deletions hooks/pre_build
Expand Up @@ -11,10 +11,9 @@ set -u # Treat unset variables as an error.

# Make sure the DOCKER_TAG has a supported format like:
# v1.0.0
# v0.1.0-beta
# v2.0.0-rc
# v0.1.0-beta1
# v2.0.0-rc2
if [[ ! "$DOCKER_TAG" =~ ^v[0-9\.]+(-(alpha|beta|rc)[0-9]*)?$ ]]; then
if [[ ! "$DOCKER_TAG" =~ ^v[0-9\.]+(-(alpha|beta|rc)[0-9]+)?$ ]]; then
echo "Unsupported DOCKER_TAG: $DOCKER_TAG"
exit 1
fi
Expand Down

0 comments on commit 2ae1f85

Please sign in to comment.