我正在尝试使用 Golang 将我的服务器部署到 Google Cloud Platform
我运行 gcloud app deploy cmd/web/app.yaml
并返回失败状态:未知:错误响应:[2]构建失败;查看构建日志以获取详细信息
在日志中打印了这个:
Starting Step #0
Step #0: Pulling image: gcr.io/gcp-runtimes/go1-builder@sha256:[...]
Step #0: sha256:[...]: Pulling from gcp-runtimes/go1-builder
Step #0: Digest: sha256:[...]
Step #0: Status: Downloaded newer image for gcr.io/gcp-runtimes/go1-builder@sha256:[...]
Step #0: main.go:8:2: cannot find package "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql" in any of:
Step #0: /usr/local/go/src/github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql (from $GOROOT)
Step #0: /workspace/_gopath/src/github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql (from $GOPATH)
Step #0: routes.go:5:2: cannot find package "github.com/bmizerany/pat" in any of:
Step #0: /usr/local/go/src/github.com/bmizerany/pat (from $GOROOT)
Step #0: /workspace/_gopath/src/github.com/bmizerany/pat (from $GOPATH)
Step #0: main.go:7:2: cannot find package "github.com/go-sql-driver/mysql" in any of:
Step #0: /usr/local/go/src/github.com/go-sql-driver/mysql (from $GOROOT)
Step #0: /workspace/_gopath/src/github.com/go-sql-driver/mysql (from $GOPATH)
Step #0: middleware.go:6:2: cannot find package "github.com/justinas/nosurf" in any of:
Step #0: /usr/local/go/src/github.com/justinas/nosurf (from $GOROOT)
Step #0: /workspace/_gopath/src/github.com/justinas/nosurf (from $GOPATH)
Step #0: handlers.go:7:2: cannot find package "myProject/pkg/forms" in any of:
Step #0: /usr/local/go/src/myProject/pkg/forms (from $GOROOT)
Step #0: /workspace/_gopath/src/myProject/pkg/forms (from $GOPATH)
Step #0: app.go:4:2: cannot find package "myProject/pkg/models" in any of:
Step #0: /usr/local/go/src/myProject/pkg/models (from $GOROOT)
Step #0: /workspace/_gopath/src/myProject/pkg/models (from $GOPATH)
Finished Step #0
ERROR
我的 gcloud 配置是正确的,因为我连接到 Google SQL 并保存了数据。我在计算引擎中有代码,但我尝试在我的电脑上运行 gcloud app deploy cmd/web/app.yaml
最佳答案
外部包需要在本地才能进行构建。 Go 程序通常由来自许多不同来源的包组成。这些资源中的每一个都来自 GOPATH 或标准库。 ( Source of Explanation )
看看govendor . Govendor 将创建您的 vendor 文件夹并添加您的外部包。
// init govendor
govendor init
# Add existing GOPATH files to vendor.
govendor add +external
关于go - 错误响应 : [2] Build failed using GCP - Golang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49659962/