Golang云SDK – gcloud app deploy找不到导入的包。

huangapple go评论87阅读模式
英文:

Golang Cloud SDK - gcloud app deploy cannot find import package

问题

根据Google App Engine标准环境(Go API)的官方文档,现在部署项目的首选工具是Cloud SDK,所以我们从goapp迁移到了gcloud。

我们无法将Go项目部署到GAE,因为在“部署时间”找不到给定项目的所有子包。
我们一直使用的典型文件夹结构如下:

-project-name
--app.yaml
--main.go
--assets
---package1
---package2

当全局库放在系统的GOPATH中时,一切都正常运行。

现在运行gcloud app deploy,我们得到以下结果:

You are about to deploy the following services:
 - yourproject/default/123456789 (from [/Path/to/app.yaml])
     Deploying to URL: [https://yourproject.appspot.com]

Do you want to continue (Y/n)?  Y

Beginning deployment of service [default]...
ERROR: (gcloud.app.deploy) Staging command [/path/to/yourproject/app.yaml /var/folders/b6/5ydn0wdn64jd32sxzzz48b7c0000gn/T/tmpbd4oiG] failed with return code [1].

------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2017/03/24 10:25:58 failed analyzing /path/to/yourproject: cannot find package "yourpackage" in any of:
        ($GOROOT not set)
        /path/to/gopath/src/yourpackage (from $GOPATH)
GOPATH: /path/to/gopath
--------------------------------------------------------------------------------

dev_appserver.py在保持相同文件夹结构的情况下可以正常工作。

我们有什么遗漏吗?
如何使用gcloud部署到Google App Engine标准环境?

如果需要更改项目结构:如何更改?是否有官方文档介绍?

提前致谢,

编辑-- 更多信息:

Luigi-Mac-Pro:path/to/yourproject distudio$ gcloud version
Google Cloud SDK 148.0.0
app-engine-go 
app-engine-go-darwin-x86_64 1.9.50
app-engine-python 1.9.50
bq 2.0.24
bq-nix 2.0.24
core 2017.03.17
core-nix 2016.11.07
gcloud 
gcloud-deps 2017.03.17
gcloud-deps-darwin-x86_64 2017.02.21
gsutil 4.23
gsutil-nix 4.22
英文:

according to the official documentation for Google App Engine Standard environment (Go API) the "preferred tooling to deploy a project" is now the Cloud SDK and so we moved to gcloud from goapp.

We are unable to deploy Go projects to GAE because all the sub-packages of every given project can't be found at "deploy time".
The typical folder structure that we have been using for every GAE project was as follows:

-project-name
--app.yaml
--main.go
--assets
---package1
---package2

When global libraries were put in the system GOPATH everything worked smoothly.

Running gcloud app deploy we now get this:

You are about to deploy the following services:
 - yourproject/default/123456789 (from [/Path/to/app.yaml])
     Deploying to URL: [https://yourproject.appspot.com]

Do you want to continue (Y/n)?  Y

Beginning deployment of service [default]...
ERROR: (gcloud.app.deploy) Staging command [/path/to/yourproject/app.yaml /var/folders/b6/5ydn0wdn64jd32sxzzz48b7c0000gn/T/tmpbd4oiG] failed with return code [1].

------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2017/03/24 10:25:58 failed analyzing /path/to/yourproject: cannot find package "yourpackage" in any of:
        ($GOROOT not set)
        /path/to/gopath/src/yourpackage (from $GOPATH)
GOPATH: /path/to/gopath
--------------------------------------------------------------------------------

while dev_appserver.py works perfectly keeping the same folder structure.

Did we miss something?
How can we deploy to Google App Engine Standard environment using gcloud?

If the project structure needs to be changed: how? Is there official documentation about it?

Thanks in advance,

Edit -- Further infos:

Luigi-Mac-Pro:path/to/yourproject distudio$ gcloud version
Google Cloud SDK 148.0.0
app-engine-go 
app-engine-go-darwin-x86_64 1.9.50
app-engine-python 1.9.50
bq 2.0.24
bq-nix 2.0.24
core 2017.03.17
core-nix 2016.11.07
gcloud 
gcloud-deps 2017.03.17
gcloud-deps-darwin-x86_64 2017.02.21
gsutil 4.23
gsutil-nix 4.22

答案1

得分: 5

谷歌建议将依赖项放在应用程序目录之外,并使用GOPATH来引用它们。在你的情况下,这意味着要做以下操作:

-project-name
--app.yaml
--main.go

其中main.go包含:

import (
    "package1"
    "package2"
)

然后在其他地方:

-my_packages
--src
---package1
---package2

然后,在运行dev_appservergcloud app deploy之前,将GOPATH环境变量设置为path/to/my_packages

未来的解决方案

我们正在解决如何在应用程序目录中正确地管理软件包的长期解决方案,可能会使用Go的未来原生软件包管理器。很抱歉,我们目前没有很好的方法来支持gcloud app deploy的子软件包。这是与App Engine灵活环境兼容性的不幸副作用。

英文:

Google recommends keeping your dependencies outside of the app directory, and using GOPATH to refer them. In your case, that would mean doing the following:

-project-name
--app.yaml
--main.go

where main.go contains

import (
    "package1"
    "package2"
)

And somewhere else:

-my_packages
--src
---package1
---package2

And then set GOPATH environment variable to path/to/my_packages prior to running dev_appserver and gcloud app deploy.

For the future

We are working out the long term solution for properly vendoring packages inside your app directory – likely using Go's future native package manager. I'm sorry to say that we don't have a good way of supporting sub-packages for gcloud app deploy. This was an unfortunate side effect of compatibility with the App Engine Flexible environment.

huangapple
  • 本文由 发表于 2017年3月24日 17:59:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/42996414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定