Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deploying Go 
 to Heroku

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Deploying Go 
 to Heroku

Avatar for Paweł Słomka

Paweł Słomka

February 21, 2019
Tweet

More Decks by Paweł Słomka

Other Decks in Programming

Transcript

  1. @pawel_slomka @pawel_slomka ABOUT ME • Blogger at mycodesmells.com • Go

    developer at Ingrid • Co-organizer of GoWroc meetup • Runner ! • Millenial @pawel_slomka
  2. @pawel_slomka WHY • You have some cool code developed locally

    • You want to share that code with the world
  3. @pawel_slomka WHERE • There a few options to choose from


    (Google App Engine, AWS, Azure, etc.) • Heroku is cool as well • Multiple languages support • Docker support • Free tier (with limitations, but enough for development)
  4. @pawel_slomka HOW I have the following code: package main import

    “fmt” import “net/http” func main() { http.HandleFunc(“/“, func(rw http.ResponseWriter, _ *http.Request) { fmt.Fprint(rw, “Hello GoWroc!”) } http.ListenAndServe(“:8080”, nil) }
  5. @pawel_slomka HOW Minor tweak for Heroku support: package main …

    import “os” func main() { … http.ListenAndServe(“:”+os.Getenv(“PORT”), nil) }
  6. @pawel_slomka HOW Add Dockerfile FROM golang:stretch as build COPY .

    /src WORKDIR /src RUN go build -o /app . ### FROM heroku/heroku:18 COPY --from=build /app /app CMD ["/app"]
  7. @pawel_slomka DEPLOY Creating an app at Heroku heroku create my-app

    heroku container:push -a my-app web Publishing image in Heroku registry: heroku container:release -a my-app web Publishing image in Heroku registry:
  8. @pawel_slomka SUMMARY • Little effort • Little time • Huge

    satisfaction • Your code is in the cloud!