我正在尝试创建一个自定义图像,以使用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
作为基本图像有效,但是图像尺寸更大。我想让它尽可能的小。
答案 0 :(得分:2)
我终于能够解决它。尽管我之前遇到过this链接,但是那一次我只是检查了Contents of package部分。今天,我再次访问了libtool的page,最后注意到,右侧有一个Depends
部分,其中提到了两个软件包作为{的依赖项(bash
和libltdl
) {1}}。安装两个软件包就可以了。 :)
更新:
尽管我的问题已解决,但我想到清理脚本只是为了确保最终不要在图像中添加不必要的软件包。从那时起,我发现我先前关于显式添加libtool
和bash
软件包以修复libltdl
依赖关系的假设是错误的。我将编写尝试构建用于构建React项目的Docker映像时遇到的所有问题(和修复)。对我来说,这更多的是笔记,可能仍然会帮助某人。
问题和解决方法:
1)libtool
修复:图像是通过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
用户运行的。在我的Dockerfile的末尾,我添加了这一行:
node
这是作为指定用户而不是USER node
用户运行映像。
参考:https://docs.docker.com/v17.09/engine/reference/builder/#user
2)root
修复:如错误消息中所述,我安装了软件包Error: pngquant failed to build, make sure that libpng-dev is installed
3)libpng-dev
修复:要解决此问题,我安装了/bin/sh: autoreconf: not found
和autoconf
。请注意,libtool
是自动安装其依赖项,即libtool
和libltdl
。
我检查了已安装软件包的列表,并能够确认实际上已安装bash
,但是构建再次失败,尽管还有另一个错误。
4)libtool
修复: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
是解决此问题所必需的。尽管如此,还会出现另一个错误:)
5)automake
修复:安装configure: error: no nasm (Netwide Assembler) found
软件包已将其修复。
就是这样。我已经准备好了最终的图像。 ;)