Managing CPAN dependencies with Carton

Managing CPAN dependencies with Carton

at Nordic Perl Workshop 2013

B2d653d5d663e750a2cd57bfbc9b727f?s=128

Tatsuhiko Miyagawa

November 23, 2013
Tweet

Transcript

  1. Carton managing CPAN dependencies Tatsuhiko Miyagawa @miyagawa Nordic Perl Workshop

    2013 Saturday, November 23, 13
  2. Me • Tatsuhiko Miyagawa • Lives in San Francisco •

    {github,twitter,CPAN}/miyagawa Saturday, November 23, 13
  3. Thank You! Saturday, November 23, 13

  4. Managing CPAN Dependencies Saturday, November 23, 13

  5. How many CPAN modules your app depends on? Saturday, November

    23, 13
  6. When is the last time upgrading a CPAN module broke

    your app? Saturday, November 23, 13
  7. Case Study: Web App Development Saturday, November 23, 13

  8. You’re writing a new web app using as many CPAN

    modules. Saturday, November 23, 13
  9. Get them from CPAN, install on your machine. Saturday, November

    23, 13
  10. john@local>  cpanm  Web::Framework installed  LWP-­‐5.912 installed  Plack-­‐0.9980 installed  Web-­‐Framework-­‐1.10 Saturday,

    November 23, 13
  11. Test it... Saturday, November 23, 13

  12. Works? Ship it! Saturday, November 23, 13

  13. What if ... Saturday, November 23, 13

  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 16th: Deploy to the production Saturday, November 23, 13
  15. • 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 Saturday, November 23, 13
  16. root@prod>  cpanm  Web::Framework installed  LWP-­‐5.912 installed  Plack-­‐0.9980 installed  Web-­‐Framework-­‐1.20 Saturday,

    November 23, 13
  17. Web::Framework 1.2 API changes! Saturday, November 23, 13

  18. Saturday, November 23, 13

  19. Saturday, November 23, 13

  20. “Upgrading CPAN modules broke my app” Saturday, November 23, 13

  21. Dependencies are part of your app. Saturday, November 23, 13

  22. a solution cpanm 1.6 Saturday, November 23, 13

  23. >  cpanm  Web::Framework@1.10 installed  Web-­‐Framework-­‐1.10 Saturday, November 23, 13

  24. >  cpanm  Web::Framework~">=  1.0,  <  1.2" installed  Web-­‐Framework-­‐1.19 Saturday, November

    23, 13
  25. ♥ MetaCPAN Saturday, November 23, 13

  26. a solution cpanfile + cpanm 1.6 Saturday, November 23, 13

  27. >  cat  cpanfile requires  'Web::Framework',  '==  1.10'; >  cpanm  -­‐-­‐installdeps

     . installed  Web-­‐Framework-­‐1.10 Saturday, November 23, 13
  28. cpanfile DSL to describe prereqs Saturday, November 23, 13

  29. 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'; }; Saturday, November 23, 13
  30. inspired by: gemfile(5) Saturday, November 23, 13

  31. Compatible to: Module::Install(::DSL) Saturday, November 23, 13

  32. Converted to: CPAN::Meta::Prereqs Saturday, November 23, 13

  33. Toolset Module::CPANfile Module::Install::CPANfile Dist::Zilla plugins Saturday, November 23, 13

  34. Supported by dzil, Milla & cpanm 1.6 Saturday, November 23,

    13
  35. cpanfile + cpanm • Simple • Yet powerful and flexible

    way to describe dependencies and version requirements • Version control cpanfile Saturday, November 23, 13
  36. caveats • Locking each dependency with specific version is tedious

    work • Can only lock direct dependencies • MetaCPAN as SPOF • No easy/reliable way to fallback Saturday, November 23, 13
  37. Many other solutions Needs servers, Needs databases Too simple, Too

    complicated, etc. Saturday, November 23, 13
  38. the new Solution Saturday, November 23, 13

  39. Carton https://github.com/miyagawa/carton Saturday, November 23, 13

  40. Inspired by... Saturday, November 23, 13

  41. Saturday, November 23, 13

  42. Basic idea: Describe CPAN dependencies snapshot tarball pathnames Saturday, November

    23, 13
  43. Built on top of: cpanfile + cpanm 1.7 Saturday, November

    23, 13
  44. • 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 Saturday, November 23, 13
  45. Local perl environment Using local::lib and cpanm -L Each app

    has an isolated local library path Saturday, November 23, 13
  46. Fast and safe install Saves MYMETA.json and install meta info

    Saturday, November 23, 13
  47. Dep tree analysis Rebuild the dependency tree from snapshot Checks

    if anything is missing/superfluous Saturday, November 23, 13
  48. Freezing versions Versions are saved in snapshots including dependencies Saturday,

    November 23, 13
  49. Easy Redeployment Reinstall exactly the same set of modules on

    another prod/development machines. Saturday, November 23, 13
  50. Conservative Update Modules won't be upgraded unless it is required,

    or manually updated. Saturday, November 23, 13
  51. Single-file, VCS friendly You can add cpanfile.snapshot to git update

    whenever you update modules "Dependencies are part of your app." Saturday, November 23, 13
  52. Safe and easy rollback revert the lock file and redeploy

    Saturday, November 23, 13
  53. DEMO Saturday, November 23, 13

  54. Deployment with Carton Saturday, November 23, 13

  55.  @local>  carton  install  @local>  git  commit  cpanfile.snapshot  @local>  git  push

    @remote>  carton  install  -­‐-­‐deployment @remote>  carton  exec  plackup  ... Saturday, November 23, 13
  56. Example: github.com/miyagawa/cpanmetadb-perl capistrano, Server::Starter, carton, plackup (twiggy) Saturday, November 23,

    13
  57. PaaS/Cloud github.com/miyagawa/heroku-buildpack-perl Saturday, November 23, 13

  58. Saturday, November 23, 13

  59. http://weblog.bulknews.net Saturday, November 23, 13

  60. Support to come! Dokku, DotCloud, Travis CI, Cloud Foundry etc.

    Saturday, November 23, 13
  61. carton 1.0 on CPAN Saturday, November 23, 13

  62. >  cpanm  Carton Saturday, November 23, 13

  63. Preview: next major releases Saturday, November 23, 13

  64. cpanm 1.8 git (+ any URL) support in index Saturday,

    November 23, 13
  65. cpanfile 1.1 git syntax support Saturday, November 23, 13

  66. requires  'Plack',  '1.0000',    git  =>  'git://github.com/plack/Plack.git',    ref  =>

     'devel'; carton 1.1 Saturday, November 23, 13
  67. requires  'Plack',  '1.0011',    dist  =>  'MIYAGAWA/Plack-­‐1.0011.tar.gz'; carton 1.1 Saturday,

    November 23, 13
  68. requires  'Plack',  '1.0011',    dist  =>  'http://darkpan/Plack-­‐1.tar.gz'; carton 1.1 Saturday,

    November 23, 13
  69. (demo) Saturday, November 23, 13

  70. cpanm 1.8 • Rewrite internals • Backend API • Plugin

    support • CPAN Testers support (via plugins) Saturday, November 23, 13
  71. carton 1.1 • binstubs • configure args/hints support • safe

    exec on development • remember options (--path etc.) Saturday, November 23, 13
  72. github.com/miyagawa/carton irc.perl.org #carton Saturday, November 23, 13

  73. speakerdeck.com /miyagawa Saturday, November 23, 13

  74. gum.co/BmXz Saturday, November 23, 13

  75. Questions? Saturday, November 23, 13