2017-05-27 425 views
0

我是Google App Engine的新成員。而且,我遇到了一個我無法解決的問題。與引擎庫一起部署App引擎

我有一個非常簡單的應用程序(在轉到developped)是這樣的:

main/ 
| model/ 
| | user.go 
| main.go 
| app.yaml 

這些main.go的進口:

import (
    "github.com/julienschmidt/httprouter" 
    "log" 
    "net/http" 
) 

我的代碼工作得很好,當我運行本地。

但是,當我嘗試發佈它在我的谷歌應用程序引擎實例,我收到此錯誤:

$ gcloud app deploy 

You are about to deploy the following services: 
- <MY_APP_ENGINE_URL> (from [<MY_LOCAL_YAML_PATH>]) 
Deploying to URL: [<MY_APP_ENGINE_URL>] 

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

Beginning deployment of service [default]... 
Some files were skipped. Pass `--verbosity=info` to see which ones. 
You may also view the gcloud log file, found at 
[<LOCAL_APP_ENGINE_LOG>]. 
File upload done. 
Updating service [default]...failed.                                        
ERROR: (gcloud.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed: 
2017/05/27 14:48:24 go-app-builder: build timing: 5×compile (301ms total), 0×link (0s total) 
2017/05/27 14:48:24 go-app-builder: failed running compile: exit status 2 

main.go:4: can't find import: "github.com/julienschmidt/httprouter" 

我做了什麼錯?

編輯: 這是我的app.yaml文件的內容:

runtime: go 
api_version: go1 

handlers: 
- url: /.* 
    script: _go_app 

回答

1

App Engine環境不包含你的依賴,你可以添加一個腳本做去得到......對於每一個,但它太hacky和Go有一個解決方案,我們可以將我們的依賴關係保存在我們項目根目錄下的供應商文件夾中。

快速解決

# Instal godep: 
go get -v -u github.com/tools/godep 

cd your/project/path 
godep save 

現在再次部署,你會看到一個廠商文件夾中的項目,不將其刪除,並把它添加到您的git源,該文件夾包含所有的第三方的依賴就像你httprouter(這是我最喜歡的:))

注意:您可以使用其他工具來保存你的依賴

+0

感謝您的回答。 它創建了我2個文件夾Godeps和供應商(其中包含我的依賴內容);但我仍然收到來自App Engine的相同錯誤: main.go:4:無法找到導入:「github.com/julienschmidt/httprouter」 – Belgikoi

+0

您是否在app.yaml中包含了所有內容? –

+0

嗨,我在編輯:)中添加了我的app.yaml的內容。 閱讀@Ain的回覆,似乎GoDeps無法幫助我。這是真的嗎? – Belgikoi

0

我沒有用過gcloud工具,但在當天goapp是您必須創建github.com/julienschmidt/httprouter(當然有lib的源代碼)的工具,直接在您的main之下,然後部署。 AFIK App Engine的go版本目前爲1.6,這意味着雖然vendoring默認開啓,但它可以關閉 - 也許是這種情況,這就是爲什麼@Yandry Pozo的建議不起作用。