mwvgroup / pittgoogle-user-demos

GNU General Public License v3.0
2 stars 0 forks source link

Update deployment script for Cloud Run #9

Closed hernandezc1 closed 1 year ago

hernandezc1 commented 2 years ago

The purpose of this pull request is to create a deployment script for Cloud Run and update as needed (eventually we want to replace this with something that uses Cloud Workflows, Cloud Build, and/or Terraform). See Issue #2 for additional information on this.

The objectives in creating the deployment script are to:

In order to deploy the classifier module to Cloud Run, the script must:

It is important for the reader to be aware that Cloud Run modules are triggered via a Pub/Sub subscription. Once the Cloud Run module is deployed, its URL will be printed to the screen. This URL is needed in order to create the Pub/Sub subscription trigger. For now, the URL must be manually copy-pasted into the following code in order to create the subscription:

subscrip="elasticc-loop-${testid}"
topic="elasticc-loop"
topic_project="avid-heading-329016"
url="<copy-paste the Cloud Run URL here>"
route="/"
runinvoker_svcact="cloud-run-invoker@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com"

gcloud pubsub subscriptions create "${subscrip}" \
    --topic "${topic}" \
    --topic-project "${topic_project}" \
    --ack-deadline=600 \
    --push-endpoint="${url}${route}" \
    --push-auth-service-account="${runinvoker_svcact}"

Future work includes figuring out a way to automate this.

The Cloud Run module will be active as soon as the subscription is created. To stop the Cloud Run module, you must delete the trigger subscription:

gcloud pubsub subscriptions delete "${subscrip}"