functions-framework-go: Cannot deploy to Google Cloud Functions

Deploying a Golang function to Google Cloud Functions errors with a reference this package, so this seems like the best place to report this.

The following command had been running for over a year without fail. This morning we tried it and it failed, and it has continued to fail since then as we attempt deploys in various scenarios to fix or work around the problem.

Deploy Command

gcloud  functions deploy $FUNCTION_ID  \
        --quiet \
        --project $MY_PROJECT \
        --runtime go113 \
        --entry-point=Server \
        --trigger-http \
        --timeout=540s \
        --memory=4096MB

Google Cloud Deploy error

Our functions have just today (2021-09-25) spontaneously started failing to deploy. The error we get is:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: vendored dependencies must include “github.com/GoogleCloudPlatform/functions-framework-go”; if your function does not depend on the module, please add a blank import: _ “github.com/GoogleCloudPlatform/functions-framework-go”; Error ID: fd86168a

The build log is curiously empty:

image

import functions-framework-go

import (
	_ "github.com/GoogleCloudPlatform/functions-framework-go"
)

yields a compile-time error:

package github.com/netpleadings/minutebox/services/json2word imports github.com/GoogleCloudPlatform/functions-framework-go: no Go files in /home/brian_minutebox_com/minutebox/services/docgen2/vendor/github.com/GoogleCloudPlatform/functions-framework-go

Import functions-framework-go/funcframework

import (
	_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
)

yields a deploy error:

Deploying function (may take a while - up to 2 minutes)…⠛
For Cloud Build Logs, visit: https://console.cloud.google.com/cloud-build/builds;region=us-central1/3b5fb4af-132d-4cbf-b551-e299c04aa78a?project={ANON_PROJECTID} Deploying function (may take a while - up to 2 minutes)…failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: can’t load package: package functions.local/app: cannot find module providing package functions.local/app; Error ID: 1a663392

Change to go116

We changed the --runtime from go113 to go116. This had no impact and we still received the error.

Setup

❯ go version
go version go1.16.8 linux/amd64
❯ gcloud version
Google Cloud SDK 352.0.0
alpha 2021.08.06
beta 2021.08.06
bq 2.0.70
core 2021.08.06
gsutil 4.66

I initially tried this with Go 1.15 (that is prepackaged for Debian 11) and upgraded to see if that fixes it (but it did not).

We’re not sure where to go from here and any thoughts, advice, or input would be most welcome. We will cross-report to Google Cloud Support.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Hey @shreejad, thanks for the link. I was able to resolve my issue (on go 1.13) by adding the vendor/ directory to the .gcloudignore file, while leaving go.mod and go.sum out of the .gcloudignore. This was a recommendation from Google Cloud Support.

I believe the blank import we are suggesting in the Cloud Build logs is incorrect. It should be:

import (
	_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
)

This aligns with the code that gets added by the functions-framework buildpack. @brianmhunt please give that a try and let us know if it fixes the issue. Sorry for the confusion.

Thanks for the report. We’re looking into it.

I have run into the same issue as @guntenbein where I must use go mod vendor due to dependencies on private github repos. I can no longer downgrade to 1.22 because I depend on a library that I must use that requires 1.23. So at present I haven’t yet found a way to deploy a needed change to my function.

I had the same problem, solved it by changing

_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"

to

"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"

and adding this in my init() func:

if false {
	funcframework.Start("foo")
}

I have no idea why this works.

The same problem appeared to me again with the version go v1.23.3. After rolling back to 1.22.2 it works normally. This is the message I have when deploy the GCF:

│ Error: Error waiting for Updating function: Error code 3, message: Build failed with status: FAILURE and message: go: ignoring package functions.local/app which exists in the vendor directory but is missing from vendor/modules.txt. To sync the vendor directory run go mod vendor.
│ cannot find module providing package functions.local/app: import lookup disabled by -mod=vendor
│ 	(Go version in go.mod is at least 1.14 and vendor directory exists.). For more details see the logs at 

I have the dependency on other private project and thus use go mod vendor

I have the import _ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework" at my function go file.

The problem appeared when I switched to go v1.23.3 and disappeared when I rolled back to v1.22.2

We can into a similar issue, and discovered that our issues was due to how buildpack was trying to compile our binary. We had to explicitly pass in the build arguments into the gcloud deploy command.

Previously, we were deploying with the following command on version 290.0.1 of gcloud which failed:

gcloud  functions deploy $FUNCTION_ID  \
        --quiet \
        --project $MY_PROJECT \
        --runtime go113 \
        --entry-point=Server \
        --trigger-http \
        --timeout=540s \
        --memory=4096MB

We then upgraded to version 356.0.0 of gcloud, which allowed us to pass in the --set-build-env-vars flag:

gcloud  functions deploy $FUNCTION_ID  \
        --quiet \
        --project $MY_PROJECT \
        --runtime go113 \
        --entry-point=Server \
        --trigger-http \
        --timeout=540s \
        --memory=4096MB \
        --set-build-env-vars GOOGLE_BUILDABLE=./main.go

Thanks for the detailed error report @brianmhunt. Any more messages or details are welcome.

I’ve sent a message to members of the team.

I am investigating if this error may be caused by a Buildpack change for the Go Functions Framework, for example, https://github.com/GoogleCloudPlatform/buildpacks/commit/e3b1fbb25249e3b158500f787c45d75ebeb3e562