summaryrefslogtreecommitdiffstats
path: root/hack/push-release.sh
blob: 1f41ab179a03c7bf407fb6fc9b2d9c97375d5db4 (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
#!/bin/bash

# This script pushes a built image to a registry.
#
# Set OS_PUSH_BASE_REGISTRY to prefix the destination images e.g.
# OS_PUSH_BASE_REGISTRY="docker.io/"
#
# Set OS_PUSH_TAG with a comma-separated list for pushing same image
# to multiple tags e.g.
# OS_PUSH_TAG="latest,v3.6"

set -o errexit
set -o nounset
set -o pipefail

starttime=$(date +%s)

# image name without repo or tag.
image="${PREFIX:-openshift/origin-ansible}"

# existing local tag on the image we want to push
source_tag="${OS_TAG:-latest}"

# Enable retagging a build with one or more tags for push
IFS=',' read -r -a push_tags <<< "${OS_PUSH_TAG:-latest}"
registry="${OS_PUSH_BASE_REGISTRY:-}"

# force push if available
PUSH_OPTS=""
if docker push --help | grep -q force; then
  PUSH_OPTS="--force"
fi

set -x
for tag in "${push_tags[@]}"; do
  docker tag "${image}:${source_tag}" "${registry}${image}:${tag}"
  docker push ${PUSH_OPTS} "${registry}${image}:${tag}"
done
set +x

endtime=$(date +%s); echo "$0 took $(($endtime - $starttime)) seconds"; exit 0