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

Heroku Tutorial

Harold Giménez
September 17, 2014
170

Heroku Tutorial

In this tutorial you will understand what Heroku is and what primitives are exposed so that you are able to run and scale applications in your favorite language. We will discuss dynos and their env, buildpacks, deployment, releases, HTTP routing, addons, and of course Postgres.

Harold Giménez

September 17, 2014
Tweet

Transcript

  1. CONTENT • What is Heroku? • What are dynos and

    how do I manage them? • Procfile • Logs • HTTP routing • Releases, rollback and pipelines • Postgres and Addons • Buildpacks • Where to learn more Wednesday, September 17, 14
  2. WHAT IS HEROKU? Database Enterprise grade Postgres as a service

    ! Add-ons Marketplace for logging, data and more ! Dynos Run virtually any language at any scale ! Wednesday, September 17, 14
  3. WHAT IS HEROKU? 5 Billion Requests per day ! 3+

    Million Apps Created ! 125+ Add-on Services ! Wednesday, September 17, 14
  4. SET UP • Create a Heroku account: https://signup.heroku.com/ • Download

    the toolbelt: https://toolbelt.heroku.com • Install git Wednesday, September 17, 14
  5. PUSH YOUR FIRST APP $ mkdir first-app $ cd first-app

    $ git init $ echo "Hello! It’s <?= date('D, d M Y H:i:s'); ?>." > index.php $ git add . && git commit -m "First commit" $ heroku create first-app-$(whoami) $ git push heroku master $ heroku open Wednesday, September 17, 14
  6. $ heroku ps === web (1X): `vendor/bin/heroku-php-apache2` web.1: up 2014/09/15

    18:46:21 (~ 44m ago) $ heroku ps:scale web=2 Scaling dynos... done, now running web at 2:1X. Wednesday, September 17, 14
  7. PROCFILE $ cat Procfile web: ./bin/web worker: ./bin/worker $ #

    on heroku $ heroku ps:scale worker=50 web=10 $ # locally, use foreman $ foreman run Wednesday, September 17, 14
  8. LOGS $ heroku logs --tail 2014-09-16T13:23:17.174042+00:00 heroku[router]: at=info method=GET path="/"

    host=hgmnz-pgopen.herokuapp.com request_id=5135b624-7d01-4ef9-842c-055d58157325 fwd="142.177.69.102" dyno=web.1 connect=2ms service=9ms status=200 bytes=580 Use a logging addon for searchable log storage Wednesday, September 17, 14
  9. CONFIG $ heroku config hgmnz-pgopen has no config vars. $

    heroku config:set WEB_PASSWORD=s3krit Setting config vars and restarting hgmnz-pgopen... done, v6 WEB_PASSWORD: s3krit $ heroku config === hgmnz-pgopen Config Vars WEB_PASSWORD: s3krit Wednesday, September 17, 14
  10. RELEASES $ heroku releases === hgmnz-pgopen Releases v6 Set WEB_PASSWORD

    config vars [email protected] 2014/09/16 09:57:56 (~ 1m ago) v5 Deploy 2d97a3e [email protected] 2014/09/15 18:46:10 (~ 15h ago) v4 Deploy 754b51d [email protected] 2014/09/15 18:43:36 (~ 15h ago) v3 Deploy d9528ae [email protected] 2014/09/15 18:37:15 (~ 15h ago) v2 Enable Logplex [email protected] 2014/09/15 18:36:21 (~ 15h ago) v1 Initial release [email protected] 2014/09/15 18:36:20 (~ 15h ago) Wednesday, September 17, 14
  11. ROLLBACK! $ heroku logs --tail [exception traces everywhere!] $ heroku

    ps === web (1X): `vendor/bin/heroku-php-apache2` web.1: crashed 2014/09/16 07:42:55 (~ 1m ago) $ heroku releases:rollback v3 Rolling back hgmnz-pgopen... done, v3 $ heroku releases | head -n2 === hgmnz-pgopen Releases v7 Rollback to v3 [email protected] 2014/09/16 10:10:06 (~ 37s ago) Wednesday, September 17, 14
  12. PIPELINES $ heroku labs:enable pipelines $ heroku plugins:install git://github.com/heroku/heroku-pipeline.git $

    heroku pipeline:add your-app-production --app your-app-staging $ heroku pipelines Pipeline: your-app-staging ---> your-app-production $ heroku pipeline:diff Comparing your-app-staging to your-app-production...done, your-app- staging ahead by 1 commit: 73ab415 2012-01-01 A super important fix (Jim) $ heroku pipeline:promote Promoting myapp-staging to myapp...done, v2 Wednesday, September 17, 14
  13. ADDONS Easily add managed infrastructure services to your heroku app

    addons.heroku.com $ heroku addons:add addon-name Adding addon-name on test-app... done, v425 (free) Wednesday, September 17, 14
  14. HEROKU POSTGRES • Implemented as a heroku addon • Fully

    managed • Visibility through log events and web frontend • Various plan levels • Continuous Protection, forks, followers, HA with automated failover, rollback (PiTR), logical backups (pg_dump), encryption at rest Wednesday, September 17, 14
  15. HEROKU POSTGRES $ heroku addons:add heroku-postgresql:standard-0 Adding heroku-postgresql:standard-0 on hgmnz-pgopen...

    done, v9 ($50) Attached as HEROKU_POSTGRESQL_GRAY_URL Use `heroku addons:docs heroku-postgresql` to view documentation. $ heroku pg:psql GRAY $ heroku pg:info $ heroku pg:diagnose Wednesday, September 17, 14
  16. CREATE FOLLOWERS $ heroku addons:add heroku-postgresql:standard-0 --follow=gray Adding heroku-postgresql:standard-0 on

    hgmnz-pgopen... done, v23 ($50/mo) Attached as HEROKU_POSTGRESQL_BLUE_URL Follower will become available for read-only queries when up-to-date Use `heroku pg:wait` to track status. Use `heroku addons:docs heroku-postgresql` to view documentation. Wednesday, September 17, 14
  17. AND FORKS $ heroku addons:add heroku-postgresql:standard-0 --fork=rose Adding heroku-postgresql:standard-0 on

    hgmnz-pgopen... done, v24 ($50/mo) Attached as HEROKU_POSTGRESQL_OLIVE_URL Database will become available after it completes forking Use `heroku pg:wait` to track status. Use `heroku addons:docs heroku-postgresql` to view documentation. Wednesday, September 17, 14
  18. HEROKU PG EXTRAS $ heroku plugins:install git://github.com/heroku/heroku-pg-extras.git $ heroku pg:index-usage

    $ heroku pg:unused-indexes $ heroku pg:cache-hit $ heroku pg:ps $ heroku pg:locks $ heroku pg:blocking $ heroku pg:outliers $ heroku pg:pull $ heroku pg:push $ heroku pg:index-size $ heroku pg:table-size $ heroku pg:seq-scans $ heroku pg:long-running-queries $ heroku pg:bloat $ heroku pg:vacuum-stats Wednesday, September 17, 14
  19. BUILDPACKS • Installs runtime dependencies, like language VMs • All

    official buildpacks are open source • Auto-detected by Heroku, but can be customized by setting BUILDPACK_URL config var. Wednesday, September 17, 14
  20. CREATING BUILDPACKS • API: https://devcenter.heroku.com/articles/buildpack-api • Three scripts • bin/detect:

    whether to apply buildpack to app • bin/compile: perform transformations on the app • bin/release: provide metadata back to runtime Wednesday, September 17, 14
  21. BUILDPACKS • Official buildpacks: https://devcenter.heroku.com/articles/ buildpacks#default-buildpacks • Third party: https://devcenter.heroku.com/articles/third-party-

    buildpacks • Run many buildpacks on same app with the multi buildpack: https://github.com/ddollar/heroku-buildpack-multi Wednesday, September 17, 14