deploy-cloud-functions
deploy-cloud-functions copied to clipboard
Could you improve the documentation of the trigger inputs please? (especially pubsub)
Question
As an example - I am trying to implement the equivalent of gcloud command
gcloud functions deploy my-function \
--runtime go113 \
--trigger-topic=some_topic \
--service-account=$CLOUD_FUNCTION_SA_EMAIL \
--project $PROJECT_ID \
--entry-point MyEntrypoint \
--set-env-vars PROJECT_ID=$PROJECT_ID,REPLAY_TOPIC_ID=$REPLAY_TOPIC_ID,BUCKET_NAME=$BUCKET_NAME \
--region $REGION \
--memory 256 \
--timeout 60 \
--max-instances 100 \
--quiet
Documentation issues:
event_trigger_type: (Optional) Specifies which action should trigger the function. Defaults to creation of http trigger.
OK, so what are the other trigger types? There is not a direct mapping of gcloud flag to action input here so its pure guesswork. What should I use for the equivalent of --trigger-topic=some_topic ?
I crawled around your issues until I found a maybe solution of :
event_trigger_type: google.pubsub.topic.publish
event_trigger_resource: projects/$PROJECT_ID/topics/$PDH_TOPIC_ID
event_trigger_service: pubsub.googleapis.com
This worked it seemed - but as these seem to be legacy flags - I am not sure for how long or if there is a simpler / shorter set of values that could be used
I also am looking for this too^ thank you!
Along this topic - I also figured out how to do it for storage if anyone is wondering:
event_trigger_type: google.storage.object.finalize
event_trigger_resource: projects/PROJECT/buckets/BUCKET
event_trigger_service: storage.googleapis.com
Thanks for the report @erzz @RickRen7575
While the API still requires these in the above format, we can handle that inside the action by detecting event types.
This helps A LOT!!
Along this topic - I also figured out how to do it for storage if anyone is wondering:
event_trigger_type: google.storage.object.finalize event_trigger_resource: projects/PROJECT/buckets/BUCKET event_trigger_service: storage.googleapis.com
Thank you @RickRen7575 this literally saved my life. <3 This definitely needs to be better documented!
I feel this needs a bump after the best part of a year :) Still today I am crawling the web and the source to try and find clues for implementing the various kinds of triggers!
Agreed. Trying to setup a workflow for deploying a function triggered by pub/sub is not well documented.
The previously mentioned solution
event_trigger_type: google.pubsub.topic.publish
event_trigger_resource: projects/$PROJECT_ID/topics/$TOPIC_ID
event_trigger_service: pubsub.googleapis.com
may work but those values are not easy to find
Google are you kidding?
Why is this do badly documented?
Yes, it’s incredible..
To help anyone also getting stuck -
- id: "deploy"
uses: "google-github-actions/deploy-cloud-functions@v0"
with:
# Name of the Cloud Function, same as the entry point name
name: "${FUNCTION_NAME}"
# Runtime to use for the function
runtime: "nodejs16"
region: "asia-southeast1" // optional change of region
event_trigger_type: "google.pubsub.topic.publish"
event_trigger_resource: "projects/${PROJECT_VALUE}/topics/${TOPIC_ID}" // ie the string identifying the topic, not anything else
event_trigger_service: "pubsub.googleapis.com"
Also, if you have deployed an http based trigger with the same function name - delete that first, as a trigger-based function with the same name will not deploy otherwise
@erzz What did you figure out for multiple env vars?
Having tried:
- id: "deploy"
...
secret_environment_variables: [FOO=BAR,APPLE=ORANGE]
secret_environment_variables: FOO=BAR,APPLE=ORANGE
secret_environment_variables: FOO=BAR, APPLE=ORANGE
etc
and either it fails immediately with 'steps not expected' or the build times out..
It works fine with just one entry e.g.
secret_environment_variables: FOO=BAR
The closest I have gotten is following the tests
secret_environment_variables: |-
FOO=BAR
APPLE=ORANGE
which deploys both variables, but the build times out
GitHub Actions inputs can only be strings. This is a limitation of GitHub Actions, not the deploy-cloud-functions action. As such you can pass multiple values in as a comma-separated list or as a newline separated list (using | in yaml).
Without more information, it's difficult to say why the build it timing out. Please open a new issue and include your GitHub Action YAML and log output so we can debug it.
Thanks @sethvargo for confirming.
After moving on with
secret_environment_variables: |-
FOO=BAR
APPLE=ORANGE
the problem was not with the action script (as you noted) but on the GC end with permissions. Resolved by setting the correct Secret Manager Secret Accessor and Secret Manager Viewer appropriately (documenting more for any others reaching this stage)
Hey folks - the triggers for v1 and v2 are documented https://cloud.google.com/functions/docs/calling and subpages (e.g. https://cloud.google.com/functions/docs/calling/storage) now.