Vicente Gavara
Vicente Gavara

Reputation: 31

gcloud functions deploy with go runtime fails on downloading dependencies from non-public repositories

I'm not able to deploy a Golang-based Google Cloud Function by running gcloud functions deploy.

The reason in that my code imports packages from non-public GitHub repositories, and gcloud is not happy with that:

fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

According to this source, the solution for dealing with gcloud functions deploy getting non-public packages is working with a vendor directory.

Basically, by running the command go mod vendor the vendor directory, containing the program dependencies, is added to the project root, so gcloud function deploy will detect its presence and will get the packages from it instead of trying to download them.

If using the Google Cloud Functions Go 1.22 runtime (argument --runtime=go122 in gcloud functions deploy) then the deployment fails again, this time claiming that the vendor directory is not synced with the go.mod file:

failed to build: extracting module and package names: (error ID: 03a1e2f7):
go: inconsistent vendoring in /workspace/serverless_function_source_code:
    github.com/GoogleCloudPlatform/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
    ...

Saddly that's false, since the vendor/modules.txtcontent is correct and is explicitly requiring that file:

# github.com/GoogleCloudPlatform/functions-framework-go v1.9.1
## explicit; go 1.21

The problem is not just related to github.com/GoogleCloudPlatform/functions-framework-go but to ALL the dependencies in the go.mod file.

Upvotes: 1

Views: 34

Answers (1)

Vicente Gavara
Vicente Gavara

Reputation: 31

The solution for me has been using the go 1.21 runtime instead of the go 1.22 runtime in gcloud functions deploy:

gcloud functions deploy my-gcloud-function \
    --runtime=go121 \
    ...

It seems to me a gcloud bug, but nevertheless I share the problem and my solution, maybe it was helpful for somebody else.

Upvotes: 1

Related Questions