Search code examples
gogoogle-cloud-functionsgo-modules

How can I use a local repository in the vendor in Google Cloud Functions with Go


I'm trying to deploy a Google Cloud Function written in Go.

By doing some research I found out that vendor files are prefered over go.mod so I'm vendoring everything I use (which includes some local dependencies) and ignoring the go.mod/sum files in the .gcloudignore file.

The problem is that after trying to deploy, I get the following error:

go: [email protected]: parsing /nimbus/go.mod: open /nimbus/go.mod: no such file or directory; Error ID: 03a1e2f7

nimbus is my local dependency and it has the following structure:

local repository structure

My Function repository has the following structrure:

enter image description here

and my go.mod file is:

module my_function

go 1.13

require nimbus v0.0.0-00010101000000-000000000000

replace nimbus => ../../../nimbus

I've tried this solution https://stackoverflow.com/questions/5441096 already. But it did not fix my issue.

I've tried everything to solve this issue, but nothing seems to work.


Solution

  • Turns out the problem was very complicated and I hope Google finds a solution for it asp.

    By deploying my function using Cloud Build, It would read from my repository on Google Source, but, by reading from there it would bypass the .gcloudignore file and deploy both the go.mod/sum files and the vendor directory with my local code.

    As said in https://stackoverflow.com/a/62050872/10316247:

    If you have a go.mod file and a vendor directory, the vendor directory will be ignored when you deploy your function.

    So the error would occur because of my go.mod not being able to find local repository.

    My solution was to rename my go.mod/sum files so it would not be considered:

    enter image description here