【发布时间】:2022-01-14 04:10:02
【问题描述】:
我以前没有遇到过这个问题,我有 nodegyp (g++ make python) 的所有先决条件,它在 alpine 3.13 上工作。 但是一旦 node:14-alpine 更新到最新的 alpine,它就会在构建过程中开始失败。
tldr:在 alpine 3.13 上构建工作,但在 3.14 上不工作 - nodegyp 问题
Docker版本:Docker版本20.10.11,build dea9396
containerd containerd.io 1.4.12 7b11cfaabd73bb80907dd23182b9347b4245eb5d
Dockerfile:
FROM node:14-alpine as builder
RUN mkdir /app && chown node:node /app && npm i npm@latest -g
WORKDIR /app
COPY package*.json .npmrc ./
RUN apk add --no-cache --virtual .gyp python3 make g++ \
&& npm ci --only=production && npm cache clean --force \
&& apk del .gyp \
&& rm -f .npmrc
ENV PATH /app/node_modules/.bin:$PATH
COPY --chown=node:node . .
FROM builder as dev
WORKDIR /app
RUN npm ci
ENV PATH /app/node_modules/.bin:$PATH
USER node
CMD ["nodemon", "index.js"]
完整的错误是:
npm ERR! path /app/node_modules/xxhash
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! make: Entering directory '/app/node_modules/xxhash/build'
npm ERR! make: Leaving directory '/app/node_modules/xxhash/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@14.18.2 | linux | x64
npm ERR! gyp info find Python using Python version 3.9.5 found at "/usr/bin/python3"
npm ERR! gyp WARN EACCES current user ("node") does not have permission to access the dev dir "/root/.cache/node-gyp/14.18.2"
npm ERR! gyp WARN EACCES attempting to reinstall using temporary dev dir "/tmp/.node-gyp"
npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v14.18.2/node-v14.18.2-headers.tar.gz
npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v14.18.2/node-v14.18.2-headers.tar.gz
npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v14.18.2/SHASUMS256.txt
npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v14.18.2/SHASUMS256.txt
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/app/node_modules/xxhash/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/tmp/.node-gyp/14.18.2/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/tmp/.node-gyp/14.18.2',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/tmp/.node-gyp/14.18.2/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/app/node_modules/xxhash',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! make: printf: Operation not permitted
npm ERR! make: *** [hash.target.mk:117: Release/obj.target/hash/src/hash.o] Error 127
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:400:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)
npm ERR! gyp ERR! System Linux 5.4.0-1057-aws
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /app/node_modules/xxhash
npm ERR! gyp ERR! node -v v14.18.2
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok
搜索了一段时间后卡住了,没有找到解决办法
【问题讨论】: