15
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GAE/Go (+dep) で gcloud app deploy する為の構成

Last updated at Posted at 2018-03-01

Go1.11対応が入り go.mod が使えるようになりました!!🎉

参考情報
Structuring Web Services in App Engine
App Engine Standard Go 1.9 migration to Go 1.11

〜〜〜 以下、むかしむかし、辛かった時代のお話 〜〜〜

構成だけで解決するのは無理なので make deploy でシンボリックリンクを利用しデプロイ出来る $GOPATH を作った上で gcloud app deploy を叩く作戦

構成

./
├── Makefile
├── README.md
├── build
│   └── go ... デプロイ時の $GOPATH、make deploy 時にシンボリックリンクを貼る
│       └── src
│           ├── github.com -> ../../../go/src/lib/vendor/github.com
│           ├── golang.org -> ../../../go/src/lib/vendor/golang.org
│           └── lib
│               └── app -> ../../../../go/src/lib/app
├── devtools
├── gae ... GAE/Goのプロジェクトルート、デプロイ時の CWD
│   ├── admin
│   │   ├── admin.yaml
│   │   ├── init.go
│   │   ├── static
│   │   └── views
│   ├── app
│   │   ├── app.yaml
│   │   ├── cron.yaml
│   │   ├── init.go
│   │   ├── static
│   │   └── views
│   ├── dispatch.yaml
│   ├── var
│   └── worker
│       ├── init.go
│       └── worker.yaml
└── go ... IDE起動時やdev_appserver.py 時の $GOPATH
    └── src
        └── lib
            ├── Gopkg.lock
            ├── Gopkg.toml
            ├── app
            └── vendor

Makefile

PROJECT_NAME="gaego-template-sample"

create:
	gcloud app create --project $(PROJECT_NAME)

init:
	cd go/src/lib; GOPATH=$(abspath go) dep init -v

install:
	cd go/src/lib; GOPATH=$(abspath go) dep ensure -v

update:
	cd go/src/lib; GOPATH=$(abspath go) dep ensure -v -update

serve:
	cd gae; GOPATH=$(abspath go) dev_appserver.py \
		--datastore_path=var/.datastore \
		dispatch.yaml app/app.yaml admin/admin.yaml worker/worker.yaml

deploy:
	# 一旦クリーン
	find build/go/src -type l -delete
	# vendor配下になるディレクトリのシンボリックを作成
	ls -1 go/src/lib/vendor | xargs -n 1 -I {} ln -s ../../../go/src/lib/vendor/{} build/go/src/{}
	# ローカルパッケージのシンボリックを作成
	ln -s ../../../../go/src/lib/app build/go/src/lib/app
	cd gae; GOPATH=$(abspath build/go) gcloud app deploy --project $(PROJECT_NAME) --version 1 app/app.yaml

clean:
	find build/go/src -type l -delete

https://issuetracker.google.com/issues/38449183#comment19
早くgo1.10のサポートと共にベンダリングもサポートされて欲しい

参考

15
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?