在App Engine Standard上进行销售

I know this topic has been referenced a few times already. Unfortunately I still wasn't able to find a working solution for my use case.

I can't seem to get vendoring working for my Go application on App Engine Standard. I'm using dep for vendoring.

I'm building a GraphQL API and here is my folder structure:

/GOPATH
└──/src
   └──/acme
      ├──/app
      |   ├── app.yaml
      |   └── app.go
      ├──/src
      |   ├── /mutations/
      |   ├── /queries/
      |   └── /types/
      └──/vendor/

Running goapp serve app/app.yaml on Cloud Shell fails with

INFO     2018-05-14 15:42:08,386 devappserver2.py:764] Skipping SDK update check.
INFO     2018-05-14 15:42:08,471 api_server.py:268] Starting API server at: http://0.0.0.0:47213
INFO     2018-05-14 15:42:08,600 dispatcher.py:199] Starting module "default" running at: http://0.0.0.0:8080
INFO     2018-05-14 15:42:08,601 admin_server.py:116] Starting admin server at: http://0.0.0.0:8000
ERROR    2018-05-14 15:42:13,983 go_runtime.py:181] Failed to build Go application: (Executed command: /google/go_appengine/goroot/bin/go-app-builder -app_base /home/xxx/gopath/src/acme/app -arch 6 -dynamic -goroot /google/go_appengine/goroot -gopath /home/xxx/gopath:/google/gopath -nobuild_files ^^$ -incremental_rebuild -unsafe -binary_name _go_app -extra_imports appengine_internal/init -work_dir /tmp/tmpbt8DA2appengine-go-bin -gcflags -I,/google/go_appengine/goroot/pkg/linux_amd64_appengine -ldflags -L,/google/go_appengine/goroot/pkg/linux_amd64_appengine app.go)
/home/xxx/gopath/src/acme/vendor/github.com/graphql-go/graphql/definition.go:4: can't find import: "context"

2018/05/14 15:42:09 Can't find package "context" in $GOPATH: cannot find package "context" in any of:
        /home/xxx/gopath/src/acme/vendor/context (vendor tree)
        /google/go_appengine/goroot/src/context (from $GOROOT)
        /home/xxx/gopath/src/context (from $GOPATH)
        /google/gopath/src/context

Looks like the problem might be that one vendor is not using a full dependency name for "context". (EDIT: probably not the case though since I’m using 1.8)

Has anyone ever managed to successfully deploy on App Engine Standard using vendoring? Been pulling my hair all day on this.

The context package will be inside $GOROOT ( not in vendor directory ). Probably your Go Appengine SDK is old and does not support Go 1.8.

Update your SDK to the latest version. The $GOROOT should be like /path/to/somewhere/goroot-1.8

Just in case anyone else struggles with this, this is the approach I've taken that seems to work for me.

Directory structure looks like this:

/GOPATH
├──/appengine
|  ├──/.git/
|  ├──/project1
|  |  ├── app.yaml
|  |  └── app.go
|  └──/project2
|     ├── app.yaml
|     └── app.go
└──/src
   ├──/project1
   |  ├──/.git/
   |  ├──/mutations/
   |  ├──/queries/
   |  ├──/types/
   |  ├──/vendor/
   |  └──/main.go
   └──/project2
      ├──/.git/
      ├──/foo/
      ├──/bar/
      ├──/vendor/
      └──/main.go

Each app.go file below the appengine folder contains:

package projectX

import "projectX"

func init() {
    projectX.Run()
}

Each main.go file below src/projectX contains:

package projectX

import (
    // Import whatever you need
    "google.golang.org/appengine"
)

func Run() {
    // Do whatever you need
    appengine.Main()
}

Seems that having the folder that contains app.yaml outside of $GOPATH/src is indeed necessary.

This is also not ideal for version control if you need to have each project versioned under their own git repo as opposed to having one monolyth repo. I solved this by versioning each project AND versioning the appengine folder as well separately.

I was having issues with, spent ages looking around trying to figure out why it wasn't working. This answer is a little late but hopefully will be useful for anyone else who has this issue.

I updated to use Go 1.11 which I thought wasn't supported (found one of the GCP examples on github using it here)

Set runtime: go111 in app.yaml and it will support vendoring and give you a link to a proper build log.

Now my directory structure is as follows.

/GOPATH └──/src ├──/project1 | ├──/.git/ | ├──/whateverCode/ | ├──/vendor/ | └──/main.go | └──/app.yaml

I assume if it supports Go 1.11 we could also use Modules for versioning but I haven't looked into that yet.