Docker Alpine错误:可能是未定义的宏:AC_PROG_LIBTOOL

问题描述 投票:1回答:1

我正在尝试使用Alpine作为基本图像创建用于构建基于React的项目的自定义图像。

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

现在,当我构建此图像并在我的Bitbucket管道中使用时,我收到以下错误:

> 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)

在线检查给了我线索,需要libtool,所以我把它添加到Dockerfile(如上所示),但我仍然得到相同的错误。

Bitbucket管道:

image: my_custom_image

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

我想到列出图像中安装的软件包。

$ cat build.sh
#!/bin/bash

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

输出上述命令:

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

我在上面的包装清单中找不到libtool。我错过了什么吗?

注意:使用jessie而不是alpine作为基本图像可以工作,但图像大小更多。我希望尽可能小。

docker compilation autoconf alpine libtool
1个回答
2
投票

我终于能够解决它了。虽然之前我遇到过this链接,那个时候我刚刚检查了Contents of package部分。今天我再次访问了libtool的page,最后注意到右侧有一个Depends部分,提到bash的两个包作为依赖(libltdllibtool)。安装这两个包就可以了。 :)


更新: 虽然我的问题已经解决,但我想清理脚本只是为了确保我不会最终添加不必要的包到我的图像。就在那时我发现我之前关于明确添加bashlibltdl包来修复libtool依赖的假设是错误的。我将编写我在尝试构建用于构建React项目的docker镜像时遇到的所有问题(和修复)。对我来说这更像是一张纸条,可能仍然会对某人有所帮助。

问题和修复:

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

修复:图像与root用户一起运行,而不是与node用户一起运行。在我的Dockerfile的末尾,我添加了这一行:

USER node

这样做是将图像作为指定用户而不是root用户运行。

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


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

修复:如错误消息中所述,我安装了包libpng-dev


3)/bin/sh: autoreconf: not found

修复:为了解决这个问题,我安装了autoconflibtool。请注意,libtool会自动安装其依赖项,即libltdlbash

我检查了已安装软件包的列表,并且能够确认libtool实际安装但是构建再次失败,尽管还有其他错误。


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

修复:automake需要解决此问题。不过,还有一个错误即将来临:)


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

修复:安装nasm包固定它。


而已。我准备好了我的最终形象。 ;)

© www.soinside.com 2019 - 2024. All rights reserved.