|
1 | | -#!/bin/bash -eu |
2 | | - |
3 | | -# Push the 'cli:5' image to Dockerhub when on the 'master' branch |
4 | | - |
5 | | -cd "$(git rev-parse --show-toplevel)" |
6 | | - |
7 | | -IMAGE='cyberark/conjur-cli' |
8 | | - |
9 | | -function tag_and_push() { |
10 | | - local image="$1" |
11 | | - local tag="$2" |
12 | | - local description="$3" |
13 | | - |
14 | | - echo "TAG = $tag, $description" |
15 | | - |
16 | | - docker tag "$image" "$image:$tag" |
17 | | - docker push "$image:$tag" |
18 | | -} |
19 | | - |
20 | | -version_tag="5-$(cat VERSION)" |
21 | | - |
22 | | -tag_and_push $IMAGE '5' 'latest image' |
23 | | -tag_and_push $IMAGE '5-latest' 'same as "5"' |
24 | | -tag_and_push $IMAGE $version_tag 'version-specific image' |
25 | | - |
26 | | -# push to legacy `conjurinc/cli5` tag |
27 | | -docker tag "$IMAGE" conjurinc/cli5:latest |
28 | | -docker push conjurinc/cli5:latest |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +readonly REGISTRY="cyberark" |
| 6 | +readonly VERSION="$(cat VERSION)" |
| 7 | +readonly VERSION_TAG="5-${VERSION}" |
| 8 | +readonly image_name="conjur-cli" |
| 9 | +readonly full_image_name="${REGISTRY}/${image_name}:latest" |
| 10 | + |
| 11 | +readonly TAGS=( |
| 12 | + "5" |
| 13 | + "5-latest" |
| 14 | + "$VERSION_TAG" |
| 15 | +) |
| 16 | + |
| 17 | +# fetching tags is required for git_description to work |
| 18 | +git fetch --tags |
| 19 | +git_description=$(git describe) |
| 20 | + |
| 21 | +# if it’s not a tagged commit, VERSION will have extra junk (i.e. -g666c4b2), so we won’t publish that commit |
| 22 | +# only when tag matches the VERSION, push VERSION and latest releases |
| 23 | +# and x and x.y releases |
| 24 | +#Ex: v5-6.2.1 |
| 25 | +if [ "$git_description" = "v${VERSION_TAG}" ]; then |
| 26 | + echo "Revision $git_description matches version $VERSION exactly. Pushing to Dockerhub..." |
| 27 | + |
| 28 | + for tag in "${TAGS[@]}"; do |
| 29 | + echo "Tagging and pushing $REGISTRY/$image_name:$tag" |
| 30 | + |
| 31 | + docker tag $full_image_name "$REGISTRY/$image_name:$tag" |
| 32 | + docker push "$REGISTRY/$image_name:$tag" |
| 33 | + done |
| 34 | + |
| 35 | + # push to legacy `conjurinc/cli5` tag |
| 36 | + docker tag $full_image_name conjurinc/cli5:latest |
| 37 | + docker push conjurinc/cli5:latest |
| 38 | +fi |
0 commit comments