k8s.io/registry.k8s.io@v0.3.1/hack/make-rules/deploy.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2022 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit -o nounset -o pipefail 18 19 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" 20 cd "${REPO_ROOT}" 21 22 # if we're in cloudbuild then we might want to change the project to point 23 # at where we're deploying instead of deploying from 24 if [[ -n "${CLOUDBUILD_SET_PROJECT:-}" ]]; then 25 gcloud config set project "${CLOUDBUILD_SET_PROJECT:?}" 26 fi 27 28 # make sure we have a k8s.io clone for the prod terraform 29 k8sio_dir="$(cd "${REPO_ROOT}"/../k8s.io && pwd -P)" 30 if [[ ! -d "${k8sio_dir}" ]]; then 31 >&2 echo "Deploying requires a github.com/kubernetes/k8s.io clone at ./../k8s.io" 32 >&2 echo "FAIL" 33 exit 1 34 fi 35 36 # install crane and get current image digest 37 TAG="${TAG:-"$(date +v%Y%m%d)-$(git describe --always --dirty)"}" 38 # TODO: this can't actually be overridden currently 39 # the terraform always uses the default here 40 IMAGE_REPO="${IMAGE_REPO:-gcr.io/k8s-staging-infra-tools/archeio}" 41 GOBIN="${REPO_ROOT}/bin" go install github.com/google/go-containerregistry/cmd/crane 42 IMAGE_DIGEST="${IMAGE_DIGEST:-$(bin/crane digest "${IMAGE_REPO}:${TAG}")}" 43 export IMAGE_DIGEST 44 45 # cd to staging terraform and apply 46 cd "${k8sio_dir}"/infra/gcp/terraform/k8s-infra-oci-proxy 47 # use tfswitch to control terraform version based on sources, if available 48 if command -v tfswitch >/dev/null; then 49 tfswitch 50 fi 51 terraform -v 52 terraform init 53 # NOTE: this must use :? expansion to ensure we will not run with unset variables 54 (set -x; terraform apply -auto-approve -var digest="${IMAGE_DIGEST:?}")