├── .gitignore ├── .gitmodules ├── README.md ├── backend ├── app.yaml ├── favicon.ico ├── server.go └── server_test.go ├── circle.yml ├── package.json ├── service_account.json.enc └── tools └── set_appcfg_token.sh /.gitignore: -------------------------------------------------------------------------------- 1 | service_account.json 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/github.com/labstack/echo"] 2 | path = vendor/github.com/labstack/echo 3 | url = https://github.com/labstack/echo 4 | [submodule "vendor/github.com/labstack/gommon"] 5 | path = vendor/github.com/labstack/gommon 6 | url = https://github.com/labstack/gommon 7 | [submodule "vendor/github.com/mattn/go-colorable"] 8 | path = vendor/github.com/mattn/go-colorable 9 | url = https://github.com/mattn/go-colorable 10 | [submodule "vendor/github.com/mattn/go-isatty"] 11 | path = vendor/github.com/mattn/go-isatty 12 | url = https://github.com/mattn/go-isatty 13 | [submodule "vendor/github.com/valyala/fasttemplate"] 14 | path = vendor/github.com/valyala/fasttemplate 15 | url = https://github.com/valyala/fasttemplate 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AppEngine Vendor Example 2 | -------------------------------------------------------------------------------- /backend/app.yaml: -------------------------------------------------------------------------------- 1 | application: vendor-example 2 | version: 1 3 | runtime: go 4 | api_version: go1 5 | 6 | handlers: 7 | - url: /favicon\.ico 8 | static_files: favicon.ico 9 | upload: favicon\.ico 10 | 11 | - url: /.* 12 | script: _go_app 13 | -------------------------------------------------------------------------------- /backend/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k2wanko/appengine-vendor-example/09893465aa57cb695bdad01f617a5992ea03ec0c/backend/favicon.ico -------------------------------------------------------------------------------- /backend/server.go: -------------------------------------------------------------------------------- 1 | package backend 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "github.com/labstack/echo" 8 | "github.com/labstack/echo/engine/standard" 9 | 10 | "google.golang.org/appengine" 11 | ) 12 | 13 | func init() { 14 | e := echo.New() 15 | 16 | e.Use(AppContext) 17 | e.GET("/", handle) 18 | 19 | s := standard.New("") 20 | s.SetHandler(e) 21 | http.Handle("/", s) 22 | } 23 | 24 | func handle(c echo.Context) error { 25 | appID := appengine.AppID(c.StdContext()) 26 | html := fmt.Sprintf("
%s", appID) 27 | return c.HTML(200, html) 28 | } 29 | 30 | func AppContext(next echo.HandlerFunc) echo.HandlerFunc { 31 | return func(c echo.Context) error { 32 | c.SetStdContext(appengine.WithContext(c.StdContext(), c.Request().(*standard.Request).Request)) 33 | return next(c) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /backend/server_test.go: -------------------------------------------------------------------------------- 1 | package backend 2 | 3 | import ( 4 | "testing" 5 | 6 | "google.golang.org/appengine/aetest" 7 | 8 | "github.com/labstack/echo" 9 | "github.com/labstack/echo/test" 10 | ) 11 | 12 | func TestHandle(t *testing.T) { 13 | t.Parallel() 14 | e := echo.New() 15 | req := test.NewRequest(echo.GET, "/", nil) 16 | rec := test.NewResponseRecorder() 17 | c := e.NewContext(req, rec) 18 | 19 | err := appTestContext(handle)(c) 20 | 21 | if err != nil { 22 | t.Fatal(err) 23 | } 24 | 25 | if s := rec.Status(); s != 200 { 26 | t.Errorf("Status not ok: status = %d", s) 27 | } 28 | } 29 | 30 | func appTestContext(next echo.HandlerFunc) echo.HandlerFunc { 31 | return func(c echo.Context) error { 32 | ctx, close, err := aetest.NewContext() 33 | if err != nil { 34 | return err 35 | } 36 | defer close() 37 | c.SetStdContext(ctx) 38 | return next(c) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | environment: 3 | PATH: "${PATH}:$HOME/.yarn/bin:/opt/google-cloud-sdk/platform/google_appengine" 4 | GOPATH: "${HOME}/.go_workspace" 5 | PROJECT_PACKAGE: "${CIRCLE_REPOSITORY_URL:8:${#CIRCLE_REPOSITORY_URL}}" 6 | WORK_DIR: "${GOPATH}/src/${PROJECT_PACKAGE}" 7 | post: 8 | # Install yarn 9 | - > 10 | test -e $HOME/.yarn/bin/yarn || curl -o- -L https://yarnpkg.com/install.sh | bash; 11 | yarn self-update 12 | # Update gcloud 13 | - > 14 | test -e ~/.google-cloud-sdk || sudo mv /opt/google-cloud-sdk ~/.google-cloud-sdk; 15 | sudo rm -rf /opt/google-cloud-sdk && 16 | sudo ln -fs ~/.google-cloud-sdk /opt/google-cloud-sdk && 17 | sudo /opt/google-cloud-sdk/bin/gcloud components update -q && 18 | sudo /opt/google-cloud-sdk/bin/gcloud components install app-engine-go -q && 19 | sudo chmod +x /opt/google-cloud-sdk/platform/google_appengine/goapp && 20 | sudo chown $USER:$USER -R ~/.config/gcloud 21 | # Put PROJECT_PACKAGE to GOPATH 22 | - > 23 | mkdir -p $(dirname ${WORK_DIR}) && 24 | rsync -azC --delete --include '.git/' ~/${CIRCLE_PROJECT_REPONAME} $(dirname ${WORK_DIR}) 25 | 26 | general: 27 | build_dir: "../.go_workspace/src/${PROJECT_PACKAGE}" 28 | 29 | dependencies: 30 | cache_directories: 31 | - "~/.yarn" 32 | - "~/.cache/yarn" 33 | - "~/.google-cloud-sdk" 34 | override: 35 | - yarn 36 | test: 37 | pre: 38 | # update locally with: 39 | # $ openssl aes-256-cbc -e -in service_account.json -out service_account.json.enc -k $KEY 40 | - openssl aes-256-cbc -d -in service_account.json.enc -k $KEY > service_account.json 41 | - gcloud auth activate-service-account --key-file service_account.json && ./tools/set_appcfg_token.sh 42 | override: 43 | - yarn test 44 | 45 | deployment: 46 | production: 47 | branch: master 48 | commands: 49 | - yarn run deploy -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "appengine-vendor-example", 3 | "version": "1.0.0", 4 | "author": "Kazuhiro Kubota