mwvgroup / pittgoogle-user-demos

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

Add deployment script #2

Closed troyraen closed 1 year ago

troyraen commented 2 years ago

Add a deployment script + instructions for its use.

The script should:

For now, we should put in a script similar to the one we use to deploy a broker instance.

Eventually we will want to replace this with something cleaner that uses Cloud Workflows, Cloud Build, and/or Terraform.

troyraen commented 2 years ago

instruct Cloud Build to containerize the module and deploy it to Cloud Run

The script can skip this step until that stuff is added to the repo. (Update: this was added in #6. The deployment code is repeated below for convenience.)

troyraen commented 2 years ago

Additional files may need to be added as well. For example, the script will need access to the file that defines the BigQuery table schema.

troyraen commented 2 years ago

Here is the code to deploy to Cloud Run. Specifically, this will:

moduledir="classifier"  # assumes we're in the repo's root dir
config="${moduledir}/cloudbuild.yaml"

gcloud builds submit --config="${config}" \
  --substitutions=_SURVEY="${SURVEY}",_TESTID="${TESTID}" \
  "${moduledir}"

Once that deploys, the Cloud Run module's URL will be printed to the screen. We need that URL in order to create the Pub/Sub subscription that will trigger this module. I am working on automating this, but 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}"

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}"
troyraen commented 2 years ago

@hernandezc1 when creating the Pub/Sub subscription with the code above, pay attention to the subscrip, topic, and topic_project variables (in addition to the url). You will need to change them in order to test this module in the way that we talked about testing it on Zoom today. Note that the way I have those variables set above will work (what will it do, exactly?), or to be more specific, it should work and that is a test we will want to run in addition to the one we talked about today (why do we need to do both?). But first you should do it the way we talked about today.

troyraen commented 1 year ago

completed in #9