push-release.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. # This script pushes a built image to a registry.
  3. #
  4. # Set OS_PUSH_BASE_REGISTRY to prefix the destination images e.g.
  5. # OS_PUSH_BASE_REGISTRY="docker.io/"
  6. #
  7. # Set OS_PUSH_TAG with a comma-separated list for pushing same image
  8. # to multiple tags e.g.
  9. # OS_PUSH_TAG="latest,v3.6"
  10. set -o errexit
  11. set -o nounset
  12. set -o pipefail
  13. starttime=$(date +%s)
  14. # image name without repo or tag.
  15. image="${PREFIX:-docker.io/openshift/origin-ansible}"
  16. # existing local tag on the image we want to push
  17. source_tag="${OS_TAG:-latest}"
  18. # Enable retagging a build with one or more tags for push
  19. IFS=',' read -r -a push_tags <<< "${OS_PUSH_TAG:-latest}"
  20. registry="${OS_PUSH_BASE_REGISTRY:-}"
  21. # force push if available
  22. PUSH_OPTS=""
  23. if docker push --help | grep -q force; then
  24. PUSH_OPTS="--force"
  25. fi
  26. set -x
  27. for tag in "${push_tags[@]}"; do
  28. docker tag "${image}:${source_tag}" "${registry}${image}:${tag}"
  29. docker push ${PUSH_OPTS} "${registry}${image}:${tag}"
  30. done
  31. set +x
  32. endtime=$(date +%s); echo "$0 took $(($endtime - $starttime)) seconds"; exit 0