Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
ci: switch to secret manager for samples tests (#30)
Browse files Browse the repository at this point in the history
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/1a5efa2b-7082-489a-87a2-7d303da2cd98/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@6d3eed6
Source-Link: googleapis/synthtool@d1addcd
  • Loading branch information
yoshi-automation committed Jun 15, 2020
1 parent 02d5303 commit a3f1d34
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .kokoro/build.sh
Expand Up @@ -39,7 +39,7 @@ retry_with_backoff 3 10 \

# if GOOGLE_APPLICATION_CREDIENTIALS is specified as a relative path prepend Kokoro root directory onto it
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS})
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
fi

RETURN_CODE=0
Expand Down
16 changes: 6 additions & 10 deletions .kokoro/nightly/samples.cfg
Expand Up @@ -24,19 +24,15 @@ env_vars: {

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "keystore/73713_java_it_service_account"
value: "secret_manager/java-docs-samples-service-account"
}

env_vars: {
key: "ENABLE_BUILD_COP"
value: "true"
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
}

before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "java_it_service_account"
}
}
env_vars: {
key: "ENABLE_BUILD_COP"
value: "true"
}
43 changes: 43 additions & 0 deletions .kokoro/populate-secrets.sh
@@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2020 Google LLC.
#
# 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.

set -eo pipefail

function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
function msg { println "$*" >&2 ;}
function println { printf '%s\n' "$(now) $*" ;}


# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
mkdir -p ${SECRET_LOCATION}
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
do
msg "Retrieving secret ${key}"
docker run --entrypoint=gcloud \
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
gcr.io/google.com/cloudsdktool/cloud-sdk \
secrets versions access latest \
--project cloud-devrel-kokoro-resources \
--secret ${key} > \
"${SECRET_LOCATION}/${key}"
if [[ $? == 0 ]]; then
msg "Secret written to ${SECRET_LOCATION}/${key}"
else
msg "Error retrieving secret ${key}"
fi
done
14 changes: 5 additions & 9 deletions .kokoro/presubmit/samples.cfg
Expand Up @@ -24,14 +24,10 @@ env_vars: {

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "keystore/73713_java_it_service_account"
value: "secret_manager/java-docs-samples-service-account"
}

before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "java_it_service_account"
}
}
}
env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-docs-samples-service-account"
}
2 changes: 2 additions & 0 deletions .kokoro/trampoline.sh
Expand Up @@ -21,4 +21,6 @@ function cleanup() {
echo "cleanup";
}
trap cleanup EXIT

$(dirname $0)/populate-secrets.sh # Secret Manager secrets.
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"
4 changes: 2 additions & 2 deletions synth.metadata
Expand Up @@ -4,7 +4,7 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/java-accesscontextmanager.git",
"sha": "37186ff8b8faee56cc4394553e24e12486638013"
"sha": "02d530301d8866deafecb773492c16193077bdf7"
}
},
{
Expand All @@ -19,7 +19,7 @@
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "987270824bd26f6a8c716d5e2022057b8ae7b26e"
"sha": "6d3eed67a45fd58f9c7bfa173c32e4fd4fed058f"
}
}
],
Expand Down

0 comments on commit a3f1d34

Please sign in to comment.