gpt4 book ai didi

go - 尝试通过 vendor 目录部署Google Cloud功能时出错

转载 作者:行者123 更新时间:2023-12-01 22:25:36 24 4
gpt4 key购买 nike

我尝试了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

我不得不尝试使用 Vendor ebcause,因为 go.modINVALID_ARGUMENT不断失败,所以在有人围着谷歌搜索后指出了这个 article

注意:
  • 如果我使用go111go.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

  • 对于go113go.mod文件,它根本没有给出有用的错误:
  • ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: Build error details not available

    日志显示:
    INVALID_ARGUMENT
  • 冉部署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可以正常工作。

    最佳答案

    我发现了2种(非常hacky)解决此问题的方法。我的特殊情况是我有一个GCP无法访问的 private 存储库。他们说我需要在此页面底部(今天)创建一个供应商目录:
    https://cloud.google.com/functions/docs/writing/specifying-dependencies-go
    所以我做到了,但是后来我得到了上面报告的错误。
    错误解决方案1:
    将所有内容放在主目录中,然后将每个包重命名为入口点函数的包名称。
    Hacky解决方案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),然后再次进行部署。

    关于go - 尝试通过 vendor 目录部署Google Cloud功能时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60104595/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com