Last active
May 25, 2023 00:41
-
-
Save atrauzzi/924a09acdc5234568726b8507f5c9071 to your computer and use it in GitHub Desktop.
Google Cloud Run Get Project Hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROJECT=${1:-"$(gcloud config get-value project)"} | |
REGION=${2:-"us-central1"} | |
IMAGE="hub.docker.com/_/nginx" | |
{ | |
gcloud services enable "run.googleapis.com" --project="${PROJECT}" | |
gcloud auth configure-docker --quiet | |
docker pull nginx | |
docker tag nginx "${IMAGE}" | |
docker push "${IMAGE}" | |
gcloud run deploy \ | |
"hash-temp" \ | |
--project="${PROJECT}" \ | |
--image="${IMAGE}" \ | |
--region="${REGION}" \ | |
--port=80 \ | |
--no-allow-unauthenticated \ | |
--quiet \ | |
--format="json" | |
SERVICE_INFO=$(gcloud run services describe \ | |
"hash-temp" \ | |
--project="${PROJECT}" \ | |
--region="${REGION}" \ | |
--format="json") | |
HASH=$(echo ${SERVICE_INFO} | jq -cr '.["status"]["address"]["url"] | match(".*hash\\-temp\\-(.*)\\-.*\\.run\\.app").captures[0].string') | |
gcloud run services delete \ | |
"hash-temp" \ | |
--project="${PROJECT}" \ | |
--region="${REGION}" \ | |
--quiet | |
} &> /dev/null | |
echo "${HASH}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This 🐌💦 slow script will get you the per-project hash for your Google Cloud Run services.
It simply pulls nginx from docker hub, pushes it to your project container registry, instantiates a Cloud Run service with it, inspects it for the hash, deletes the service and outputs the hash.