4

I'm trying to structure my GCP gcloud functions (in python) as a separate file per function. It sounds like from the documentation it should be supported but when I try to use --source as a file name instead of a directory it fails. Is there something I'm doing wrong?

Here is the command I use:

gcloud functions deploy createAccount --runtime python38 --trigger-http --source=postgres/createAccount.py --region us-central1

and the error I get back is:

ERROR: (gcloud.functions.deploy) argument --source: Provided path does not point to a directory

But if I put my "createAccount" python function in main.py inside the postgres directory and use this command the function deploys perfectly:

gcloud functions deploy createAccount --runtime python38 --trigger-http --source=postgres --region us-central1

Here it loojs as though it should accept file names in the --source option:

https://cloud.google.com/functions/docs/first-python

See this section:

enter image description here

Any ideas if there is a way to not make main.py one big monolith of all my cloud functions?

1 Answer 1

5

If we look at the documentation of the gcloud command for deploying functions and the --source flag within:

https://cloud.google.com/sdk/gcloud/reference/functions/deploy#--source

We find that it unambiguously says that it wants a directory as a parameter and not a source file. The link you gave which seems to say that we can specify a file looks to be in error. I think that is a mistake and it can only be a directory that is supplied with --source.

This would seem to imply that you can create multiple directories ... where each directory contains just the function you wish to deploy.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, thank you for the information. I was thinking maybe I could do a sort of work around with main.py importing multiple other files (one for each cloud function), but so far that didn't work either. Making a directory for every function I write feels a bit clunky to me since you have N requirements.txt files and N main.py files then.
Do we need the --source flag when deploying the cloud function through Docker? or the --docker-repository flag is enough?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.