3

I have a working UBUNTU image with this Dockerfile:

FROM perl:5.14

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y libgd-dev

RUN perl -MCPAN -e 'install (Try::Tiny)'
RUN perl -MCPAN -e 'install (Kafka::Connection)'
RUN perl -MCPAN -e 'install (YAML)'
RUN perl -MCPAN -e 'install (GD::Simple)'
RUN perl -MCPAN -e 'install (GD::Graph)'
RUN perl -MCPAN -e 'install (JSON)'
RUN perl -MCPAN -e 'install (JSON::MaybeXS)'
RUN perl -MCPAN -e 'install (HTTP::Request)'
RUN perl -MCPAN -e 'install (HTTP::Response)'
RUN perl -MCPAN -e 'install (HTTP::Daemon)'

COPY run.sh /run.sh

RUN chmod +x "/run.sh"

RUN mkdir -p /code_path

WORKDIR /code_path

CMD ["/run.sh"]

I'n trying to get a slimmer alpine version like this:

FROM alpine:3.10.3

## alpine curl and wget aren't fully compatible, so we install them
## here. gnupg is needed for Module::Signature.
RUN apk update && apk upgrade
RUN apk add curl tar make gcc build-base wget gnupg

RUN mkdir -p /usr/src/perl

WORKDIR /usr/src/perl

## from perl; `true make test_harness` because 3 tests fail
## some flags from http://git.alpinelinux.org/cgit/aports/tree/main/perl/APKBUILD?id=19b23f225d6e4f25330e13144c7bf6c01e624656
RUN curl -SLO https://www.cpan.org/src/5.0/perl-5.30.0.tar.gz \
    && echo 'aa5620fb5a4ca125257ae3f8a7e5d05269388856 *perl-5.30.0.tar.gz' | sha1sum -c - \
    && tar --strip-components=1 -xzf perl-5.30.0.tar.gz -C /usr/src/perl \
    && rm perl-5.30.0.tar.gz \
    && ./Configure -des \
    -Duse64bitall \
    -Dcccdlflags='-fPIC' \
    -Dcccdlflags='-fPIC' \
    -Dccdlflags='-rdynamic' \
    -Dlocincpth=' ' \
    -Duselargefiles \
    -Dusethreads \
    -Duseshrplib \
    -Dd_semctl_semun \
    -Dusenm \
    && make libperl.so \
    && make -j$(nproc) \
    && true TEST_JOBS=$(nproc) make test_harness \
    && make install \
    && curl -LO https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm \
    && chmod +x cpanm \
    && ./cpanm App::cpanminus \
    && rm -fr ./cpanm /root/.cpanm /usr/src/perl




## from tianon/perl
ENV PERL_CPANM_OPT --verbose --mirror https://cpan.metacpan.org --mirror-only
RUN cpanm Digest::SHA Module::Signature && rm -rf ~/.cpanm
ENV PERL_CPANM_OPT $PERL_CPANM_OPT --verify

RUN perl -MCPAN -e 'install (Try::Tiny)'
RUN perl -MCPAN -e 'install (Kafka::Connection)'
RUN perl -MCPAN -e 'install (YAML)'
RUN perl -MCPAN -e 'install (GD::Simple)'
RUN perl -MCPAN -e 'install (GD::Graph)'
RUN perl -MCPAN -e 'install (JSON)'
RUN perl -MCPAN -e 'install (JSON::MaybeXS)'
RUN perl -MCPAN -e 'install (HTTP::Request)'
RUN perl -MCPAN -e 'install (HTTP::Response)'
RUN perl -MCPAN -e 'install (HTTP::Daemon)'

COPY run.sh /run.sh

RUN chmod +x "/run.sh"

RUN mkdir -p /code_path

WORKDIR /code_path

CMD ["/run.sh"]

I keep getting this error

OS.c:18:10: fatal error: obstack.h: No such file or directory
 #include <obstack.h>    /* glibc's handy obstacks */

how do I get all the dependencies for Kafka on the image?

daxim
  • 39,270
  • 4
  • 65
  • 132
Rubber Duck
  • 3,673
  • 3
  • 40
  • 59
  • I undid the last change to the question because it is a completely different problem now and the existing answers do not fit the question anymore. Please [open a new question](https://stackoverflow.com/questions/ask) for the Test-Block problem. Your text is still available: [revision 2](https://stackoverflow.com/revisions/59127135/2) / [source](https://stackoverflow.com/revisions/3d519878-47c8-48f1-97d6-b6ba776d0ccf/view-source) – daxim Dec 02 '19 at 08:14
  • @daxim The question was about installing perl Kafka on alpine. your answer ultimately helped me very much!. thanks! – Rubber Duck Dec 02 '19 at 08:18

3 Answers3

2

Alpine does not ship glibc, and obstack.h is not part of musl-dev.

Try alpine-pkg-glibc.

daxim
  • 39,270
  • 4
  • 65
  • 132
  • I tried your suggestion the error receded but I couldn't install the dependancies for Kafka. the error has to do with failing cpan install Test::Block – Rubber Duck Dec 02 '19 at 06:26
2

You could try grabbing obstack.h on Alpine by installing the newly available musl-obstack-dev package of the edge/testing repository:

apk add musl-obstack-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

Note that edge/testing packages are cutting edge and are considered experimental (as opposed to main stable package).

While Alpine (musl libc) is generally not glibc compatible, it does provide lightweight glibc compatibility in terms of convenience headers and libraries, particularly via the libc6-compat package, and packages as the aforementioned.

Tip: use Alpine's excellent package search for locating missing files. Alpine is vivid and active and sees new packages regularly. Most of the time you'll find that missing files are available in apk packages. Results for obstack.h package contents search:
https://pkgs.alpinelinux.org/contents?file=obstack.h&path=&name=&branch=edge

valiano
  • 16,433
  • 7
  • 64
  • 79
  • I tried your suggestion the error receded but I couldn't install the dependancies for Kafka. the error has to do with failing cpan install Test::Block – Rubber Duck Dec 02 '19 at 06:26
  • Is it a good idea to mix Alpine stable (OP uses 3.10) and testing? In three other distros I know, this potentially breaks the system. – daxim Dec 02 '19 at 08:20
  • 1
    @daxim In this particular case, there's no harm in doing so, since the headers are "new" and don't interfere with anything else. Just like other package managers, `apk` will refuse to install packages when there are dependency conflicts, so it could be simple trial and error. – valiano Dec 02 '19 at 09:09
1

I eventually searched Github to find a newer alpine perl image and was greatly helped by valino's answer in arriving at this Dockerfile:

FROM alpine:3.10.3

## alpine curl and wget aren't fully compatible, so we install them
## here. gnupg is needed for Module::Signature.
RUN apk update && apk upgrade
RUN apk add --no-cache curl tar make gcc build-base wget gnupg ca-certificates g++ git gd-dev
RUN apk add --no-cache zlib zlib-dev
RUN apk add --no-cache perl perl-dev

RUN curl -L <check the link above "newer alpine perl image" for this line it was rejected> > /bin/cpanm && chmod +x /bin/cpanm
RUN cpanm App::cpm

WORKDIR /usr

RUN cpm install Try::Tiny
RUN cpm install YAML
RUN cpm install JSON
RUN cpm install JSON::MaybeXS
RUN cpm install HTTP::Request
RUN cpm install HTTP::Response
RUN cpm install HTTP::Daemon

RUN cpm install GD::Simple
RUN cpm install GD::Graph
RUN cpm install Data::HexDump::Range
RUN cpm install Proc::Daemon
RUN cpm install Test::Block
RUN cpm install Text::Colorizer
RUN cpm install Gzip::Faster

ENV PERL5LIB=/usr/local/lib/perl5
ENV PATH=/usr/local/bin:$PATH

RUN apk add --no-cache musl-obstack-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

RUN cpm install Proc::ProcessTable
RUN cpm install Kafka::Connection

COPY run.sh /run.sh

RUN chmod +x "/run.sh"

RUN mkdir -p /code_path

WORKDIR /code_path

CMD ["/run.sh"]
Rubber Duck
  • 3,673
  • 3
  • 40
  • 59