helloworld-shell/tests.cloudbuild.yaml (65 lines of code) (raw):
steps:
- id: "Build Container Image"
name: "gcr.io/cloud-builders/docker:latest"
dir: "${_SAMPLE_DIR}"
args: ["build", "-t", "${_IMAGE_NAME}", "."]
- id: "Push Container Image"
name: "gcr.io/cloud-builders/docker:latest"
args: ["push", "${_IMAGE_NAME}"]
- id: "Deploy to Cloud Run"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk:$_CLOUDSDK_VERSION"
entrypoint: /bin/bash
args:
- "-c"
- |
gcloud run deploy ${_SERVICE}-$BUILD_ID \
--image ${_IMAGE_NAME} \
--no-allow-unauthenticated
- id: "Get Cloud Run URL"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk:$_CLOUDSDK_VERSION"
entrypoint: "/bin/bash"
args:
- "-c"
- |
set -e
. /workspace/testing/cloudbuild-templates/common.sh
echo $(get_url ${BUILD_ID}) > _service_url
echo "Cloud Run URL for ${_SERVICE}-$BUILD_ID is $(cat _service_url)"
echo $(get_idtoken) > _id_token
if [[ -z $(cat _id_token) ]]; then exit 1; fi
env:
# Make substitutions available in shell script.
- "_SECRET_NAME=${_SECRET_NAME}"
- "_RUNNER_IDENTITY=${_RUNNER_IDENTITY}"
- "_SERVICE=${_SERVICE}"
# This does not seem like expected behavior. For example:
- id: "Integration Tests"
# TODO: Update the following image name, entrypoint, and args to fit your testing needs
name: "gcr.io/cloud-builders/curl"
entrypoint: "/bin/sh"
args:
- "-c"
- |
set -e
./testing/cloudbuild-templates/retry.sh "curl -si --fail --show-error -H 'Authorization: Bearer $(cat _id_token)' '$(cat _service_url)'"
- id: "Teardown"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk:$_CLOUDSDK_VERSION"
entrypoint: "/bin/bash"
args:
- "-c"
- |
set -x
gcloud --quiet container images delete ${_IMAGE_NAME}
gcloud --quiet run services delete ${_SERVICE}-$BUILD_ID --region ${_SERVICE_REGION}
set +x
echo "View build details in the console: https://console.cloud.google.com/cloud-build/builds/${BUILD_ID}"
# Uncomment if skipping teardown to associate build with container image.
# images:
# - '${_IMAGE_NAME}'
options:
env:
- "CLOUDSDK_RUN_REGION=${_SERVICE_REGION}"
- "GOOGLE_CLOUD_PROJECT=${PROJECT_ID}"
dynamicSubstitutions: true
# TODO: Update these User-defined substitutions
substitutions:
_SERVICE: helloworld-shell
_SAMPLE_DIR: helloworld-shell
_SERVICE_REGION: us-central1
_CLOUDSDK_VERSION: latest
_AR_REPO_NAME: samples
_AR_REPO_REGION: us-central1
_IMAGE_NAME: ${_AR_REPO_REGION}-docker.pkg.dev/${PROJECT_ID}/${_AR_REPO_NAME}/${_SERVICE}:${SHORT_SHA} # Tag docker image with git commit sha