0

我试过了go113go111但没有一个有效:

目录结构如下:


cool_project
   - func.go
   - func_test.go
   utility
     - helper.go
   fancy
     - fancy.go
   go.mod # module cool_project
   go.sum
   .gcloudignore
   vendor
     ...

当我尝试部署gcloud functions deploy ...失败时:找不到包cool_project/utilitycool_project/fancy.

我不得不尝试使用Vendorebcausego.mod一直失败,INVALID_ARGUMENT所以在谷歌搜索周围有人指出这篇文章之后

笔记:

  1. go111如果我只使用文件(没有供应商目录)进行部署,go.mod它会失败并出现神秘错误:
Deploying function (may take a while - up to 2 minutes)...failed.                                       
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: cfb2
go: finding google.golang.org/grpc v1.27.0
go: finding golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5
go: finding github.com/golang/protobuf v1.3.3
go: finding golang.org/x/lint v0.0.0-20200130185559-910be7a94367
go: finding golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7
go: finding golang.org/x/time v0.0.0-20191024005414-555d28b269f0
go: finding google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90
go: finding cloud.google.com/go/bigquery v1.4.0
go: finding golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
go: finding cloud.google.com/go v0.52.0
go: finding golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74
go: finding golang.org/x/mod v0.2.0
go: finding golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7
go: finding github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473
go: finding golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
go: finding golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6
go: finding golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee
go: finding golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
go: finding github.com/google/go-cmp v0.4.0
go: finding golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8
go: finding golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
go: finding google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1
go: finding golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e
go: finding golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
go: finding golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
go: finding golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
go: finding golang.org/x/exp v0.0.0-20191129062945-2f5052295587
go: finding golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
go: finding golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f
go: finding golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
go: finding golang.org/x/sys v0.0.0-20200122134326-e047566fdf82
go: finding github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
go: finding golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a
go: finding golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a
go: finding google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150
go: finding golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
go: finding google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba
go: finding golang.org/x/sys v0.0.0-20200113162924-86b910548bc1
go: finding golang.org/x/tools v0.0.0-20200117161641-43d50277825c
go: finding github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc
go: finding golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e
go: finding github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
go: finding github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1
go: finding github.com/chzyer/logex v1.1.10
go: finding github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6
go: downloading github.com/pkg/errors v0.9.1
go: downloading google.golang.org/api v0.17.0
go: downloading cloud.google.com/go v0.52.0
go: downloading github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
go: downloading gopkg.in/yaml.v2 v2.2.8
go: downloading cloud.google.com/go/storage v1.5.0
go: downloading cloud.google.com/go/pubsub v1.2.0
go: downloading google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90
go: downloading google.golang.org/grpc v1.27.0
go: downloading github.com/golang/protobuf v1.3.3
go: downloading golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
go: downloading go.opencensus.io v0.22.3
go: downloading golang.org/x/net v0.0.0-20200202094626-16171245cfb2
go: downloading github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
go: downloading golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5
go: downloading github.com/googleapis/gax-go/v2 v2.0.5
go: downloading golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
go: downloading github.com/google/go-cmp v0.4.0
# cool_project
files/foo.go:86:69: undefined: "github.com/pkg/errors".Unwrap
files/bar.go:90:70: undefined: "github.com/pkg/errors".Unwrap

  1. 并且使用go113and go.modfile 它给出了根本没有帮助的错误:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: Build error details not available

日志显示:

INVALID_ARGUMENT
  1. 跑部署cmd:
gcloud functions deploy cool_proj113  --trigger-topic test_cool_proj --runtime go113 --entry-point HelloPubSub --source=$PWD/cool_project --verbosity="debug"
DEBUG: (gcloud.functions.deploy) OperationError: code=4, message=Build failed: srv/gopath/src/p/vendor/gcpfun/func.go:21:2: cannot find package "cool_project/fancy" in any of:
        /tmp/staging/srv/gopath/src/p/vendor/vendor/cool_project/fancy (vendor tree)
        /tmp/staging/srv/gopath/src/p/vendor/cool_project/fancy
        /usr/local/go/src/cool_project/fancy (from $GOROOT)
        /tmp/staging/srv/gopath/src/cool_project/fancy (from $GOPATH)
srv/gopath/src/p/vendor/gcpfun/func.go:20:2: cannot find package "cool_project/utility" in any of:
        /tmp/staging/srv/gopath/src/p/vendor/vendor/cool_project/utility (vendor tree)
        /tmp/staging/srv/gopath/src/p/vendor/cool_project/utility
        /usr/local/go/src/cool_project/utility (from $GOROOT)
        /tmp/staging/srv/gopath/src/cool_project/utility (from $GOPATH)
Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 981, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 807, in Run
    resources = command_instance.Run(args)
  File "/usr/lib/google-cloud-sdk/lib/surface/functions/deploy.py", line 309, in Run
    return _Run(args, track=self.ReleaseTrack())
  File "/usr/lib/google-cloud-sdk/lib/surface/functions/deploy.py", line 265, in _Run
    op, do_every_poll=TryToSetInvokerPermission)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/util.py", line 306, in CatchHTTPErrorRaiseHTTPExceptionFn 
    return func(*args, **kwargs)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/util.py", line 353, in WaitForFunctionUpdateOperation
    do_every_poll=do_every_poll)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 137, in Wait
    _WaitForOperation(client, request, notice, do_every_poll)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 111, in _WaitForOperation
    sleep_ms=SLEEP_MS)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 219, in RetryOnResult
    result = func(*args, **kwargs)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 70, in _GetOperationStatus
    raise exceptions.FunctionsError(OperationErrorToString(op.error))

叹!FWIW 我做了测试去单元测试,一切正常go113

4

2 回答 2

0

当您尝试部署时,您在哪个目录中?你在里面cool_project吗?您需要确保您位于包含您的go.mod文件的目录中。

于 2020-10-10T16:49:58.570 回答
0

我找到了两种(非常老套的)方法来解决这个问题。我的特殊情况是我有一个 GCP 无法访问的私有存储库。他们说我需要在此页面底部(今天)创建一个供应商目录:

https://cloud.google.com/functions/docs/writing/specifying-dependencies-go

所以我做了,但后来我得到了你上面报告的错误。

糟糕的解决方案1:

将所有内容放在主目录中,并将每个包重命名为入口点函数的包名。

哈奇解决方案2:

这实际上是在错误的第一行之后:

DEBUG: (gcloud.functions.deploy) OperationError: code=4, message=Build failed: srv/gopath/src/p/vendor/gcpfun/func.go:21:2: cannot find package "cool_project/fancy" in any of:
    /tmp/staging/srv/gopath/src/p/vendor/vendor/cool_project/fancy (vendor tree)

在这种情况下,请执行以下操作:

go mod vendor

然后在供应商目录中创建一个名为 go mod 包名称的文件夹,在您的情况下为'cool_project'. 然后将 subdir 文件夹复制并粘贴到该目录中(例如:)vendor/cool_project/fancy/*.go,然后再次部署它。

于 2020-08-15T20:27:52.317 回答