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

Carton 1.0 at OSCON 2013

Carton 1.0 at OSCON 2013

Introducing what's new in Carton at O'Reilly Open Source Convention 2013.

Tatsuhiko Miyagawa

July 25, 2013
Tweet

More Decks by Tatsuhiko Miyagawa

Other Decks in Technology

Transcript

  1. Carton 1.0
    managing CPAN deps the right way
    Tatsuhiko Miyagawa
    @miyagawa
    O'Reilly OSCON 2013
    Wednesday, July 24, 13

    View full-size slide

  2. Me
    • Tatsuhiko Miyagawa
    • Lives in San Francisco
    • {github,twitter,CPAN}/miyagawa
    Wednesday, July 24, 13

    View full-size slide

  3. Managing CPAN
    Dependencies
    Wednesday, July 24, 13

    View full-size slide

  4. How many CPAN modules
    your app depends on?
    Wednesday, July 24, 13

    View full-size slide

  5. When is the last time
    upgrading a CPAN
    module broke your app?
    Wednesday, July 24, 13

    View full-size slide

  6. Case Study:
    Web App Development
    Wednesday, July 24, 13

    View full-size slide

  7. You’re writing a new web app
    using as many CPAN modules.
    Wednesday, July 24, 13

    View full-size slide

  8. Get them from CPAN,
    install on your machine.
    Wednesday, July 24, 13

    View full-size slide

  9. john@local>  cpanm  Web::Framework
    installed  LWP-­‐5.912
    installed  Plack-­‐0.9980
    installed  Web-­‐Framework-­‐1.10
    Wednesday, July 24, 13

    View full-size slide

  10. Test it...
    Wednesday, July 24, 13

    View full-size slide

  11. Works? Ship it!
    Wednesday, July 24, 13

    View full-size slide

  12. What if ...
    Wednesday, July 24, 13

    View full-size slide

  13. • 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 production
    Wednesday, July 24, 13

    View full-size slide

  14. • Jul 2nd: Started working on project
    • using Web::Framework 1.1
    • Jul 9th: Finished version 1.0
    • Jul 10-15th: internal beta, QA
    • Jul 15th: Web::Framework 1.2 is released
    • Jul 16th: Deploy to the cloud/production
    Wednesday, July 24, 13

    View full-size slide

  15. root@prod>  cpanm  Web::Framework
    installed  LWP-­‐5.912
    installed  Plack-­‐0.9980
    installed  Web-­‐Framework-­‐1.20
    Wednesday, July 24, 13

    View full-size slide

  16. Web::Framework 1.2
    API changes!
    Wednesday, July 24, 13

    View full-size slide

  17. Wednesday, July 24, 13

    View full-size slide

  18. Wednesday, July 24, 13

    View full-size slide

  19. “Upgrading CPAN modules
    broke my app”
    Wednesday, July 24, 13

    View full-size slide

  20. Dependencies are
    part of your app.
    Wednesday, July 24, 13

    View full-size slide

  21. a solution
    cpanm 1.6
    Wednesday, July 24, 13

    View full-size slide

  22. >  cpanm  Web::[email protected]
    installed  Web-­‐Framework-­‐1.10
    Wednesday, July 24, 13

    View full-size slide

  23. >  cpanm  Web::Framework~">=  1.0,  <  1.2"
    installed  Web-­‐Framework-­‐1.19
    Wednesday, July 24, 13

    View full-size slide

  24. ♥ MetaCPAN
    Wednesday, July 24, 13

    View full-size slide

  25. a solution
    cpanfile + cpanm 1.6
    Wednesday, July 24, 13

    View full-size slide

  26. >  cat  cpanfile
    requires  'Web::Framework',  '==  1.10';
    >  cpanm  -­‐-­‐installdeps  .
    installed  Web-­‐Framework-­‐1.10
    Wednesday, July 24, 13

    View full-size slide

  27. cpanfile
    DSL to describe prereqs
    Wednesday, July 24, 13

    View full-size slide

  28. requires  'Catalyst',  '5.8000';  
    recommends  'JSON::XS',  '2.0';
    on  'test'  =>  sub  {
       requires  'Test::More',  '>=  0.96'
    };
    on  'develop'  =>  sub  {
       recommends  'Devel::NYTProf';
    };
    feature  'sqlite'  =>  sub  {
       requires  'DBD::SQLite';
    };
    Wednesday, July 24, 13

    View full-size slide

  29. inspired by:
    gemfile(5)
    Wednesday, July 24, 13

    View full-size slide

  30. Backward compatible to:
    Module::Install(::DSL)
    Wednesday, July 24, 13

    View full-size slide

  31. Converted to to:
    CPAN::Meta::Prereqs
    Wednesday, July 24, 13

    View full-size slide

  32. Toolset
    Module::CPANfile
    Module::Install::CPANfile
    Dist::Zilla plugins
    Wednesday, July 24, 13

    View full-size slide

  33. Supported by
    dzil, Milla & cpanm 1.6
    Wednesday, July 24, 13

    View full-size slide

  34. cpanfile + cpanm
    • Simple
    • Yet powerful and flexible way to describe
    dependencies and version requirements
    • Version control cpanfile
    Wednesday, July 24, 13

    View full-size slide

  35. caveats
    • Locking each dependency with specific
    version is tedious work
    • Can only lock direct dependencies
    • MetaCPAN as SPOF
    • No easy/reliable way to fallback
    Wednesday, July 24, 13

    View full-size slide

  36. Many other solutions
    Needs servers, Needs databases
    Too simple, Too complicated, etc.
    Wednesday, July 24, 13

    View full-size slide

  37. the Solution
    Wednesday, July 24, 13

    View full-size slide

  38. Carton
    https://github.com/miyagawa/carton
    Wednesday, July 24, 13

    View full-size slide

  39. Inspired by...
    Wednesday, July 24, 13

    View full-size slide

  40. Wednesday, July 24, 13

    View full-size slide

  41. Basic idea:
    Describe CPAN dependencies
    snapshot tarball pathnames
    Wednesday, July 24, 13

    View full-size slide

  42. Built on top of:
    cpanfile + cpanm 1.6
    Wednesday, July 24, 13

    View full-size slide

  43. • App-specific local environment
    • Fast and safe install with caches
    • Dep-tree analysis, including versions
    • Freezing module versions
    • Conservative updates
    • Easy Redeployment, Rollback
    • Single-file, VCS friendly
    Wednesday, July 24, 13

    View full-size slide

  44. Local perl environment
    Using local::lib and cpanm -L
    Each app has an isolated local library path
    Wednesday, July 24, 13

    View full-size slide

  45. Fast and safe install
    Saves MYMETA.json and install meta info
    Wednesday, July 24, 13

    View full-size slide

  46. Dep tree analysis
    Rebuild the dependency tree from snapshot
    Checks if anything is missing/superfluous
    Wednesday, July 24, 13

    View full-size slide

  47. Freezing versions
    Versions are saved in snapshots
    including dependencies
    Wednesday, July 24, 13

    View full-size slide

  48. Easy Redeployment
    Reinstall exactly the same set of modules
    on another prod/development machines.
    Wednesday, July 24, 13

    View full-size slide

  49. Conservative Update
    Modules won't be upgraded
    unless it is required, or manually updated.
    Wednesday, July 24, 13

    View full-size slide

  50. Single-file, VCS friendly
    You can add cpanfile.snapshot to git
    update whenever you update modules
    "Dependencies are part of your app."
    Wednesday, July 24, 13

    View full-size slide

  51. Safe and easy rollback
    revert the lock file and redeploy
    Wednesday, July 24, 13

    View full-size slide

  52. DEMO
    Wednesday, July 24, 13

    View full-size slide

  53. Deployment
    with Carton
    Wednesday, July 24, 13

    View full-size slide

  54.  @local>  carton  install
     @local>  git  commit  cpanfile.snapshot
     @local>  git  push
    @remote>  carton  install  -­‐-­‐deployment
    @remote>  carton  exec  plackup  ...
    Wednesday, July 24, 13

    View full-size slide

  55. Example:
    github.com/miyagawa/cpanmetadb-perl
    capistrano, Server::Starter,
    carton, plackup (twiggy)
    Wednesday, July 24, 13

    View full-size slide

  56. PaaS/Cloud
    github.com/miyagawa/heroku-buildpack-perl
    Wednesday, July 24, 13

    View full-size slide

  57. Wednesday, July 24, 13

    View full-size slide

  58. http://weblog.bulknews.net
    Wednesday, July 24, 13

    View full-size slide

  59. Support to come!
    Dokku, DotCloud, Travis CI,
    Cloud Foundry etc.
    Wednesday, July 24, 13

    View full-size slide

  60. carton 1.0
    later this week
    Wednesday, July 24, 13

    View full-size slide

  61. >  cpanm  -­‐-­‐dev  Carton
    Wednesday, July 24, 13

    View full-size slide

  62. Towards 1.1
    • Inject patched versions (DarkPAN)
    • Install from github
    • bootstrap with fatpack
    Wednesday, July 24, 13

    View full-size slide

  63. github.com/miyagawa/carton
    irc.perl.org #carton
    Wednesday, July 24, 13

    View full-size slide

  64. speakerdeck.com
    /miyagawa
    Wednesday, July 24, 13

    View full-size slide

  65. Questions?
    Wednesday, July 24, 13

    View full-size slide