Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up my Dockerfile to use cpanm to install a specific version of a Perl module?

Within my Dockerfile, I am setting up the Perl modules that will be installed when run, like so:

RUN ["cpanm", "Carp", "Carp::Heavy", "Class::Data::Inheritable"]

However, for one module, I need a specific version of a module, not the latest one. How can I specify that version in the above line?

I've been searching online for hours, and haven't turned up anything useful yet.

like image 340
Mik Avatar asked Jul 26 '16 19:07

Mik


2 Answers

Instead of specifying a module name, specify a URL. Eg, instead of Class::Data::Inheritable, use https://cpan.metacpan.org/authors/id/T/TM/TMTM/Class-Data-Inheritable-0.06.tar.gz

You can find the applicable URL by going to the module page on metacpan, selecting the version you want, and copying the download link.

PS: You might want to also set PERL_CPANM_OPT=--from https://cpan.metacpan.org/ in the environment so cpanm only downloads using HTTPS.

like image 188
Sinan Ünür Avatar answered Oct 30 '22 17:10

Sinan Ünür


For anyone who's searching for this same answer in the future, another option can be found here in the documentation for cpanm:

cpanm [email protected]

If you have a long list of modules, consider feeding a cpanfile into cpanm rather than listing them all in the Dockerfile.

The easiest way to specify a particular version number for a module in a cpanfile is like this:

requires 'Text::ParseWords', '==3.1';

The syntax for requesting the latest version of a module is this:

requires 'Text::ParseWords';

Requesting a minimum version: (note the lack of '==')

requires 'Text::ParseWords', '3.1';

The syntax for requesting specific versions in other ways is fairly well-documented here.

Another great write-up of the use of cpanm and a cpanfile can be found in Installation of cpan modules by cpanm and cpanfile.

like image 23
Mik Avatar answered Oct 30 '22 19:10

Mik