Mat*_*att 7 google-app-engine go glide-golang
我正在尝试将一个小型测试应用程序部署到Google App Engine(标准版).如果我包含任何供应商库,我会收到错误.
这是我尝试部署时遇到的错误
% gcloud app deploy
Services to deploy:
descriptor: [/Users/matt/work/appenginetest1/src/hello/default/app.yaml]
source: [/Users/matt/work/appenginetest1/src/hello/default]
target project: REDACTED
target service: [default]
target version: [20170709t220721]
target url: REDACTED
Do you want to continue (Y/n)? y
Beginning deployment of service [default]...
??????????????????????????????????????????????????????????????
?? Uploading 0 files to Google Cloud Storage ??
??????????????????????????????????????????????????????????????
File upload done.
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed:
go-app-builder: build timing: 2×compile (210ms total), 0×link (0s total)
go-app-builder: failed running compile: exit status 2
main.go:6: can't find import: "github.com/julienschmidt/httprouter"
Run Code Online (Sandbox Code Playgroud)
对于某些上下文,这是$ GOPATH的树
% tree $GOPATH
/Users/matt/work/appenginetest1
??? src
??? hello
??? default
? ??? app.yaml
? ??? main.go
??? glide.lock
??? glide.yaml
??? vendor
??? github.com
??? julienschmidt
??? httprouter
??? path.go
??? router.go
??? tree.go
Run Code Online (Sandbox Code Playgroud)
通过dev_appserver.py运行本地服务器工作正常.它看起来不像app引擎在运行后没有找到供应商目录的情况
% rm -rf ~/work/appenginetest1/src/hello/vendor/github.com
Run Code Online (Sandbox Code Playgroud)
它甚至在推送到云之前就出错了
% gcloud app deploy
ERROR: (gcloud.app.deploy) Staging command [/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/goroot-1.6/bin/go-app-stager /Users/matt/work/appenginetest1/src/hello/default/app.yaml /var/folders/nx/8w2_6q551cl50h3ff6lmy9s40000gn/T/tmp97Kiis/tmpe0MHQ0] failed with return code [1].
------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2017/07/09 22:12:52 failed analyzing /Users/matt/work/appenginetest1/src/hello/default: cannot find package "github.com/julienschmidt/httprouter" in any of:
/Users/matt/work/appenginetest1/src/hello/vendor/github.com/julienschmidt/httprouter (vendor tree)
($GOROOT not set)
/Users/matt/work/appenginetest1/src/github.com/julienschmidt/httprouter (from $GOPATH)
GOPATH: /Users/matt/work/appenginetest1
--------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
如果我将github.com目录从供应商移动到src,则部署工作没有问题.
的app.yaml
service: default
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
Run Code Online (Sandbox Code Playgroud)
main.go
package hello
import (
"fmt"
"net/http"
"github.com/julienschmidt/httprouter"
)
func init() {
router := httprouter.New()
router.GET("/hello/:name", Hello)
http.Handle("/", router)
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "Hello, %s!", ps.ByName("name"))
}
Run Code Online (Sandbox Code Playgroud)
如果我在运行滑动安装后将github.com目录从vendor移动到src,我可以部署这个项目.
您可以使用$GOPATH变量来解决这个问题。请注意,您的$GOPATH环境变量实际上可以是多个位置的列表(有关更多信息,请参阅https://golang.org/cmd/go/#hdr-GOPATH_environment_variable ):
GOPATH 环境变量列出了查找 Go 代码的位置。在 Unix 上,该值是一个以冒号分隔的字符串。在 Windows 上,该值是一个以分号分隔的字符串。在计划 9 中,该值是一个列表。
vendor/github.com您可以编写一个脚本,暂时将该目录添加到$GOPATH环境变量中,执行部署,然后将其从环境变量中删除,而不是将 github.com 目录从供应商移动到 src 。
| 归档时间: |
|
| 查看次数: |
536 次 |
| 最近记录: |