github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/deploy.sh (about)

     1  #!/bin/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  # TODO(fejta): update this and hack/print-workspace-status to customize STABLE_*_CLUSTER
    28  
    29  if [[ -n "${GOOGLE_APPLICATION_CREDENTIALS:-}" ]]; then
    30    echo "Detected GOOGLE_APPLICATION_CREDENTIALS, activating..." >&2
    31    gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
    32  fi
    33  
    34  case "${1:-}" in
    35  "--confirm")
    36      ;;
    37  "")
    38    read -p "Deploy prow to prod [no]: " confirm
    39    if [[ "${confirm}" != y* ]]; then
    40      exit 1
    41    fi
    42    ;;
    43  *)
    44    echo "Usage: $(basename "$0") [--confirm]"
    45    exit 1
    46  esac
    47  
    48  # See https://misc.flogisoft.com/bash/tip_colors_and_formatting
    49  
    50  color-green() { # Green
    51    echo -e "\x1B[1;32m${@}\x1B[0m"
    52  }
    53  
    54  color-context() { # Bold blue
    55    echo -e "\x1B[1;34m${@}\x1B[0m"
    56  }
    57  
    58  color-missing() { # Yellow
    59    echo -e "\x1B[1;33m${@}\x1B[0m"
    60  }
    61  
    62  ensure-context() {
    63    local proj=$1
    64    local zone=$2
    65    local cluster=$3
    66    local context="gke_${proj}_${zone}_${cluster}"
    67    echo -n " $(color-context "$context")"
    68    kubectl config get-contexts "$context" &> /dev/null && return 0
    69    echo ": $(color-missing MISSING), getting credentials..."
    70    gcloud container clusters get-credentials --project="$proj" --zone="$zone" "$cluster"
    71    kubectl config get-contexts "$context" > /dev/null
    72    echo -n "Ensuring contexts exist:"
    73  }
    74  
    75  echo -n "Ensuring contexts exist:"
    76  current_context=$(kubectl config current-context 2>/dev/null || true)
    77  restore-context() {
    78    if [[ -n "$current_context" ]]; then
    79      kubectl config set-context "$current_context"
    80    fi
    81  }
    82  trap restore-context EXIT
    83  ensure-context k8s-prow-builds us-central1-f prow
    84  ensure-context k8s-prow us-central1-f prow
    85  echo " $(color-green done), Deploying prow..."
    86  for s in {5..1}; do
    87      echo -n $'\r'"in $s..."
    88      sleep 1s
    89  done
    90  bazel run //prow/cluster:production.apply --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64
    91  echo "$(color-green SUCCESS)"