Showing posts with label cpanm. Show all posts
Showing posts with label cpanm. Show all posts

Cpanm with local library installation

One of the issue I kept facing when developing local Perl modules installation and dependency management.

$ cpanm -nq --installdeps --with-develop --with-recommends .
!
! Can't write to /usr/local/share/perl/5.26.0 and /usr/local/bin: Installing modules
! to /home/foobar/perl5
! To turn off this warning, you have to do one of the following:
!  - run me as a root or with --sudo option (to install to 
!    /usr/local/share/perl/5.26.0 and /usr/local/bin)
!  - Configure local::lib in your existing shell to set PERL_MM_OPT etc.
!  - Install local::lib by running the following commands
!
!    cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
!

Either we do this manually everytime.
$ cpanm --local-lib=~/perl5 local::lib 
$ eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
local::lib is up to date. (2.000024)

Or setup your local environment for once through local::lib.
$ PATH="$PATH:~/perl5/bin"

Additional directories for Perl library.
$ export PERL5LIB=~/perl5/lib/perl5

Options for Module::Build.
$ export PERL_MB_OPT="--install_base '$HOME/perl5'"

Options for Module::MakeMaker.
$ export PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"

$ curl -L http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib

Add this to your `.profile` as well.
$ eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)
$ source ~/.profile # reload

Or just use Perl's Docker container image.

Or just use Carton and set everything to local folder.

Debugging Dockerfile

While building Docker image through Dockerfile, I've encountered an error in one of the build step, shown below. It seemed that that one of the Perl's module failed to install due to some unknown reason.
$ docker build -t ang:dist-zilla .

Sending build context to Docker daemon 3.072 kB
Step 1 : FROM perl:latest
 ---> a9d757d1a33b
Step 2 : RUN cpanm install Term::ReadKey
 ---> Running in 78760f841b26
 ---> Working on install
......
Building and testing TermReadKey-2.33 ... ! Installing Term::ReadKey failed. 
See /root/.cpanm/work/1473691870.7/build.log for details. Retry with --force to force install it.
......

Since there is an error, the particular layer of image was not created. Hence, there is no way for me to debug and trace the error. Fortunately, you can force it through the build by marking it to be a success build. The changes is minor, you just need to append an OR condition (also known as Short-circuit evaluation) as shown.
RUN cpanm install Term::ReadKey || true

Rebuild the image. Regardless the error, we have successfully create a layer.
$ docker build -t ang:dist-zilla .
......
Step 2 : RUN cpanm install Term::ReadKey || true
 ---> Running in f3fa83db0ae9
......
Building and testing TermReadKey-2.33 ... ! 
Installing Term::ReadKey failed. See /root/.cpanm/work/1473691397.7/build.log for details. 
Retry with --force to force install it.
FAIL
1 distribution installed
 ---> 62e2b1bd2c61
Removing intermediate container f3fa83db0ae9
Successfully built 62e2b1bd2c61

Log in to the particular snapshot or layer before we troubleshoot the issue.
$ docker run --rm -it 62e2b1bd2c61 bash -il
[email protected]:~#

Checking the build log.
[email protected]:~# tail .cpanm/work/1473691397.7/build.log -n 25
  
chmod 755 blib/arch/auto/Term/ReadKey/ReadKey.so
"/usr/local/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- 
ReadKey.bs blib/arch/auto/Term/ReadKey/ReadKey.bs 644
Running Mkbootstrap for Term::ReadKey ()
chmod 644 "ReadKey.bs"
PERL_DL_NONLAZY=1 "/usr/local/bin/perl" 
"-MExtUtils::Command::MM" "-MTest::Harness" "-e" 
"undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/01_basic.t ............... ok
# Looks like you planned 7 tests but ran 1.
t/02_terminal_functions.t .. 
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 6/7 subtests 
        (less 1 skipped subtest: 0 okay)

Test Summary Report
-------------------
t/02_terminal_functions.t (Wstat: 65280 Tests: 1 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 7 tests but ran 1.
Files=2, Tests=2,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.04 cusr  0.00 csys =  0.06 CPU)
Result: FAIL
Failed 1/2 test programs. 0/2 subtests failed.
Makefile:1029: recipe for target 'test_dynamic' failed
make: *** [test_dynamic] Error 255
-> FAIL Installing Term::ReadKey failed. 
See /root/.cpanm/work/1473691397.7/build.log for details. Retry with --force to force install it.
1 distribution installed

Googling result indicates that Term::ReadKey module have issue with one of the unit test where interactive shell is not found. Building Docker image does not needs interactive shell available.

The workaround is to downgrade and install the previous working version.
RUN cpanm install Term::[email protected]