Skip to content

Instantly share code, notes, and snippets.

@atrauzzi
Last active May 25, 2023 00:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save atrauzzi/924a09acdc5234568726b8507f5c9071 to your computer and use it in GitHub Desktop.
Save atrauzzi/924a09acdc5234568726b8507f5c9071 to your computer and use it in GitHub Desktop.
Google Cloud Run Get Project Hash
#!/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}"
@atrauzzi
Copy link
Author

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.

See: https://issuetracker.google.com/issues/148376224 and give it a +1 if you want a better option!

@mlazowik
Copy link

Thanks for the script!

and give it a +1 if you want a better option!

Please do this by clicking the star, not by writing a comment with "+1", everyone who starts the issue gets an email with each new comment.

Screenshot 2022-03-15 at 00 15 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment