Slide 1

Slide 1 text

Deploy Golang Web Application to Heroku

Slide 2

Slide 2 text

I’m Taichi Nakashima twitter ID is @deeeet

Slide 3

Slide 3 text

http://deeeet.com/writing

Slide 4

Slide 4 text

Marniti Λ͔ͭͬͨ Golang Web Application Λ Heroku ʹσϓϩΠ͢Δ

Slide 5

Slide 5 text

• GoͷܰྔWebϑϨʔϜϫʔΫ • Sinatra΍ExpressͷӨڹ • MiddlewareʹΑΔ֦ு Martini.

Slide 6

Slide 6 text

sinatra require 'sinatra' ! get '/' do "Hello!" end

Slide 7

Slide 7 text

Martini. package main ! import "github.com/go-martini/martini" ! func main() { m := martini.Classic() m.Get("/", func() string { return "Hello!" }) m.Run() }

Slide 8

Slide 8 text

• ґଘύοέʔδͷ؅ཧ • Procfileͷ४උ • Buildpackͷ४උ How?

Slide 9

Slide 9 text

$ go get github.com/kr/godep $ godep save $ gem install bundler $ bundle install Dependency

Slide 10

Slide 10 text

Procfile web: bundle exec rackup config.ru -p $PORT $ echo "web: $(basename `pwd`)" > Procfile

Slide 11

Slide 11 text

Buildpack $ heroku create $ heroku create -b https://github.com/kr/ heroku-buildpack-go.git

Slide 12

Slide 12 text

Deploy $ git push heroku master

Slide 13

Slide 13 text

Heroku on Docker Build a Docker container for app using Heroku Buildpacks

Slide 14

Slide 14 text

! • ContainerܕԾ૝Խιϑτ ΢ΣΞ • VMͱൺ΂ͯΦʔόϔου͕ গͳ͘ߴ଎ʹಈ࡞ • OSXͰ΋ܰྔVMΛ্ཱͪ͛ Ε͹࢖͑Δ

Slide 15

Slide 15 text

• CenturyLinkLabs࡞ • BuildpackΛ࢖ͬͨDocker container Λ࡞੒ • ϩʔΧϧʹHerokuͱಉ͡؀ ڥΛؾܰʹ࡞Γ͍ͨΛ࣮ݱ • Rails, Node, Golang Building

Slide 16

Slide 16 text

Prepare on OSX $ brew install docker boot2docker $ boot2docker init $ boot2docker up

Slide 17

Slide 17 text

Prepare $ gem install building

Slide 18

Slide 18 text

Run building $ cd your-application $ building -p 3000 tcnksm/goapp

Slide 19

Slide 19 text

Run building $ building -p 3000 tcnksm/goapp create Dockerfile building docker build -t tcnksm/goapp:latest . Step 0 : FROM ctlc/buildstep:ubuntu13.10 ---> a5432f93c775 Step 1 : ADD . /app ---> ef908258208c Step 2 : RUN /build/builder ---> Running in afd1b5565e3c Go app detected -----> Installing go1.2.1... done -----> Running: godep go install -tags heroku ./... -----> Discovering process types Procfile declares types -> web ---> 1d4265dcac7 running docker run -d -p 3000 -e "PORT=3000" tcnksm/goapp

Slide 20

Slide 20 text

Conclusion • GolangͷWeb ApplicationΛHerokuʹDeploy • Heroku on Docker