3

I tried doing the following. First, I install a relocatable perl, e.g.:

% perlbrew -Duserelocatableinc -j4 -n --as perl-5.28.1-fresh_src 5.28.1

Then, whenever I need a new throw-away fresh installation of perl to test things out, I do:

% cp -la ~/perl5/perlbrew/perls/perl-5.28.1-fresh{_src,1}
% perlbrew switch 5.28.1-fresh1

(then would later create fresh2, fresh3 and so on as needed; and when I want to throw these away I just rm -rf ~/perl5/perlbrew/perls/*fresh1 and so on.)

However, something (cpanm? EUMM?) is still confused. Scripts installed from CPAN still has the original perl path (in this case, /home/USER/perl5/perlbrew/perls/perl-5.28.1-fresh_src/bin) in their shebang line.

Any hint to the problem above, or an alternative way to quickly create a fresh throw-away perl installation is appreciated. Also, would the -l (--link) option of cp in the above command cause issue (other than perllocal.pod being appended and will contain installation records of perl installations, which is fine for me)?

Perl Ancar
  • 580
  • 3
  • 10

1 Answers1

2

It's not quite the same, but I find docker works if I'm needing a clean install for certain testing scenarios - build up a base image and a clean perl install, fire up the container and run 'whatever'.

You'll need root access and be able to install packages (e.g. docker) so it's not going to be suitable for every use case.

https://buildlogs.centos.org/centos/7/docker/ has a base image you can use to build a 'clean' CentOS (or use whatever OS you prefer frankly - most have container versions)

FROM scratch
ADD CentOS-7-20140625-x86_64-docker_01.img.tar.xz
LABEL name="CentOS Base Image"
CMD ["/bin/bash"]

In the working directory:

docker build -t mycentos . 

This will give you a very basic image:

Then your perl dockerfile:

FROM mycentos 
COPY local.repo /etc/yum.repos.d/local.repo
RUN yum clean all
RUN yum install --nogpgcheck -y make gcc tar
ADD perl-5.28.1.tar.gz /build/
RUN cd /build/perl-5.28.1 && ./Configure -de
RUN cd /build/perl-5.28.1 && make && make test && make install
COPY MyConfig.pm /root/.cpan/CPAN/MyConfig.pm
RUN cpan install Bundle::CPAN
CMD ["/bin/bash"]

You'll be able to spin this up, with e.g. docker run and invoke a script using /usr/local/bin/perl.

It's not quite what you asked for, but your base image can be started and discarded as you wish - you can maintain image for a few different OS and perl combinations too.

Sobrique
  • 52,974
  • 7
  • 60
  • 101
  • Thanks. Not what I expected, but at least I know it's an option. BTW, how long does it typically take to create an instance? – Perl Ancar Mar 27 '19 at 07:39
  • 1
    Once you've built the image? Seconds. `docker run -it perl` will get you a shell with your 'clean perl' almost instantly. You might need to copy 'whatever' you want to test into there. The build naturally is 'compiling perl' sort of timescale, so can take a while. However, Docker uses intermediate stages, so you don't need a full rebuild for every tweak. (but as a result, you should probably put the things that change least, first). Which means you can have a penultimate line of `COPY script_to_test` and it's still pretty quick. – Sobrique Mar 27 '19 at 09:42
  • OK, color me intrigued. Will add a todo item to try out docker. Thanks. – Perl Ancar Mar 27 '19 at 14:10