Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to deploy Google cloud function in Go 1.11 using go modules #743

Closed
sharkyze opened this issue Jan 29, 2019 · 2 comments

Comments

@sharkyze
Copy link

@sharkyze sharkyze commented Jan 29, 2019

I originally posted this on stackoverflow: https://stackoverflow.com/questions/54410963/error-when-trying-to-deploy-google-cloud-function-in-go-1-11-using-go-modules

I am having issues deploying a Google cloud function in Go 1.11 using Go modules. I have the following code structure in my GOPATH:

github.com/example/
├── models
│   ├── go.mod
│   └── models.go
└── load
    ├── fn.go
    ├── go.mod
    ├── go.sum
    └── vendor
        ├── cloud.google.com
        │   └── ...
        ├── github.com
        │   ├── golang
        │   │   └── ...
        ├── github.com
        │   └── example
        │       └── models
        │           ├── go.mod
        │           └── models.go
        └── ...

the load/go.mod looks like the following:

module github.com/example/load

require (
	github.com/example/models v0.0.0
)

replace github.com/example/models => ../models

When I try to deploy the function using the command

gcloud functions deploy load-data --entry-point GCSNewFileTrigger --runtime go111 --trigger-resource new_data --trigger-event google.storage.object.finalize

I get the following error:

Deploying function (may take a while - up to 2 minutes)...failed.                                                                                                                                                                     
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: go: parsing /models/go.mod: open /models/go.mod: no such file or directory
go: error loading module requirements

The commands go mod vendor and go mod verify run successfully locally and I can see my local package models in the vendor folder of load

@tbpg

This comment has been minimized.

Copy link
Contributor

@tbpg tbpg commented Jan 29, 2019

Thank you for filing this issue!

Modules are preferred by the builder over vendor. If there is a go.mod, modules will be used. When you upload your function, it only includes the directory with your function at the root, not any directories one level up. So, when there is a go.mod and you have a replace directive pointing one level up, it will not work.

The solution is to vendor and not upload the go.mod/go.sum files. When using gcloud, you can create a .gcloudignore file to do this for you. See https://cloud.google.com/functions/docs/concepts/go-runtime#specifying_dependencies for more detail.

I'm going to close this issue as this repo is for hosting sample code, and is only watched by engineers working on those samples. Thank you for bringing this up!

@tbpg tbpg closed this Jan 29, 2019
@sharkyze

This comment has been minimized.

Copy link
Author

@sharkyze sharkyze commented Jan 30, 2019

Thank you so much for your answer. This fixed my problem 😀. Sorry for posting this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.