deploying functions using golang and a vendor directory

812 views
Skip to first unread message

Justin Randall

unread,
Jun 27, 2019, 9:09:53 AM6/27/19
to Google Cloud Developers
Hello!

I have been searching high and low for an answer, but so far have not had much luck. I could not find a google cloud functions group, so I am posting here in general dev. If there is a better place to ask, please let me know.

I have a project I am migrating from AppEngine to Google Cloud Functions. Since I have some private repositories as dependencies, I must vendor instead of using go.mod.

The project builds fine in a dev environment. It is a fairly simple setup. From the project root, I have my .go source files. There is a cmd/ subfolder I use for my local main.go to test and debug. There is a vendor folder with all of the required dependencies. There is no go.mod or go.sum file. My .gcloudignore file excludes go.mod (per instructions on specifying dependencies https://cloud.google.com/functions/docs/writing/specifying-dependencies-go#using_a_vendor_directory).

However, when I attempt to deploy using gcloud functions deploy ReturnLicense --region=asia-east2 --runtime go111 --trigger-http --project "MYPROJECT"
it fails like so:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: /tmp/sgb/gopath/src/serverlessapp/vendor/MYSOURCE.go:10:2: cannot find package "github.com/MYUSER/MYDEP" in any of:
        /tmp/sgb/gopath/src/serverlessapp/vendor/github.com/MYUSER/MYDEP(vendor tree)
        /go/src/github.com/MYUSER/MYDEP (from $GOROOT)
        /tmp/sgb/gopath/src/github.com/MYUSER/MYDEP (from $GOPATH)

$ go env GOROOT
/usr/lib/go-1.11

$ go env GOPATH
/home/User/go

Since I am in a container, I even went so far as to symlink $GOPATH to /go, just to try to force the issue (I tear down the container and rebuild a couple times a day). Is this happening in the remote environment instead of locally? Why aren't any of my vendored sources included/found when I deploy?

Any help is greatly appreciated!

Justin Randall

unread,
Jun 27, 2019, 1:23:03 PM6/27/19
to Google Cloud Developers
OK, so this is something that turns up with the "cut-and-paste" configuration in the documentation for .gcloudignore (https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore). It includes .gitignore, and if you rely on tools like "dep" to satisfy dependencies building the vendor directory and not clutter your source control with "./vendor", then "./vendor" will be ignored and not deploy your dependencies. I zapped the line suggested in the documentation for .gcloudignore and all was well. 

If there are any maintainers here for that documentation, it would be helpful to add a warning about this around the "EXAMPLES" section so anyone searching with this problem can solve it in just a few minutes.

It would also be great if the error output let people know if it was the remote that could not find it vs. the local system. Would also be helpful if the exclusions with verbosity set to debug traced better (as in, "ignoring <such-and-such> because .gcloudignore, via the included .gitignore. The error output was not as helpful as it should have been. "Can't find package" is really ambiguous. Can't find it on the remote as the code is deployed? Can't find it locally? Maybe a URL to the answer to fix the problem in the error output would be helpful as well.

Sorry for the noise here. Solved it.

I hope this turns up in a search so others hit by this particular self-inflicted configuration bug can solve it quickly.

Nicolas (Google Cloud Platform Support)

unread,
Jun 28, 2019, 4:40:29 PM6/28/19
to Google Cloud Developers

Hi Justin

 

Thanks for sharing this,I’m glad you were able to resolve your issue and I’m sure it will other developer in the future.

 

I relayed the documentation improvement suggested to the rightful team, thanks again!


Reply all
Reply to author
Forward
0 new messages