#!/bin/bash # Copyright 2021 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # usage: ci-gce.sh # This program build all images for capi gce ################################################################################ set -o errexit set -o nounset set -o pipefail [[ -n ${DEBUG:-} ]] && set -o xtrace CAPI_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. cd "${CAPI_ROOT}" || exit 1 # shellcheck source=ensure-go.sh source "./hack/ensure-go.sh" # shellcheck source=ensure-boskosctl.sh source "./hack/ensure-boskosctl.sh" # Verify the required Environment Variables are present. : "${GOOGLE_APPLICATION_CREDENTIALS:?Environment variable empty or not defined.}" function boskosctlwrapper() { boskosctl --server-url http://"${BOSKOS_HOST}" --owner-name "cluster-api-provider-gcp" "${@}" } cleanup() { echo "Cleaning up image" filter="name~cluster-api-ubuntu-*" (gcloud compute images list --project "$GCP_PROJECT" \ --no-standard-images --format="table[no-heading](name)" --filter="${filter}" \ | awk '{print "gcloud compute images delete --quiet --project '"$GCP_PROJECT"' "$1" " "\n"}' \ | bash ) || true # stop boskos heartbeat if [ -n "${BOSKOS_HOST:-}" ]; then boskosctlwrapper release --name "${RESOURCE_NAME}" --target-state used fi exit "${test_status}" } trap cleanup EXIT if [[ -z "$GOOGLE_APPLICATION_CREDENTIALS" ]]; then cat <