Search code examples
dockercompilationautoconfalpine-linuxlibtool

Docker Alpine Error: possibly undefined macro: AC_PROG_LIBTOOL


I am trying to create a custom image for building React based project using Alpine as base image.

FROM python:3.6-alpine3.6

ENV NODE_VERSION 8.11.4

RUN addgroup -g 1000 node \
    && adduser -u 1000 -G node -s /bin/sh -D node \
    && apk add --no-cache \
        libstdc++ \
    && apk add --no-cache --virtual .build-deps \
        binutils-gold \
        curl \
        g++ \
        gcc \
        autoconf \
        automake \
        gnupg \
        libtool \    # Was added later based on suggestions I saw online
        #libltdl-dev \
        libgcc \
        libc-dev \
        libpng-dev \
        linux-headers \
        make \
        python \
  # gpg keys listed at https://github.com/nodejs/node#release-team
  && for key in \
    94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
    FD3A5288F042B6850C66B31F09FE44734EB7990E \
    71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
    DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
    C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
    B9AE9905FFD7803F25714661B63B535A4C206CA9 \
    56730D5401028683275BD23C23EFEFE93C4CFFFE \
    77984A986EBC2AA786BC0F66B01FBB92821C587A \
    8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
  ; do \
    gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
    gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
    gpg --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
  done \
    && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.xz" \
    && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
    && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
    && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
    && tar -xf "node-v$NODE_VERSION.tar.xz" \
    && cd "node-v$NODE_VERSION" \
    && ./configure \
    && make -j$(getconf _NPROCESSORS_ONLN) \
    && make install \
    #&& apk del .build-deps \                  # Had to disable this otherwise Node project compilation was failing
    && ln -s /usr/share/aclocal /usr/local/share/aclocal \         # Tried linking but seems it's not working
    && cd .. \
    && rm -Rf "node-v$NODE_VERSION" \
    && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt

ENV YARN_VERSION 1.6.0

RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
  && for key in \
    6A010C5166006599AA17F08146C2130DFD2497F5 \
  ; do \
    gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
    gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
    gpg --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
  done \
  && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
  && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
  && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
  && mkdir -p /opt \
  && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
  && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
  && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
  && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
  && apk del .build-deps-yarn


# RUN Install some more tools in one layer

USER node # Had to use this otherwise Node project compilation was failing when running with root user

Now when i build this image and use in my Bitbucket pipeline, i get the following error:

> node lib/install.js
  ⚠ spawn /opt/atlassian/pipelines/agent/build/node_modules/mozjpeg/vendor/cjpeg ENOENT
  ⚠ mozjpeg pre-build test failed
  ℹ compiling from source
  ✖ Error: autoreconf -fiv && ./configure --disable-shared --disable-dependency-tracking --with-jpeg8  --prefix="/opt/atlassian/pipelines/agent/build/node_modules/mozjpeg/vendor" --bindir="/opt/atlassian/pipelines/agent/build/node_modules/mozjpeg/vendor" --libdir="/opt/atlassian/pipelines/agent/build/node_modules/mozjpeg/vendor" && make -j8 && make install -j8
Command failed: autoreconf -fiv
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force 
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
configure.ac:23: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

Checking online gave me clue that libtool was needed so i added that to the Dockerfile (as you can see above) but i am still getting the same error.

Bitbucket pipeline:

image: my_custom_image

pipelines:
  branches:
    some_branch:
      - step:
          name: Deploy
          script:
            - chmod u+x build.sh && bash ./build.sh

I thought of listing the packages that are installed in the image.

$ cat build.sh
#!/bin/bash

apk info -v | sort
ls -laR /usr/share/aclocal
npm install
npm run build

Output of above command:

g++-6.3.0-r4
gcc-6.3.0-r4
gdbm-1.12-r0
git-2.13.7-r0
gmp-6.1.2-r0
gnupg-2.1.20-r1
isl-0.17.1-r0
libassuan-2.4.3-r0
libatomic-6.3.0-r4
libbz2-1.0.6-r5
libc-dev-0.7.1-r0
libc-utils-0.7.1-r0
libcap-2.25-r1
libcurl-7.61.0-r0
libffi-3.2.1-r3
libgcc-6.3.0-r4
libgcrypt-1.7.10-r0
libgomp-6.3.0-r4
libgpg-error-1.27-r0
libksba-1.3.4-r0
libldap-2.4.44-r5
libpng-1.6.29-r1
libpng-dev-1.6.29-r1
libressl2.5-libcrypto-2.5.5-r2
libressl2.5-libssl-2.5.5-r2
libressl2.5-libtls-2.5.5-r2
libsasl-2.1.26-r10
libssh2-1.8.0-r1
libstdc++-6.3.0-r4
linux-headers-4.4.6-r2
m4-1.4.18-r0
make-4.2.1-r0
mpc1-1.0.3-r0
mpfr3-3.1.5-r0
musl-1.1.16-r14
musl-dev-1.1.16-r14
musl-utils-1.1.16-r14
ncurses-libs-6.0_p20171125-r1
ncurses-terminfo-6.0_p20171125-r1
ncurses-terminfo-base-6.0_p20171125-r1
npth-1.2-r0
openssh-7.5_p1-r2
openssh-client-7.5_p1-r2
openssh-keygen-7.5_p1-r2
openssh-server-7.5_p1-r2
openssh-sftp-server-7.5_p1-r2
pcre-8.41-r0
perl-5.24.4-r1
pinentry-1.0.0-r0
pkgconf-1.3.7-r0
python2-2.7.15-r0
readline-6.3.008-r5
scanelf-1.2.2-r0
sqlite-libs-3.20.1-r2
ssl_client-1.26.2-r11
xz-libs-5.2.3-r0
zlib-1.2.11-r0
zlib-dev-1.2.11-r0

/usr/share/aclocal:
total 32
drwxr-xr-x    2 root     root          4096 Sep  3 08:37 .
drwxr-xr-x    1 root     root          4096 Sep  3 09:04 ..
-rw-r--r--    1 root     root           368 Oct 19  2017 README
-rw-r--r--    1 root     root         12670 May 20  2017 pkg.m4

I could not find libtool in the package list above. Am i missing something?

Note: Using jessie instead of alpine as base image works but the image size is more. I want to keep it as small as possible.


Solution

  • I was finally able to resolve it. Though i came across this link before, that time i just checked the Contents of package section. Today i again visited libtool's page and finally noticed that there is a Depends section on the right-hand side that mentions two packages as dependency (bash and libltdl) for libtool. Installing both the packages did the trick. :)


    UPDATE:
    Although my issue was resolved, i thought of cleaning up the script just to ensure i don't end up adding unnecessary packages to my image. That's when i found that my earlier assumption about explicitly adding bash and libltdl packages for fixing libtool dependency was wrong. I am going to write all the issues (and fixes) that i encountered while trying to build my docker image for building React project. It's more of a note for me and might still help someone.

    Issues and Fixes:

    1) npm WARN lifecycle <project_name>@3.6.0~preinstall: cannot run in wd %s %s (wd=%s) <project_name>@3.6.0 npm run npmcheckversion /opt/atlassian/pipelines/agent/build

    Fix: Image was running with root user and not with node user. At the end of my Dockerfile, i added this line:

    USER node
    

    What this does is runs the image as the specified user and not as root user.

    Ref: https://docs.docker.com/v17.09/engine/reference/builder/#user


    2) Error: pngquant failed to build, make sure that libpng-dev is installed

    Fix: As mentioned in the error message, i installed package libpng-dev


    3) /bin/sh: autoreconf: not found

    Fix: To fix this, i installed autoconf and libtool. Please note that libtool automatically installs its dependencies i.e., libltdl and bash.

    I checked the list of installed packages and was able to confirm that libtool was actually installed but the build again failed, although with another error.


    4) Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326. autoreconf: failed to run aclocal: No such file or directory

    Fix: automake was required to fix the issue. Still, one more error was about to come :)


    5) configure: error: no nasm (Netwide Assembler) found

    Fix: Installing nasm package fixed it.


    That's it. I was ready with my final image. ;)