Tatsuhiko Miyagawa's Blog


September 25, 2013

Link: miyagawa/cpan-module-bootstrap

Creates a shell script and cpanm bundle to install modules on a remote machine without cpanm installed and no network connection.Another YAPC::Asia is over, and now Carton gets the big traction. Carton solves the problem of “CPAN breaking my app”, and installing modules on a deployment host is easier and more stable then ever.

Now there is one remaining piece of puzzle. How do you install Carton in the first place on the remote target?

The most obvious and easiest answer is to install it like a regular module, with just cpanm Carton into site_perl or a dedicated local::lib. It works nicely, and even though Carton has a fair amount of dependencies, they will never interfere with the dependencies of your app — Carton uses Moo, and your app can use Moo, even a different version of that.

There’s some possibility where a network install from CPAN is not allowed on a production or stage machine. That’s what carton bundle is for. And beginning the recent version, it creates a fatpacked executable inside vendor/bin. It’s like a 2MB of perl script that contains everything you need to run Carton.

FatPacker however is kind of a hack — yet a really cool hack. It works around the absence of installed files database by looking at packlists, and it doesn’t work reliably with XS modules.

If fatpacked vendor/bin/carton works for you, great. If it doesn’t, we should think about another way to do this.

Luckily there’s quite a few tools that does it. One is App::cpackage — bundles the tarball with cpanm’s options and creates a single file installer. It uses a little dated option for cpanm to do this, but it will probably work for you anyway.

And now I created another one called cpan-module-bootstrap. Besides it uses OrePAN2 to recreate a mirror, and that it creates a shell script (instead of a perl script) to bootstrap on a remote, it’s basically the same with cpackage.

I just made it for an alternative for cpackage (and carton fatpack) to bootstrap any CPAN module on a remote machine. To use it,

git clone https://github.com/miyagawa/cpan-module-bootstrap.git
cd ./cpan-module-bootstrap
./setup Cartonand you’ll get bundle/ directory. Copy that to a remote machine, then run ./bootstrap within there, and you’ll get Carton installed on a remote machine that doesn’t have cpanm installed, or has no network connection.