1

I want to perlbrew on docker building phase. I successfully install a perl but can't perlbrew switch to it so cpanm installs the module into wrong place.

The Dockerfile is as follows.

FROM centos:centos7
SHELL ["/bin/bash", "-c"]
RUN yum -y update
RUN yum -y groupinstall "Development Tools"
RUN yum -y install iproute cpan gcc perl-ExtUtils-Manifest
RUN curl -L https://install.perlbrew.pl | SHELL=/bin/bash bash
RUN echo "source /root/perl5/perlbrew/etc/bashrc" >> /root/.bashrc
RUN \source ~/perl5/perlbrew/etc/bashrc
RUN /root/perl5/perlbrew/bin/perlbrew install --notest --noman perl-5.30.0
RUN /root/perl5/perlbrew/bin/perlbrew install-cpanm
RUN /root/perl5/perlbrew/bin/perlbrew switch perl-5.30.0
RUN /root/perl5/perlbrew/bin/cpanm File::Find::Rule

CMD /sbin/init

It fails on perlbrew switch with errors.

Step 6/13 : RUN curl -L https://install.perlbrew.pl | SHELL=/bin/bash bash
 ---> Running in 2d003bbacf0e
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   170  100   170    0     0    189      0 --:--:-- --:--:-- --:--:--   189
100  1548  100  1548    0     0   1261      0  0:00:01  0:00:01 --:--:--     0

## Download the latest perlbrew

## Installing perlbrew
Using Perl </usr/bin/perl>
perlbrew is installed: ~/perl5/perlbrew/bin/perlbrew

perlbrew root (~/perl5/perlbrew) is initialized.

Append the following piece of code to the end of your ~/.bash_profile and start a
new shell, perlbrew should be up and fully functional from there:

    source ~/perl5/perlbrew/etc/bashrc

Simply run `perlbrew` for usage details.

Happy brewing!

## Installing patchperl

## Done.
Removing intermediate container 2d003bbacf0e
 ---> cf3fe0430858
Step 7/13 : RUN echo "source /root/perl5/perlbrew/etc/bashrc" >> /root/.bashrc
 ---> Running in 835a04a14f9f
Removing intermediate container 835a04a14f9f
 ---> d06c29928706
Step 8/13 : RUN \source ~/perl5/perlbrew/etc/bashrc
 ---> Running in e655fe87bc0c
Removing intermediate container e655fe87bc0c
 ---> fbc2aa1dcbb7
Step 9/13 : RUN /root/perl5/perlbrew/bin/perlbrew install --notest --noman perl-5.30.0
 ---> Running in 1bb4851a6e5d
Fetching perl 5.30.0 as /root/perl5/perlbrew/dists/perl-5.30.0.tar.gz
Download http://www.cpan.org/src/5.0/perl-5.30.0.tar.gz to /root/perl5/perlbrew/dists/perl-5.30.0.tar.gz
Installing /root/perl5/perlbrew/build/perl-5.30.0/perl-5.30.0 into ~/perl5/perlbrew/perls/perl-5.30.0

This could take a while. You can run the following command on another shell to track the status:

  tail -f ~/perl5/perlbrew/build.perl-5.30.0.log

perl-5.30.0 is successfully installed.
Removing intermediate container 1bb4851a6e5d
 ---> 5c2f139f28c4
Step 10/13 : RUN /root/perl5/perlbrew/bin/perlbrew install-cpanm
 ---> Running in c8650ea79674

cpanm is installed to

    /root/perl5/perlbrew/bin/cpanm

Removing intermediate container c8650ea79674
 ---> c3e92218cf8f
Step 11/13 : RUN /root/perl5/perlbrew/bin/perlbrew switch perl-5.30.0
 ---> Running in 551369fc6a61
Use of uninitialized value $shell in pattern match (m//) at /root/perl5/perlbrew/bin/perlbrew line 2445.
Use of uninitialized value $shell in concatenation (.) or string at /root/perl5/perlbrew/bin/perlbrew line 2485.

A sub-shell is launched with perl-5.30.0 as the activated perl. Run 'exit' to finish it.

HOSTNAME=551369fc6a61
SHELL=
PATH=/root/perl5/perlbrew/bin:/root/perl5/perlbrew/perls/perl-5.30.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
PWD=/
HOME=/root
SHLVL=2
PERLBREW_PERL=perl-5.30.0
PERLBREW_VERSION=0.86
MANPATH=/root/perl5/perlbrew/perls/perl-5.30.0/man:
PERL_LOCAL_LIB_ROOT=
PERL5LIB=
PERLBREW_MANPATH=/root/perl5/perlbrew/perls/perl-5.30.0/man
PERLBREW_LIB=
PERLBREW_SKIP_INIT=1
PERLBREW_PATH=/root/perl5/perlbrew/bin:/root/perl5/perlbrew/perls/perl-5.30.0/bin
PERLBREW_ROOT=/root/perl5/perlbrew
Removing intermediate container 551369fc6a61
 ---> b76db56bd82f
Step 12/13 : RUN /root/perl5/perlbrew/bin/cpanm File::Find::Rule
 ---> Running in 5574895c6069
--> Working on File::Find::Rule
Fetching http://www.cpan.org/authors/id/R/RC/RCLAMP/File-Find-Rule-0.34.tar.gz ... OK
Configuring File-Find-Rule-0.34 ... OK
==> Found dependencies: Test::More, Text::Glob, Number::Compare
--> Working on Test::More
Fetching http://www.cpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302167.tar.gz ... OK
Configuring Test-Simple-1.302167 ... OK
Building and testing Test-Simple-1.302167 ... OK
Successfully installed Test-Simple-1.302167
--> Working on Text::Glob
Fetching http://www.cpan.org/authors/id/R/RC/RCLAMP/Text-Glob-0.11.tar.gz ... OK
Configuring Text-Glob-0.11 ... OK
Building and testing Text-Glob-0.11 ... OK
Successfully installed Text-Glob-0.11
--> Working on Number::Compare
Fetching http://www.cpan.org/authors/id/R/RC/RCLAMP/Number-Compare-0.03.tar.gz ... OK
Configuring Number-Compare-0.03 ... OK
Building and testing Number-Compare-0.03 ... OK
Successfully installed Number-Compare-0.03
Building and testing File-Find-Rule-0.34 ... OK
Successfully installed File-Find-Rule-0.34
4 distributions installed
Removing intermediate container 5574895c6069
 ---> b7cbd8213dcc
Step 13/13 : CMD /sbin/init
 ---> Running in 3180df4e4deb
Removing intermediate container 3180df4e4deb
 ---> b6ebc0ca82a5
Successfully built b6ebc0ca82a5

I also tried to switch/use perl-5.28.2 on centos7/ubuntu and results the same. It fails only on building stage and I can perlbrew switch successfully by attaching to the container after building.

The direct cause of this seems to be the lack of shell environment variable in the sub shell forked in perlbrew swich/use.

Use of uninitialized value $shell in pattern match (m//) at /root/perl5/perlbrew/bin/perlbrew line 2445.

How can I solve the problem?

My environment is

App::Perlbrew 0.86
Docker version 19.03.1, build 74b1e89
  • Successfully built 3d1ea879e226 ? – LinPy Aug 26 '19 at 12:03
  • why not using the official docker image for perl? it'd be a simple `docker pull perl:5.30` – Stefano Aug 26 '19 at 12:10
  • Try setting the `SHELL` variable explicitly in `Dockerfile` like this: `RUN curl -L https://install.perlbrew.pl | SHELL=/bin/bash bash` – Håkon Hægland Aug 26 '19 at 16:21
  • uh, the output doesn't match the script. The output says Step 9/11 is `Step 9/11 : RUN /root/perl5/perlbrew/bin/perlbrew install --notest --noman perl-5.30.0` is followed by `RUN /root/perl5/perlbrew/bin/perlbrew use perl-5.30.0`, but you claim it's followed by `RUN /root/perl5/perlbrew/bin/perlbrew install-cpanm` and that the command that did run is nowhere in the script. – ikegami Aug 26 '19 at 22:00
  • @HåkonHægland Thanks. I tried what your saying and there was not change. I updated the question. – user3203239 Aug 27 '19 at 01:50
  • @ikegami Thanks for pointing it. Now I'm sure the code and the log is corresponding. – user3203239 Aug 27 '19 at 01:52
  • @Stefano There is some reasons but I'll also consider your suggestion. Thanks. – user3203239 Aug 27 '19 at 02:22
  • Why are you trying to run `perlbrew switch` in a non-interactive shell? I don't understand what you're trying to achieve. – melpomene Aug 27 '19 at 04:45
  • @melpomene I'd like to `cpanm` some modules after switch. – user3203239 Aug 27 '19 at 05:03
  • @user3203239 If you look at the output from `cpanm` it says `Successfully installed File-Find-Rule-0.34` so it seems to be working, right? – Håkon Hægland Aug 27 '19 at 07:03
  • Sorry for my duplicate question. My issue was solved by reading past Q&A and my script now is `RUN /root/perl5/perlbrew/perls/perl-5.28.2/bin/perl -S /root/perl5/perlbrew/bin/cpanm File::Find::Rule` without switch. Thank you. – user3203239 Aug 27 '19 at 08:04

0 Answers0