地味に毎回やってるから自動化してサクッと開発を始めたい。
martini-heroku-init.goみたいなの作ってもいいかも?
※templateかな?
package main
import (
"github.com/go-martini/martini"
)
func main() {
m := martini.Classic()
m.Get("/", func() string {
return "Hello world!"
})
m.Run()
}
git init
しないとgodepが使えない。
$ git init
$ godep save
※2015/11/21 heroku公式Goサポートで不要になった。
$ echo ${PWD##*src/} > .godir
$ echo "web: $(basename `pwd`)" > Procfile
$ heroku create {name}
herokuのAccount情報にあるAPIKeyをWerckerの対象プロジェクトのDeploys設定のタブで選択して、デプロイTargetとか設定。
wercker.yml
の最後に以下を追加してgithubにpushで完了。
box: wercker/golang
# Build definition
build:
# The steps that will be executed on build
steps:
# Sets the go workspace and places you package
# at the right place in the workspace tree
- setup-go-workspace
# Gets the dependencies
- script:
name: go get
code: |
cd $WERCKER_SOURCE_DIR
go version
go get -t ./...
# Build the project
- script:
name: go build
code: |
go build ./...
# Test the project
- script:
name: go test
code: |
go test ./...
deploy:
steps:
- heroku-deploy:
key-name: MY_DEPLOY_KEY
WerckerのWeb上でMyAppのSettingで、masterをauto deployに指定する。 (スペース区切りで複数のブランチを指定可能)
あと、ssh-key設定しないと毎回新しいssh-keyでherokuにアクセスしてメールバンバンくるから設定したほうがいい。