github.com/GoogleCloudPlatform/testgrid@v0.0.174/images/push.sh (about)

     1  #!/bin/bash
     2  # Copyright 2019 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  # * activate GOOGLE_APPLICATION_CREDENTIALS and configure-docker if set
    19  # * run //images:push, retrying if necessary
    20  
    21  set -o errexit
    22  set -o nounset
    23  set -o pipefail
    24  
    25  # Coloring Macros
    26  # See https://misc.flogisoft.com/bash/tip_colors_and_formatting
    27  
    28  color-version() { # Bold blue
    29    echo -e "\x1B[1;34m${@}\x1B[0m"
    30  }
    31  
    32  color-error() { # Light red
    33    echo -e "\x1B[91m${@}\x1B[0m"
    34  }
    35  
    36  color-target() { # Bold cyan
    37    echo -e "\x1B[1;33m${@}\x1B[0m"
    38  }
    39  
    40  gcloud auth configure-docker
    41  
    42  # Build and push the current commit, failing on any uncommitted changes.
    43  new_version="v$(date -u '+%Y%m%d')-$(git describe --tags --always --dirty)"
    44  echo -e "version: $(color-version ${new_version})" >&2
    45  if [[ "${new_version}" == *-dirty ]]; then
    46    echo -e "$(color-error ERROR): uncommitted changes to repo" >&2
    47    echo "  Fix with git commit" >&2
    48    exit 1
    49  fi
    50  
    51  bazel=$(command -v bazelisk || command -v bazel)
    52  
    53  echo -e "Pushing $(color-version ${new_version})" >&2
    54  # Remove retries after https://github.com/bazelbuild/rules_docker/issues/673
    55  for i in {1..3}; do
    56    if "$bazel" run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //images:push; then
    57      exit 0
    58    elif [[ "$i" == 3 ]]; then
    59      echo "Failed"
    60      exit 1
    61    fi
    62    echo "Failed attempt $i, retrying..."
    63    sleep 5
    64  done