deploy-cloud-functions icon indicating copy to clipboard operation
deploy-cloud-functions copied to clipboard

Could you improve the documentation of the trigger inputs please? (especially pubsub)

Open erzz opened this issue 4 years ago • 13 comments

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

erzz avatar May 07 '21 09:05 erzz

I also am looking for this too^ thank you!

RickRen7575 avatar May 07 '21 15:05 RickRen7575

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

RickRen7575 avatar May 10 '21 12:05 RickRen7575

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.

bharathkkb avatar May 26 '21 04:05 bharathkkb

This helps A LOT!!

PeaceS avatar Jul 19 '21 23:07 PeaceS

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!

ankile avatar Sep 27 '21 18:09 ankile

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!

erzz avatar Feb 06 '22 15:02 erzz

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

JaredEzz avatar Feb 10 '22 16:02 JaredEzz

Google are you kidding?

Why is this do badly documented?

gregorvand avatar Aug 09 '22 16:08 gregorvand

Yes, it’s incredible..

ankile avatar Aug 09 '22 16:08 ankile

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

gregorvand avatar Aug 09 '22 17:08 gregorvand

@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

gregorvand avatar Aug 10 '22 14:08 gregorvand

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.

sethvargo avatar Aug 10 '22 14:08 sethvargo

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)

gregorvand avatar Aug 11 '22 10:08 gregorvand

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.

sethvargo avatar Dec 17 '22 23:12 sethvargo