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

Plack + Carton: deployment made simple and awesome

Plack + Carton: deployment made simple and awesome

at PerlMova and YAPC::Russia 2012

Tatsuhiko Miyagawa

May 12, 2012
Tweet

More Decks by Tatsuhiko Miyagawa

Other Decks in Technology

Transcript

  1. Plack + Carton deployment simple & awesome Tatsuhiko Miyagawa Perl

    Mova / YAPC::Russia 2012 Saturday, May 12, 12
  2. Me • Tatsuhiko Miyagawa • CPAN: MIYAGAWA • github.com/miyagawa •

    Twitter @miyagawa • Lives in San Francisco, CA Saturday, May 12, 12
  3. #  WSGI def  hello(environ,  start_response):    start_response(“200  OK”,  [  

         (‘Content-­‐Type’,  ‘text/plain’)    ])    return  [“Hello  World”] Saturday, May 12, 12
  4. WSGI • Django • Bottle • CherryPy • Tornado •

    Pylons • Flask • mod_wsgi • Paste • gunicorn • uWSGI • wsgiref • Google AppEngine Saturday, May 12, 12
  5. WSGI WSGI middleware Django Bottle Flask Tornado Apache lighttpd nginx

    mod_wsgi wsgi handlers GAE Saturday, May 12, 12
  6. #  Rack class  Hello    def  call(env)      

     return  [              200,              {  “Content-­‐Type”  =>  ”text/plain”  },                [“Hello  World”]        ]    end end Saturday, May 12, 12
  7. Rack • Rails • Merb • Sinatra • Camping •

    Ramaze • etc. • Unicorn • Thin • Mongrel • Rainbows! • Phusion Passenger • Heroku Saturday, May 12, 12
  8. Rack Rack middleware Rails Merb Sinatra Ramaze Apache lighttpd Thin

    Unicorn Rack handlers Mongrel Saturday, May 12, 12
  9. #  WSGI def  hello(environ,  start_response):    start_response(“200  OK”,  [  

         (‘Content-­‐Type’,  ‘text/plain’)    ])    return  [“Hello  World”] Saturday, May 12, 12
  10. #  Rack class  Hello    def  call(env)      

     return  [              200,              {  “Content-­‐Type”  =>  ”text/plain”  },                [“Hello  World”]        ]    end end Saturday, May 12, 12
  11. #  PSGI my  $app  =  sub  {      

     my  $env  =  shift;        return  [                  200,                [  ‘Content-­‐Type’,  ‘text/plain’  ],                [  ‘Hello  World’  ],        ]; }; Saturday, May 12, 12
  12. #  PSGI my  $app  =  sub  {      

     my  $env  =  shift;        return  [                  200,                [  ‘Content-­‐Type’,  ‘text/plain’  ],                [  ‘Hello  World’  ],        ]; }; Saturday, May 12, 12
  13. CGI::Application Apache IIS lighttpd CGI.pm CGI fastcgi mod_perl Jifty Mason

    Catalyst Mason::CGIHandler Catalyst::Engine nginx HTTP::Server ::Simple Saturday, May 12, 12
  14. PSGI Plack::Middleware Catalyst CGI::App Jifty Dancer Apache lighttpd HTTP::Server::PSGI Twiggy

    Starman Plack::Handler::* (CGI, FCGI, Apache) Saturday, May 12, 12
  15. #  Catalyst use  MyApp; MyApp-­‐>setup_engine(‘PSGI’); my  $app  =  sub  {

     MyApp-­‐>run(@_)  }; #  $app  is  a  PSGI  app! Saturday, May 12, 12
  16. #  Dancer use  Dancer; get  ‘/’  =>  sub  {  

         “Hello  World”; }; dance;  #  returns  a  PSGI  app! Saturday, May 12, 12
  17. #  Mojolicious::Lite use  Mojolicious::Lite; get  ‘/:name’  =>  sub  {  

         my  $self  =  shift;        $self-­‐>render_text(‘Hello!’); }; app-­‐>start;  #  returns  PSGI  app Saturday, May 12, 12
  18. #  Web::Simple use  Web::Simple  ‘MyApp’; package  MyApp; dispatch  {  

     sub(GET)  {        [  200,  [...],  [  ‘Hello’  ]  ];    } }; my  $app  =  MyApp-­‐>as_psgi; #  $app  is  a  PSGI  app! Saturday, May 12, 12
  19. Recap: PSGI • Inspired by Python, Ruby • Very simple

    • Code ref, hash ref, array ref • adapted by many frameworks and businesses Saturday, May 12, 12
  20. Step 3: Run your code on the cloud via git

    push! Saturday, May 12, 12
  21. Recap • PSGI: web app standard • cpanm: dependencies installation

    • PSGI + cpanm => Deploy to the cloud! Saturday, May 12, 12
  22. use  ExtUtils::MakeMaker; WriteMakefile(    NAME  =>  ‘MyModule’,    VERSION  =>

     ‘1.22’,    PREREQ_PM  =>  {        ‘JSON’  =>  0,        ‘Hash::MultiValue’  =>  ‘0.11’,    }, ); Saturday, May 12, 12
  23. use  Module::Build; my  $build  =  Module::Build-­‐>new(    module_name  =>  ‘MyModule’,

       requires  =>  {        ‘JSON’  =>  ‘2.00’,        ‘Hash::MultiValie’  =>  ‘0.20’,    }, ); $build-­‐>create_build_script; Saturday, May 12, 12
  24. use  ExtUtils::MakeMaker; WriteMakefile(    NAME  =>  ‘MyModule’,    VERSION  =>

     ‘1.22’,    PREREQ_PM  =>  {        ‘JSON’  =>  0,        ‘Hash::MultiValue’  =>  ‘0.11’,    }, ); Saturday, May 12, 12
  25. use  Module::Build; my  $build  =  Module::Build-­‐>new(    module_name  =>  ‘MyModule’,

       requires  =>  {        ‘JSON’  =>  ‘2.00’,        ‘Hash::MultiValie’  =>  ‘0.20’,    }, ); $build-­‐>create_build_script; Saturday, May 12, 12
  26. • Jul 2nd: Started working on project • using Web::Framework

    1.1 • Jul 9th: Finished version 1.0 • Jul 10-15th: internal beta, QA • Jul 16th: Deploy to the cloud/production Saturday, May 12, 12
  27. • Jul 2nd: Started working on project • using Web::Framework

    1.1 • Jul 9th: Finished version 1.0 • Jul 10-15th: internal beta, QA • Jul 16th: Web::Framework 1.2 is released • Jul 16th: Deploy to the cloud/production Saturday, May 12, 12
  28. Makefile.PL Recap • Not so easy to write • Could

    have deps, bootstrapping issue • No way to freeze versions Saturday, May 12, 12
  29. requires  ‘Plack’,  0.9980; requires  ‘Catalyst’,  ‘>=  5.8,  <  5.9’; conflicts

     ‘MooseX::Foo’,  ‘<  0.10’; on  ‘test’  =>  sub  {        requires  ‘Test::More’,  0.80; }; on  ‘develop’  =>  sub  {        requires  ‘Devel::NYTProf’; }; Saturday, May 12, 12
  30. • App-specific local environment • Fast and safe install •

    Dep-tree analysis, including versions • Locking module versions • Easy Redeployment • Single-file, VCS friendly • Safe and easy rollback Saturday, May 12, 12
  31. Local perl environment Using local::lib and cpanm -L Each app

    has an isolated local library path Saturday, May 12, 12
  32. Dep tree analysis Rebuild the dependency tree from meta info

    Checks if anything is missing/superfluous Saturday, May 12, 12
  33. Easy Redeployment Reinstall exactly the same set of modules on

    another prod/development machines. Saturday, May 12, 12
  34. Single-file, VCS friendly You can add carton.lock to git update

    whenever you update modules Saturday, May 12, 12
  35. WARNING It is pre-1.0 beta software, some features are missing

    or not working correctly (yet). Saturday, May 12, 12
  36. TODO / Roadmap • Update specific modules • Make install

    and bundle faster • Inject old versions / patched versions • Install from git SHA Saturday, May 12, 12
  37. Recap • Write app in PSGI/Plack • Specify CPAN dependencies

    with cpanfile • Manage them and deploy with carton • Inspired by Ruby :) Saturday, May 12, 12