12 Factor CakePHP Applications

12 Factor CakePHP Applications

A brief overview of what 12 factor applications are and how to best apply those principles to CakePHP Applications.

35ce1084ddd81008486fcc31170bec96?s=128

Jose Diaz-Gonzalez

September 01, 2013
Tweet

Transcript

  1. 12-Factor cakephp applications i’ll tell you hwat

  2. cakefest 2013 12 factor cakephp applications About me Cakephp core

    seatgeek employee accidental operations all around good guy
  3. cakefest 2013 12 factor cakephp applications a common problem ‣

    supporting more requests ‣ configuration ‣ dependency management ‣ installing the codebase ‣ logging ‣ background tasks
  4. cakefest 2013 12 factor cakephp applications building scalable applications codebase

  5. use version control cakefest 2013 12 factor cakephp applications git

    init
  6. one codebase, multiple deploys cakefest 2013 SEATGEEEK GOALS deploy staging

    deploy prod
  7. cakefest 2013 12 factor cakephp applications building scalable applications Dependencies

  8. use composer cakefest 2013 12 factor cakephp applications composer update

  9. private dependencies? cakefest 2013 12 factor cakephp applications satis

  10. cakefest 2013 12 factor cakephp applications building scalable applications configuration

  11. environment variables cakefest 2013 12 factor cakephp applications SetEnv DEBUG

    0
  12. USING ENV VARS IN PHP cakefest 2013 12 factor cakephp

    applications $DEBUG = getenv(‘DEBUG’);
  13. cakefest 2013 12 factor cakephp applications building scalable applications BACKING

    SERVICES
  14. cakefest 2013 12 factor cakephp applications PARSING RESOURCES

  15. cakefest 2013 12 factor cakephp applications <?php class DATABASE_CONFIG {

    public $default = array( 'persistent' => false, 'prefix' => '', 'encoding' => 'utf8', ); public function __construct() { $DATABASE_URL = parse_url(getenv('DATABASE_URL')); $this->default['datasource'] => 'Database/Mysql'; $this->default['host'] => Hash::get($DATABASE_URL, 'host'); $this->default['login'] => Hash::get($DATABASE_URL, 'user'); $this->default['password'] => Hash::get($DATABASE_URL, 'pass'); $this->default['database'] => substr(Hash::get($DATABASE_URL, 'path'), 1); } }
  16. cakefest 2013 12 factor cakephp applications building scalable applications BUILD,

    RELEASE, RUN
  17. BUILD STEP cakefest 2013 12 factor cakephp applications PACKAGE ALL

    THE THINGS
  18. CREATE A RELEASE cakefest 2013 12 factor cakephp applications TAR

    AND DEPLOY
  19. RUN cakefest 2013 12 factor cakephp applications RESTART PROCESSES CLEAR

    CACHE
  20. cakefest 2013 12 factor cakephp applications building scalable applications process

  21. stateless cakefest 2013 12 factor cakephp applications Configure::write('Session', array( 'defaults'

    => 'cache', 'handler' => array( 'config' => 'memcache_sessions' ) ));
  22. cakefest 2013 12 factor cakephp applications building scalable applications port

    binding
  23. php port binding cakefest 2013 12 factor cakephp applications SERVER

    BECOMES A DEPENDENCY
  24. cakefest 2013 12 factor cakephp applications building scalable applications CONCURRENCY

  25. NO MORE WEBCRONS cakefest 2013 12 factor cakephp applications -

    Need to send an email? - Cache a large dataset in the database? - Generate reports for Bill in accounting?
  26. background processing cakefest 2013 12 factor cakephp applications kamisama/cake-resque josegonzalez/cake_djjob

  27. cakefest 2013 12 factor cakephp applications building scalable applications dev/prod

    parity
  28. cakefest 2013 12 factor cakephp applications run tests in the

    same environment
  29. mysql in dev, mysql in prod cakefest 2013 12 factor

    cakephp applications vagrantup.com
  30. cakefest 2013 12 factor cakephp applications building scalable applications logs

  31. cakelog cakefest 2013 12 factor cakephp applications CakeLog::config('default', array( 'engine'

    => 'ConsoleLog', 'stream' => new ConsoleOutput('php://stdout') ));
  32. cakefest 2013 12 factor cakephp applications logging format ‣ UTC

    tiMESTAMP, ISO8601 ‣ REQUEST DATA ‣ UNIQUE REQUEST ID ‣ USER IDENTIFIER ‣ THE MESSAGE ITSELF
  33. cakefest 2013 12 factor cakephp applications building scalable applications admin

    processes
  34. cakeshell cakefest 2013 12 factor cakephp applications Console/cake Migrations.migration run

    all
  35. repl cakefest 2013 12 factor cakephp applications brew install Boris

    wget -O boris.php http://bit.ly/1dURtFw mv boris.php app/Console/boris.php php app/Console/boris.php
  36. cakefest 2013 12 factor cakephp applications build better apps ‣

    reduce developer friction ‣ higher scalability ‣ increase portability ‣ decrease management overhead
  37. developer love thanks cakefest 2013 12 factor cakephp applications