在gcp cloudbuild中使用`replace`指令失败

I'm trying to build my go application using serverless framework in cloudbuild.

Here's my project structure

/api
   /giam
      go.mod
      API.go
   /other_folders...
/util
   go.mod
   util.go

Here's my build steps:

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'softinstigate/serverless'
  args: ['deploy', '-v']
  dir: 'api/giam'
  env: ['PROJECT_ROOT=${REPO_NAME}', 'GO111MODULE=on']

and here's my go.mod in api/giam

module mybackend

require bitbucket.org/myusername/mybackend/util v0.0.0

replace bitbucket.org/myusername/mybackend/util => /workspace/util

and I confirmed that I have a go.mod in my util folder.

and here's the content

module util

require cloud.google.com/go v0.37.1

The error

I got this error while running the cloudbuild..

{"ResourceType":"cloudfunctions.v1beta2.function","ResourceErrorCode":"400","ResourceErrorMessage":"Build failed: go: parsing util/go.mod: open /workspace/util/go.mod: no such file or directory
go: error loading module requirements
"}

if I got this right, the error is that it cannot find the /workspace/util/go.mod

I tried ls in the cloudbuild, specifically in /workspace/util and I found the go.mod file.

I'm pretty stuck here.. I don't know what to do next..

I managed to get it working by using vendor and omitting go.mod and go.sum in serverless package (by using package.exclude).

Here's my updated cloudbuild.yaml:

steps:
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
- name: 'gcr.io/cloud-builders/go'
  dir: 'api/giam'
  args: ['mod', 'edit', '-replace', 'bitbucket.org/myusername/mybackend/util=/workspace/util']
  env: ['GOPATH=/src', 'GO111MODULE=on']
- name: 'gcr.io/cloud-builders/go'
  dir: 'api/giam'
  args: ['mod', 'vendor']
  env: ['GOPATH=/src', 'GO111MODULE=on']
- name: 'softinstigate/serverless'
  args: ['deploy', '-v']
  dir: 'api/giam'
  env: ['GOPATH=/src', 'GO111MODULE=on']

and my go.mod:

module mybackend

require (
    bitbucket.org/myusername/mybackend/util v0.0.0
    google.golang.org/api v0.2.1-0.20190318183801-2dc3ad4d67ba
)

replace bitbucket.org/myusername/mybackend/util => ../../util

as per github issue in https://github.com/GoogleCloudPlatform/golang-samples/issues/743, it says that you need to exclude go.mod and go.sum in the deployment, otherwise the vendor won't be used. That's why in serverless.yml I use:

package:
  exclude:
    - ./**
  include:
    - vendor/**
    - '*.go'