sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/push.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2018 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # bump.sh will 17 # * ensure there are no pending changes 18 # * optionally activate GOOGLE_APPLICATION_CREDENTIALS and configure-docker if set 19 # * run //prow:release-push to build and push prow images 20 # * update all the cluster/*.yaml files to use the new image tags 21 22 set -o errexit 23 set -o nounset 24 set -o pipefail 25 26 # TODO(fejta): rewrite this in a better language REAL SOON 27 28 # See https://misc.flogisoft.com/bash/tip_colors_and_formatting 29 30 color-version() { # Bold blue 31 echo -e "\x1B[1;34m${@}\x1B[0m" 32 } 33 34 color-error() { # Light red 35 echo -e "\x1B[91m${@}\x1B[0m" 36 } 37 38 color-target() { # Bold cyan 39 echo -e "\x1B[1;33m${@}\x1B[0m" 40 } 41 42 # darwin is great 43 SED=sed 44 if which gsed &>/dev/null; then 45 SED=gsed 46 fi 47 if ! (${SED} --version 2>&1 | grep -q GNU); then 48 echo "!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'." >&2 49 exit 1 50 fi 51 52 if [[ -n "${GOOGLE_APPLICATION_CREDENTIALS:-}" ]]; then 53 echo "Detected GOOGLE_APPLICATION_CREDENTIALS, activating..." >&2 54 gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}" 55 fi 56 57 gcloud config get-value account || { echo "Debugging, ignore failure"; true; } 58 gcloud auth configure-docker 59 gcloud config get-value account || { echo "Debugging, ignore failure"; true; } 60 61 # Build and push the current commit, failing on any uncommitted changes. 62 new_version="v$(date -u '+%Y%m%d')-$(git describe --tags --always --dirty)" 63 echo -e "version: $(color-version ${new_version})" >&2 64 if [[ "${new_version}" == *-dirty ]]; then 65 echo -e "$(color-error ERROR): uncommitted changes to repo" >&2 66 echo " Fix with git commit" >&2 67 exit 1 68 fi 69 echo -e "Pushing $(color-version ${new_version}) via $(color-target //prow:release-push --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64) ..." >&2 70 # Remove retries after https://github.com/bazelbuild/rules_docker/issues/673 71 for i in {1..3}; do 72 if bazel run //prow:release-push --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64; then 73 exit 0 74 elif [[ "$i" == 3 ]]; then 75 echo "Failed" 76 exit 1 77 fi 78 echo "Failed attempt $i, retrying..." 79 sleep 5 80 done