【问题标题】:errors parsing go.mod How to deploy go app on App Engine with Cloud build?解析 go.mod 时出错如何使用 Cloud build 在 App Engine 上部署 go 应用程序?
【发布时间】:2019-10-15 19:54:22
【问题描述】:

所以我有一个在本地主机上运行良好的 Go 应用程序,但我想在谷歌云上托管,并且云已经设置好了。整个目录树看起来像这样。

gocode
---bin
---pkg
---src
  ---cloud.google.com
  ---github.com
  ...
  ---appname
    ---auth
    ---database
    ...
    ---main.go
    ---app.yaml
    ---cloudbuild.yaml
    ---go.mod

这里是 app.yaml

runtime: go112
api_version: go1

handlers:
- url: /.*
  script: _go_app

这里是 cloudbuild.yaml

steps:

- name: 'golang'
  args: ['go', 'build', '.']
  env: ['GO111MODULE=on']

- name: 'gcr.io/cloud-builders/go'
  args: ['get', '-d', 'appname']
  env: ['GOPATH=/gopath/','MODE=dev']
  volumes:
  - name: 'go'
    path: '/gopath'

- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy']
  env: ['GOPATH=/gopath/','MODE=dev']
  volumes:
  - name: 'go'
    path: '/gopath'

这里是 go.mod

module github.com/Raj-Varun/appname-API/

require github.com/spf13/viper

当我运行 gcloud builds submit --config cloudbuild.yaml . 时,我收到了这个错误

tarting Step #0
Step #0: Pulling image: golang
Step #0: Using default tag: latest
Step #0: latest: Pulling from library/golang
Step #0: Digest: sha256:a50a9364e9170ab5f5b03389ed33b9271b4a7b6bbb0ab41c4035adb3078927bc
Step #0: Status: Downloaded newer image for golang:latest
Step #0: docker.io/library/golang:latest
Step #0: go: errors parsing go.mod:
Step #0: /workspace/go.mod:3: usage: require module/path v1.2.3
Finished Step #0
ERROR
ERROR: build step 0 "golang" failed: exit status 1

【问题讨论】:

  • 你的go.mod文件是什么?
  • 我搞砸了!我知道!当我尝试构建应用程序时,你能告诉我这件事吗?我从 main.go cannot load appname/auth: cannot find module providing package appname/auth 收到此错误

标签: google-app-engine go google-cloud-build


【解决方案1】:

如错误信息中所解释,require 包路径必须有这种格式require module/path v1.2.3

在你的 go.mod 中,你有这个:

require github.com/spf13/viper

你有module/path,但你没有版本!

Go the the viper github project and take the release version that you want。例如

require github.com/spf13/viper v1.4.0

您也可以尝试执行go mod tidy 来自动构建和清理您的go.mod 文件

【讨论】:

  • 作为最后一步,您还可以运行go mod verify 来检查所有依赖项是否安装正确。
猜你喜欢
  • 2019-02-06
  • 2020-03-27
  • 2020-02-12
  • 2017-11-27
  • 1970-01-01
  • 2019-12-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多