-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Kokoro tests for Cloud Run #1629
Changes from 2 commits
c69df48
ee5cbe6
866b82a
f60317e
bd54057
f27a6e7
9ce91a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2019 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 | ||
requireEnv() { | ||
test "${!1}" || (echo "Environment Variable '$1' not found" && exit 1) | ||
} | ||
requireEnv SAMPLE_NAME | ||
|
||
# Version is in the format <PR#>-<GIT COMMIT SHA>. | ||
# Ensures PR-based triggers of the same branch don't collide if Kokoro attempts | ||
# to run them concurrently. | ||
export SAMPLE_VERSION="${KOKORO_GIT_COMMIT:-latest}" | ||
# Builds not triggered by a PR will fall back to the commit hash then "latest". | ||
SUFFIX=${KOKORO_GITHUB_PULL_REQUEST_NUMBER:-${SAMPLE_VERSION:0:12}} | ||
export SERVICE_NAME="${SAMPLE_NAME}-${SUFFIX}" | ||
export CONTAINER_IMAGE="gcr.io/${GOOGLE_CLOUD_PROJECT}/run-${SAMPLE_NAME}:${SAMPLE_VERSION}" | ||
|
||
# Build the service | ||
set -x | ||
gcloud builds submit --tag="${CONTAINER_IMAGE}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some mechanism setup to only keep N versions, or is this just going to grow forever? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a clean up function. I've confirmed it's working. I'm also going to check a few times over the next month to confirm there's nothing broken. |
||
set +x | ||
|
||
echo '---' | ||
set -x | ||
gcloud beta run deploy "${SERVICE_NAME}" \ | ||
--image="${CONTAINER_IMAGE}" \ | ||
--region="${REGION:-us-central1}" \ | ||
--platform=managed \ | ||
--quiet | ||
|
||
echo 'Cloud Run Links:' | ||
echo "- Logs: https://console.cloud.google.com/logs/viewer?project=${GOOGLE_CLOUD_PROJECT}&resource=cloud_run_revision%2Fservice_name%2F${SERVICE_NAME}" | ||
echo "- Console: https://console.cloud.google.com/run/detail/${REGION:-us-central1}/${SERVICE_NAME}/metrics?project=${GOOGLE_CLOUD_PROJECT}" | ||
|
||
echo | ||
echo '---' | ||
echo | ||
|
||
# Register post-test cleanup. | ||
# Only needed if deploy completed. | ||
function cleanup { | ||
set -x | ||
gcloud --quiet container images delete "${CONTAINER_IMAGE}" || true | ||
gcloud beta run services delete ${SERVICE_NAME} \ | ||
--platform=managed \ | ||
--region="${REGION:-us-central1}" \ | ||
--quiet | ||
} | ||
trap cleanup EXIT | ||
|
||
# Do not use exec to preserve trap behavior. | ||
"$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want the script to fail if it doesn't build or deploy the container.