Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy google cloud function when main.py and requirements.txt aren't in the same directory

I have a directory structure that looks like this:

src/
    main.py
requirements.txt

Since there doesn't seem to be any configurability surrounding where to look for requirements.txt, I have been resigned to running gcloud functions deploy in the outer directory, and I was hoping that the --entry-point flag might give me some wiggle room to target main.py inside src. Unfortunately, it seems to only define a method name.

So is there any way to make this work aside from forcing main.py and requirements.txt to be in the same directory?

For reference, the command I'm trying to run and corresponding error message:

gcloud functions deploy refresh_classes --entry-point main --runtime python37 --trigger-resource send_refresh --trigger-event google.pubsub.topic.publish --timeout 540s

Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: File main.py that is expected to define function doesn't exist
like image 932
notacorn Avatar asked Sep 17 '25 02:09

notacorn


1 Answers

It's not possible by configuring gcloud alone, or without additional source files. Cloud Functions expects a single source directory which contains both a requirements.txt and main.py.

like image 58
Dustin Ingram Avatar answered Sep 19 '25 16:09

Dustin Ingram