Slide 1

Slide 1 text

Mar 21th 2012 Deploying Happiness Richard Schneeman @schneems Fighting Homelessness & Hourschool & the 12factor App Thursday, March 22, 12

Slide 2

Slide 2 text

whoami • @Schneems • BSME with Honors from Georgia Tech • 5 + years experience Ruby & Rails • Work for @Heroku • Rails 3.1 & 3.2 contributor • 3 + years technical teaching • UT Austin Thursday, March 22, 12

Slide 3

Slide 3 text

Thursday, March 22, 12

Slide 4

Slide 4 text

Meet Hourschool Thursday, March 22, 12

Slide 5

Slide 5 text

Hourschool.com • Empower communities through teaching • Peer to Peer learning Thursday, March 22, 12

Slide 6

Slide 6 text

Hourschool.com • Community • Enterprise • Homeless Outreach • Nonprofit Thursday, March 22, 12

Slide 7

Slide 7 text

Homeless? Thursday, March 22, 12

Slide 8

Slide 8 text

Hourschool.com • Homelessness affects • All races, ages, and genders • Treating the symptoms won’t solve the problem • More shelters • More soup kitchens • Help them to help each other Thursday, March 22, 12

Slide 9

Slide 9 text

Real Skills Thursday, March 22, 12

Slide 10

Slide 10 text

Hourschool.com • Does Worry About • Filling classes with students • Bringing in new teachers • Spreading the word • Making an impact in the community Thursday, March 22, 12

Slide 11

Slide 11 text

Hourschool.com • Doesn’t worry about • Scaling their architecture • When to deploy • Managing their production system • Sleeping soundly at night Thursday, March 22, 12

Slide 12

Slide 12 text

But how? (you might ask) Thursday, March 22, 12

Slide 13

Slide 13 text

Hourschool.com • Heroku to manages their systems • The Twelve-Factor App manages their development methodology Thursday, March 22, 12

Slide 14

Slide 14 text

Twelve Factor • Can apply to any language • Speeds up deployment, makes scaling easier & keeps apps clean • Developed over direct exposure to the deployment of hundreds of thousands of apps Thursday, March 22, 12

Slide 15

Slide 15 text

Twelve-Factor for Hourschool Thursday, March 22, 12

Slide 16

Slide 16 text

Code + Methodology • Speed and confidence through: • Development environment • Staging environments • Consistent codebase practices • Quick access to logs and metrics • Easy scaling architecture Lets take a look Thursday, March 22, 12

Slide 17

Slide 17 text

development vs. production Thursday, March 22, 12

Slide 18

Slide 18 text

Development • As close to production as possible • Same data-stores (postgres, memcache) • Same language versions (Ruby 1.9) • Real/consistent data $ heroku db:pull Thursday, March 22, 12

Slide 19

Slide 19 text

Bundler • Bundle versions specified • ~> • Use semantic versioning • Prevent unexpected library changes gem 'twitter', '~> 2.0.2' gem "koala", '~> 1.2.1' gem 'tumblr-api', '~> 0.1.4' # ... Gemfile Thursday, March 22, 12

Slide 20

Slide 20 text

README.md • Living document • Standardize dev environment • Instructions for external dependencies • Instructions for starting processes • Problem with dev environment? • Put the fix in the readme $ brew install memcache $ foreman start Thursday, March 22, 12

Slide 21

Slide 21 text

but... it worked in development Thursday, March 22, 12

Slide 22

Slide 22 text

Staging • A “production like” environment • Try stuff out here before production • Set up: $ heroku create --stack cedar --remote staging Thursday, March 22, 12

Slide 23

Slide 23 text

Staging [remote "production"] url = [email protected]:hourschool.git fetch = +refs/heads/*:refs/remotes/heroku/* [remote "staging"] url = [email protected]:hourschool-drama.git fetch = +refs/heads/*:refs/remotes/heroku/* .git/config $ git push --remote staging mybranch:master Thursday, March 22, 12

Slide 24

Slide 24 text

Multiple Staging [remote "production"] # ... [remote "staging"] # ... [remote "staging-bill"] # ... [remote "staging-ted"] # ... .git/config Thursday, March 22, 12

Slide 25

Slide 25 text

Stage with Data • Install gem • Set up git remotes • Add pgbackups • Seed staging data $ gem install pgbackup-tasks $ heroku addons:add pgbackups $ bundle exec rake pgbackup:seed Thursday, March 22, 12

Slide 26

Slide 26 text

Deploy to Stage • Deploy to staging • Verify your changes worked • Merge into master • Deploy to production $ git push --remote staging mybranch:master $ git push --remote production Thursday, March 22, 12

Slide 27

Slide 27 text

1 app 1 codebase Thursday, March 22, 12

Slide 28

Slide 28 text

Git • All code for the app goes in one repository • Split out easily reusable code into separate libraries • i.e. github.com/schneems/wicked Thursday, March 22, 12

Slide 29

Slide 29 text

Git Flow • New feature? • Put it in a branch • Refactoring code? • Put it in a branch • Need a New Demo? • Put it in a branch Thursday, March 22, 12

Slide 30

Slide 30 text

Branches • Keep the codebase clean • Testing feature branches in staging is painless and easy with Heroku $ git co schneems/solr_search $ git push --remote staging mybranch:master Thursday, March 22, 12

Slide 31

Slide 31 text

Config Thursday, March 22, 12

Slide 32

Slide 32 text

Config • What varies between deploys • resource strings to databases • credentials to S3, twitter, facebook, etc. • canonical values, hostname • security tokens Thursday, March 22, 12

Slide 33

Slide 33 text

Config Does NOT go in source control Thursday, March 22, 12

Slide 34

Slide 34 text

secrets in source control aren’t secret Thursday, March 22, 12

Slide 35

Slide 35 text

Config - Production • Heroku ‘config’ • Read from environment $ heroku config:add S3_KEY=AFOONVBAR > puts ENV[“S3_KEY”] > “AFOONVBAR” Thursday, March 22, 12

Slide 36

Slide 36 text

Config - Development • Foreman • Procfile $ foreman start $ cat Procfile web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb worker: bundle exec rake jobs:work Thursday, March 22, 12

Slide 37

Slide 37 text

Config - Development • Local .env file • Foreman uses .env $ cat .env S3_KEY=AFOONVBAR FACEBOOK_APP_ID=281502345249818 FACEBOOK_SECRET=d59c2a439f4be49cf1 $ foreman run rails console ruby-1.9.3 > puts ENV[“S3_KEY”] ruby-1.9.3 > “AFOONVBAR” Thursday, March 22, 12

Slide 38

Slide 38 text

Open source- able? Thursday, March 22, 12

Slide 39

Slide 39 text

logging Thursday, March 22, 12

Slide 40

Slide 40 text

Logging • Production errors still happen • Tail logs to find the cause • Use a logging service to dig in deeper $ heroku logs --remote production --tail Thursday, March 22, 12

Slide 41

Slide 41 text

Logging Addons • Record Logs & Errors • New Relic (rpm) • Scout • Loggly • Papertrails • Airbrake (hoptoad) Thursday, March 22, 12

Slide 42

Slide 42 text

Logging Addons • Help when the problem is intermittent • Too much traffic for tail to be effective • Provide additional insights Thursday, March 22, 12

Slide 43

Slide 43 text

Error Pages • Admins get error + Backtrace Couldn't find Course with ID=chunkybacon Details Params: {"action"=>"show", "controller"=>"courses", "id"=>"chunkybacon"} Backtrace: lib/active_record/relation/finder_methods.rb:304:in `find_one' Thursday, March 22, 12

Slide 44

Slide 44 text

scale out Thursday, March 22, 12

Slide 45

Slide 45 text

Web Instances • Handle web requests • More instances = more throughput • Worker instances can help offload tasks Thursday, March 22, 12

Slide 46

Slide 46 text

Workers • Push long tasks that don’t fit in request cycle to a worker • Workers have the same code, but don’t serve web content • Perfect for • Delayed emails • Image Processing • etc. Thursday, March 22, 12

Slide 47

Slide 47 text

Workers • Use with a queuing system • Resque (redis) • DelayedJob (sql) • Enqueue from the web server • User signs up, queue email • Dequeue & run on the worker • Process next item in queue Thursday, March 22, 12

Slide 48

Slide 48 text

the web app demystified Thursday, March 22, 12

Slide 49

Slide 49 text

Twelve Factor Thursday, March 22, 12

Slide 50

Slide 50 text

Twelve Factor • Hourschool as a software service has a contract with Heroku • When the right development methods are used, their app can be cleanly deployed quickly Thursday, March 22, 12

Slide 51

Slide 51 text

Do You Like? • Minimizing new developer overhead? • Running in multiple environments? • Easily scaling without tooling, architecture or development headaches? • Having the latest updates available to users at a moments notice? Read more at 12factor.net Thursday, March 22, 12

Slide 52

Slide 52 text

Questions? @schneems Thursday, March 22, 12

Slide 53

Slide 53 text

12factor.net • Codebase • One codebase tracked in revision control, many deploys • Dependencies • Explicitly declare and isolate dependencies • Config • Store config in the environment • Backing Services • Treat backing services as attached resources Thursday, March 22, 12

Slide 54

Slide 54 text

12factor.net • Build, Release, Run • Strictly separate build and run stages • Process • Execute the app as one or more stateless processes • Port Binding • Export services via port binding • Concurrency • Scale out via the process model Thursday, March 22, 12

Slide 55

Slide 55 text

12factor.net • Disposability • Maximize robustness with fast startup and graceful shutdown • Dev/Prod Parity • Keep development, staging, and production as similar as possible • Logs • Treat logs as event streams • Admin Process • Run admin/management tasks as one-off processes Thursday, March 22, 12