forked from cyberark/conjur
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-image.sh
More file actions
executable file
·70 lines (55 loc) · 2 KB
/
Copy pathpush-image.sh
File metadata and controls
executable file
·70 lines (55 loc) · 2 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash -e
# Push the 'conjur' image to various Docker registries
# Push stable images on master branch
# Release images can be created by passing the desired tag to this script
# Ex: ./push-image 4.9.5.1
# shellcheck disable=SC1091
. version_utils.sh
TAG="${1:-$(version_tag)}"
VERSION="$(< VERSION)"
SOURCE_IMAGE="conjur:$TAG"
CONJUR_REGISTRY=registry.tld
IMAGE_NAME=cyberark/conjur
# both old-style 'conjur' and new-style 'cyberark/conjur'
INTERNAL_IMAGES=`echo $CONJUR_REGISTRY/{conjur,$IMAGE_NAME}`
# for releases, push to dockerhub and quay.io in addition to our registry
RELEASE_IMAGES=`echo $INTERNAL_IMAGES {,quay.io/}$IMAGE_NAME`
function main() {
echo "TAG = $TAG"
echo "VERSION = $VERSION"
# always push VERSION-SHA tags to our registry
tag_and_push $TAG $INTERNAL_IMAGES
# if on master (as determined by examining Jenkins-set envar BRANCH_NAME)
# assume tests have passed and push to latest and stable tags, too
if [ "$BRANCH_NAME" = "master" ]; then
tag_and_push latest $INTERNAL_IMAGES
# only do 1-stable and 1.2-stable for 1.2.3-dev
# (1.2.3-stable doesn't make sense if there is a released version called 1.2.3)
for v in `gen_versions $VERSION`; do
tag_and_push $v-stable $INTERNAL_IMAGES
done
fi
git fetch --tags || : # Jenkins brokenness workaround
local git_description=`git describe`
# if on tag matching the VERSION, also push releases to dockerhub and quay
if [[ $git_description = v$VERSION ]]; then
echo "Revision $git_description matches version exactly, pushing releases..."
for v in latest $VERSION `gen_versions $VERSION`; do
tag_and_push $v $RELEASE_IMAGES
done
else
echo "Revision $git_description does not match version $VERSION exactly, not releasing."
fi
}
# tag_and_publish tag image1 image2 ...
function tag_and_push() {
local tag="$1"
shift
for image in $*; do
local target=$image:$tag
echo Tagging and pushing $target...
docker tag "$SOURCE_IMAGE" $target
docker push $target
done
}
main