summaryrefslogtreecommitdiff
path: root/hooks/post_push
blob: 46f71bfe49ebec1bfe03938583c143ad6f075689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -exuo pipefail

export DOCKER_REPO=${DOCKER_REPO:-hairyhenderson/gomplate}
export DOCKER_TAG=${DOCKER_TAG:-latest}
export IMAGE_NAME=${IMAGE_NAME:-${DOCKER_REPO}:${DOCKER_TAG}}

docker push ${DOCKER_REPO}:artifacts

if [ "$DOCKER_TAG" == "latest" ]; then
  export SLIM_TAG="slim"
  export ALPINE_TAG="alpine"
else
  export SLIM_TAG="${DOCKER_TAG}-slim"
  export ALPINE_TAG="${DOCKER_TAG}-alpine"
fi

# Need to push the other images too
docker push $DOCKER_REPO:${SLIM_TAG}
docker push $DOCKER_REPO:${ALPINE_TAG}

# This magic figures out if we're currently on a tag (i.e. a release).
# We only want to have special tags for releases.
if (git describe --abbrev=0 --exact-match &>/dev/null); then
  tag=$(git describe --abbrev=0 --exact-match)
  # splits the major version from $tag - assumes it's a 3-part semver
  major=${tag%%\.*}
  # if we ever want minor tags, this is how
  # minor=${tag%\.*}
  docker tag $IMAGE_NAME $DOCKER_REPO:${tag}
  docker tag $IMAGE_NAME $DOCKER_REPO:stable
  docker tag $IMAGE_NAME $DOCKER_REPO:${major}
  docker tag $DOCKER_REPO:${SLIM_TAG} $DOCKER_REPO:${tag}-slim
  docker tag $DOCKER_REPO:${SLIM_TAG} $DOCKER_REPO:${major}-slim
  docker tag $DOCKER_REPO:${SLIM_TAG} $DOCKER_REPO:stable-slim
  docker tag $DOCKER_REPO:${ALPINE_TAG} $DOCKER_REPO:${tag}-alpine
  docker tag $DOCKER_REPO:${ALPINE_TAG} $DOCKER_REPO:${major}-alpine
  docker tag $DOCKER_REPO:${ALPINE_TAG} $DOCKER_REPO:stable-alpine
  docker push $DOCKER_REPO:${tag}
  docker push $DOCKER_REPO:${major}
  docker push $DOCKER_REPO:stable
  docker push $DOCKER_REPO:${tag}-slim
  docker push $DOCKER_REPO:${major}-slim
  docker push $DOCKER_REPO:stable-slim
  docker push $DOCKER_REPO:${tag}-alpine
  docker push $DOCKER_REPO:${major}-alpine
  docker push $DOCKER_REPO:stable-alpine
fi