|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2018 OpenCensus 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 | +# A script for installing necessary software on CI systems. |
| 17 | + |
| 18 | +set -ex |
| 19 | + |
| 20 | +if [ "${INSTALL_GCLOUD}" == "true" ]; then |
| 21 | + # Install gcloud |
| 22 | + if [ ! -d ${HOME}/gcloud/google-cloud-sdk ]; then |
| 23 | + mkdir -p ${HOME}/gcloud && |
| 24 | + wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz --directory-prefix=${HOME}/gcloud && |
| 25 | + cd "${HOME}/gcloud" && |
| 26 | + tar xzf google-cloud-sdk.tar.gz && |
| 27 | + ./google-cloud-sdk/install.sh --usage-reporting false --path-update false --command-completion false && |
| 28 | + cd "${TEST_BUILD_DIR}"; |
| 29 | + fi |
| 30 | +fi |
| 31 | + |
| 32 | +if [ -z "${CLOUDSDK_ACTIVE_CONFIG_NAME}" ]; then |
| 33 | + echo "You need to set CLOUDSDK_ACTIVE_CONFIG_NAME envvar." |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +if [ -z "${GOOGLE_PROJECT_ID}" ]; then |
| 38 | + echo "You need to set GOOGLE_PROJECT_ID envvar." |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +if [ -z "${CLOUDSDK_VERBOSITY}" ]; then |
| 43 | + CLOUDSDK_VERBOSITY='none' |
| 44 | +fi |
| 45 | + |
| 46 | +# gcloud configurations |
| 47 | +gcloud config configurations create ${CLOUDSDK_ACTIVE_CONFIG_NAME} || /bin/true # ignore failure |
| 48 | +gcloud config set project ${GOOGLE_PROJECT_ID} |
| 49 | +gcloud config set app/promote_by_default false |
| 50 | +gcloud config set verbosity ${CLOUDSDK_VERBOSITY} |
| 51 | + |
| 52 | +# Dump the credentials from the environment variable. |
| 53 | +php scripts/dump_credentials.php |
| 54 | + |
| 55 | +# Set the timeout |
| 56 | +gcloud config set container/build_timeout 3600 |
| 57 | + |
| 58 | +if [ ! -f "${PHP_DOCKER_GOOGLE_CREDENTIALS}" ]; then |
| 59 | + echo 'Please set PHP_DOCKER_GOOGLE_CREDENTIALS envvar.' |
| 60 | + exit 1 |
| 61 | +fi |
| 62 | + |
| 63 | +# Use the service account for gcloud operations. |
| 64 | +gcloud auth activate-service-account \ |
| 65 | + --key-file "${PHP_DOCKER_GOOGLE_CREDENTIALS}" |
| 66 | + |
| 67 | +if [ "${CIRCLECI}" == "true" ]; then |
| 68 | + # Need sudo on circleci: |
| 69 | + # https://discuss.circleci.com/t/gcloud-components-update-version-restriction/3725 |
| 70 | + # They also overrides the PATH to use |
| 71 | + # /opt/google-cloud-sdk/bin/gcloud so we can not easily use our |
| 72 | + # own gcloud |
| 73 | + sudo /opt/google-cloud-sdk/bin/gcloud -q components update beta |
| 74 | +else |
| 75 | + gcloud -q components update beta |
| 76 | +fi |
0 commit comments