Deploying a Google Cloud Function from a Source Repo using a custom repo folder path for the source code

283 views Asked by At

What I want

I have my Source Repo set up (it mirrors a GitHub repo whose main branch is called main). I'm trying to deploy a Python function, so I'm using a folder in the repo that contains a main.py and a requirements.txt file, as required here.

I followed instructions here to build my gcloud deployment invocation.

In particular I'm interested in NOT using the root of the repo as the source directory. Here is an example command with actual values changed:

gcloud --project=my-project functions deploy my-function \
--gen2 \
--region=my-region \
--runtime=python311 \
--source=https://source.developers.google.com/projects/my-project/repos/my-repo/moveable-aliases/main/paths/my/source/directory/path/in/the/repo \
--entry-point=my_cloud_event_function_name \
--trigger-bucket=my-bucket

I expect this to work, given the following piece of documentation:

To deploy from a revision other than master, append one of the following to the above path:

/revisions/REVISION_NAME
/moveable-aliases/MOVEABLE_ALIAS
/fixed-aliases/FIXED_ALIAS

To deploy source code from a directory other than the repository root, specify a revision, moveable alias, or fixed alias as above and append /paths/PATH_TO_YOUR_SOURCE_DIRECTORY to the path.

source

HOWEVER this is what I get:

ERROR: (gcloud.functions.deploy) Invalid Cloud Source Repository URL provided. 
Must match the following format: https://source.developers.google.com/projects/<projectId>/repos/<repoName>. 
Specify the desired branch by appending /moveable-aliases/<branchName>, the desired tag with /fixed-aliases/<tagName>, or the desired commit with /revisions/<commit>.

So no mention of the path in the repo to use something else than the root of the repo.

Am I missing anything here?

gcloud CLI version, in case that's relevant

gcloud --version

Google Cloud SDK 413.0.0
alpha 2023.01.06
beta 2023.01.06
bq 2.0.84
bundled-python3-unix 3.9.12
core 2023.01.06
gcloud-crc32c 1.0.0
gke-gcloud-auth-plugin 0.4.0
gsutil 5.17
1

There are 1 answers

0
Chanpols On

Posting this as a community wiki so that others can benefit from it.


As mentioned by @HugoMailhot

It turns out that from the GCP Console UI I can edit a Cloud Function deployment and select a folder path within the source repo. I'm not sure why this won't work from the CLI tool, and configuring things by clicking around in a UI isn't the most reproducible way to set things up so I might end up using something else.


Reference: