Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

carton install installs dependencies outside @INC #219

Open
pnull opened this issue Dec 24, 2016 · 3 comments
Open

carton install installs dependencies outside @INC #219

pnull opened this issue Dec 24, 2016 · 3 comments

Comments

@pnull
Copy link

pnull commented Dec 24, 2016

Problem

  1. I've created a small Dockerfile that uses perl:5 as the source image. Its attached below.
  2. A RUN task in the Dockerfile calls carton install - which finishes without an error. cpanfile also attached.
  3. The actual perl script is started using Dockers CMD.
  4. The perl script dies because it can't find DateTime in @INC - but carton pretended to install it.

Here's the actual output when after carton exec ./bin/fetcher.pl:

Can't locate DateTime.pm in @INC (you may need to install the DateTime module) (@INC contains: ./lib ../lib /usr/src/fetcher/local/lib/perl5 /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl .) at ./bin/fetcher.pl line 12.
BEGIN failed--compilation aborted at ./bin/fetcher.pl line 12.

As you can see, Carton added /usr/src/fetcher/local/lib/perl5 to the list of include paths. That seems correct - the modules seem to be installed here:

root@5871e7e089ab:/usr/src/fetcher# ls /usr/src/fetcher/local/lib/perl5
B      DateTime  Dist	 Eval	    File  HTTP	LWP	Log  Module   Net      Params  Role    Specio.pm  TODO.pod  Try  URI.pm  lwpcook.pod  namespace	Class  Devel	 Encode  Exception  HTML  IO	LWP.pm	MRO  Mozilla  Package  REST    Specio  Sub	  Test	    URI  WWW	 lwptut.pod   x86_64-linux

But there's no DateTime.pm .. The file seems to be installed in the x86_64-linux subdirectory:

root@5871e7e089ab:/usr/src/fetcher# ls /usr/src/fetcher/local/lib/perl5/x86_64-linux/
DateTime  DateTime.pm  HTML  List  Net	Package  Scalar  Sub  Variable	auto  perllocal.pod

I have no idea, why this happens or why this path isn't added to @INC ?!?

Dockerfile

FROM perl:5
RUN cpanm Carton
WORKDIR /usr/src/fetcher
COPY cpanfile* /usr/src/fetcher/
COPY bin /usr/src/fetcher/bin
COPY lib /usr/src/fetcher/lib
RUN carton install

# Run the app
CMD carton exec ./bin/fetcher.pl

cpanfile

requires 'Log::Log4perl';
requires 'DateTime';
requires 'URI::Encode';
requires 'WWW::Mechanize';
requires 'WWW::Mechanize::Sleepy';
requires 'REST::Client';
@skaji
Copy link

skaji commented Dec 25, 2016

I could not reproduce your issue https://github.com/skaji/carton-issue219
The arch directory /usr/src/fetcher/local/lib/perl5/x86_64-linux must be in @INC by PERL5LIB.

What is the output of carton exec perl -V?

@skaji
Copy link

skaji commented Dec 25, 2016

Oh, I see.
Perhaps the shebang in bin/fetcher.pl is /usr/bin/perl, right? Then you executed the wrong perl.

@melo
Copy link
Contributor

melo commented Dec 25, 2016

Use #!/usr/bin/env perl on your scripts, this will find the correct perl.

Regarding your docker and carton setup, an alternative (shameless plug): I keep a perl5-based image that takes care of all of details to install a perl application that uses Carton. It also includes hooks to install extra packages with apt-get (perl5 image is based on Ubuntu) before carton install.

For example, your image copies cpanfile* first but then copies bin and lib before carton install. This will skip a great feature of docker build, layer caching. You should copy cpanfile*, run carton install, and then copy everything else you need.

If you do it this way, the carton install step, which usually takes quite some time, will be cached between docker build's as long as your cpanfile* are untouched. You can tweak bin and lib, rebuild, and carton install layer will be reused. A major speed up on docker build's.

You can find the image at https://hub.docker.com/r/melopt/perl-carton-base/ . Even if you don't want to use it, it shows a very docker layer effective setup for Carton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants