Deploy to GCP using bash/cli (from Cloud Shell for example)
⚠️
Be sure to replace your PROJECT_ID environment variable in these scripts
# so we can push from a local docker registry
gcloud auth login
# project name is phx-danl
export PROJECT_ID="pdcp-cloud-009-danl"
export REGION="northamerica-northeast1"
export ARTIFACT_REGISTRY_REPO_NAME="garden-repo"
gcloud config set project ${PROJECT_ID}
gcloud config set run/region ${REGION}
# Allow our docker client to read/write from the registry (for later)
gcloud auth configure-docker ${REGION}-docker.pkg.dev
# docker tag <LOCAL_IMAGE_NAME> gcr.io/<PROJECT_ID>/<IMAGE_NAME>
# e.g.: Pushes should be of the form docker push HOST-NAME/PROJECT-ID/REPOSITORY/IMAGE:TAG
docker tag compose-time-go:latest ${REGION}-docker.pkg.dev/${PROJECT_ID}/${ARTIFACT_REGISTRY_REPO_NAME}/time-go:latest
docker push ${REGION}-docker.pkg.dev/${PROJECT_ID}/${ARTIFACT_REGISTRY_REPO_NAME}/time-go:latest
gcloud run deploy time-go --allow-unauthenticated --image ${REGION}-docker.pkg.dev/pdcp-cloud-009-danl/${ARTIFACT_REGISTRY_REPO_NAME}/time-go:latest
# Now, in a loop for each service; tag and push to the registry, then deploy to cloud run
for i in time-go time-deno site-nginx site-caddy; do
# destination tag
docker tag compose-$i:latest ${REGION}-docker.pkg.dev/${PROJECT_ID}/${ARTIFACT_REGISTRY_REPO_NAME}/$i:latest
# push to registry
docker push ${REGION}-docker.pkg.dev/${PROJECT_ID}/${ARTIFACT_REGISTRY_REPO_NAME}/$i:latest
# deploy to cloud run
gcloud run deploy $i --allow-unauthenticated --image ${REGION}-docker.pkg.dev/pdcp-cloud-009-danl/${ARTIFACT_REGISTRY_REPO_NAME}/$i:latest
doneHey!
This is how you install hey (opens in a new tab) For the Google Cloud shell:
wget https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
chmod +x hey_linux_amd64 && sudo mv hey_linux_amd64 /usr/local/bin/hey
# you will have a differenet hostname prefix (2m3hexrmga-nn.a.run.app in my case)
# 10000 requests, 100 concurrent
hey -n 10000 -c 100 https://time-go-2m3hexrmga-nn.a.run.app | grep 'Requests/sec'
hey -n 10000 -c 100 https://time-deno-2m3hexrmga-nn.a.run.app | grep 'Requests/sec'Testing from Cloud Shell:
| Service | Requests/sec |
|---|---|
| time-go | 4298.4 |
| time-deno | 13014.5 |
DNS
After delegating my my own subdomain dl.phac.alpha.canada.ca to Google Cloud DNS in my own project,
I created a CNAME record for each of the services pointing to time-go-2m3hexrmga-nn.a.run.app
This would be much easier with Cloud Run domain mappings, but they are not supported in any region that we are allowed to use inside our GCP environment.
Traces of my failed attempt at provisioning a domain mapping:
gcloud run services list
# get the current url
gcloud run services describe site-nginx --format="value(status.url)"
# returns https://site-nginx-2m3hexrmga-nn.a.run.app
# create the CNAME entry: site-nginx.r.dl.phac.alpha.canada.ca
# which point to the url above; notice the trailing dot "site-nginx-2m3hexrmga-nn.a.run.app."
export PROJECT_ID="pdcp-cloud-009-danl"
gcloud dns record-sets transaction start --zone=dl-phac-alpha-canada-ca --project=${PROJECT_ID}
gcloud dns record-sets transaction add --zone=dl-phac-alpha-canada-ca --name=site-nginx.r.dl.phac.alpha.canada.ca. --ttl=300 --type=CNAME "site-nginx-2m3hexrmga-nn.a.run.app." --project=${PROJECT_ID}
gcloud dns record-sets transaction execute --zone=dl-phac-alpha-canada-ca --project=${PROJECT_ID}
# Confirm it worked
gcloud dns record-sets list --zone=dl-phac-alpha-canada-ca --project=${PROJECT_ID}
gcloud dns record-sets describe --zone=dl-phac-alpha-canada-ca --project=${PROJECT_ID} --type CNAME site-nginx.r.dl.phac.alpha.canada.ca
# Remove it
gcloud dns record-sets delete --zone=dl-phac-alpha-canada-ca --project=${PROJECT_ID} --type CNAME site-nginx.r.dl.phac.alpha.canada.ca