billingross / trellis-v2

MIT License
0 stars 0 forks source link

Deploy core functions #2

Closed billingross closed 1 month ago

billingross commented 2 months ago

Process for deploying functions as-is

billingross commented 2 months ago

Deployment of create-blob-node failed because I did not include the config files. Adding the config directory to the root of the repository.

billingross commented 2 months ago

Need to make a bucket to store Trellis configuration data which is named as _TRELLIS_BUCKET is Cloud Build configuration.

billingross commented 2 months ago

Instead of using multiple create-blob-node function instances to handle finalize and update operations I'm going to try using the providers/cloud.storage/eventTypes/object.change trigger event type to capture everything so I can just use one function instance.

billingross commented 2 months ago

Replacing _TRIGGER_OPERATION finalize with _TRIGGER_EVENT providers/cloud.storage/eventTypes/object.change.

billingross commented 2 months ago

Error:

ERROR: (gcloud.beta.functions.deploy) argument --trigger-bucket: At most one of --trigger-bucket | --trigger-http | --trigger-topic | --trigger-event --trigger-resource | --trigger-event-filters --trigger-event-filters-path-pattern --trigger-channel can be specified.

I tried specifying trigger bucket and trigger event and that seems to be disallowed. But when I updated the metadata of the object I created it didn't seem to trigger the function.

From the docs, https://cloud.google.com/sdk/gcloud/reference/functions/deploy#--trigger-event:

Google Cloud Storage bucket name. Trigger the function when an object is created or overwritten in the specified Cloud Storage bucket.

So metadata updates will not trigger a bucket event but it looks like I can use --trigger-event and --trigger-resource to trigger functions based on any update in a bucket. Again from the docs:

Specifies which resource from --trigger-event is being observed. E.g. if --trigger-event is providers/cloud.storage/eventTypes/object.change, --trigger-resource must be a bucket name. For a list of expected resources, call gcloud functions event-types list.

billingross commented 2 months ago

Somehow that still doesn't work even though that exact pattern is described in the docs.

Error:

Step #1: ERROR: (gcloud.beta.functions.deploy) Invalid value for [--trigger-event]: Event type providers/cloud.storage/eventTypes/object.change is not supported by this flag, try using --trigger-event-filters.

Tried changing it to another pattern and it works. It looks like object.change is considered "legacy" so I guess they just don't care whether it works or not: https://github.com/hashicorp/terraform-provider-google/issues/1179.

I guess I'll just continue using different functions to handle different actions. That's probably a better approach since it gives me better resolution to see what is happening and adheres more to the principle of every function doing one thing. In fact, I should probably use separate functions to handle finalizing and updating actions rather than putting all of the logic into a single function and deploying separate instances.