节点 docker 构建因节点 gyp 重建而失败

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

为 ts Node js 应用程序构建 docker 镜像,将

"@kafkajs/zstd": "^0.1.1"
添加到 package.json 后,docker 构建开始失败。这是 docker 文件

# .......Development Stage.......
FROM --platform=linux/amd64 node:18-alpine3.18 as development

WORKDIR /home/app
COPY . /home/app

# RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*

RUN npm install
RUN npm run build

EXPOSE 8080

CMD ["node", "/home/app/dist/main.js"]

这是错误:

#9 71.27 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use

查看该线程此处,以及该线程此处。尝试将 python 添加到 docker 文件:

# RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*

RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install \
    && apk del .gyp

之后构建仍然失败:

#10 83.53 npm ERR! code 1
#10 83.53 npm ERR! path /usr/src/server/node_modules/segfault-handler
#10 83.55 npm ERR! command failed
#10 83.55 npm ERR! command sh -c node-gyp rebuild
#10 83.55 npm ERR! make: Entering directory '/usr/src/server/node_modules/segfault-handler/build'
#10 83.55 npm ERR!   CXX(target) Release/obj.target/segfault-handler/src/segfault-handler.o
#10 83.55 npm ERR! make: Leaving directory '/usr/src/server/node_modules/segfault-handler/build'
#10 83.55 npm ERR! gyp info it worked if it ends with ok
#10 83.56 npm ERR! gyp info using [email protected]
#10 83.56 npm ERR! gyp info using [email protected] | linux | x64
#10 83.56 npm ERR! gyp info find Python using Python version 3.8.15 found at "/usr/bin/python3"
#10 83.56 npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v16.8.0/node-v16.8.0-headers.tar.gz
#10 83.56 npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v16.8.0/node-v16.8.0-headers.tar.gz
#10 83.56 npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v16.8.0/SHASUMS256.txt
#10 83.56 npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v16.8.0/SHASUMS256.txt
#10 83.56 npm ERR! (node:62) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
#10 83.56 npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
#10 83.56 npm ERR! gyp info spawn make
#10 83.56 npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
#10 83.56 npm ERR! ../src/segfault-handler.cpp:23:10: fatal error: execinfo.h: No such file or directory
#10 83.56 npm ERR!    23 | #include <execinfo.h>
#10 83.56 npm ERR!       |          ^~~~~~~~~~~~
#10 83.56 npm ERR! compilation terminated.
#10 83.56 npm ERR! make: *** [segfault-handler.target.mk:117: Release/obj.target/segfault-handler/src/segfault-handler.o] Error 1
#10 83.56 npm ERR! gyp ERR! build error 
#10 83.56 npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
#10 83.56 npm ERR! gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
#10 83.56 npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
#10 83.56 npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
#10 83.56 npm ERR! gyp ERR! System Linux 5.10.124-linuxkit
#10 83.56 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#10 83.56 npm ERR! gyp ERR! cwd /usr/src/server/node_modules/segfault-handler
#10 83.56 npm ERR! gyp ERR! node -v v16.8.0
#10 83.56 npm ERR! gyp ERR! node-gyp -v v7.1.2
#10 83.56 npm ERR! gyp ERR! not ok

之后阅读此线程https://github.com/ddopson/node-segfault-handler/issues/70,但也没有太多运气,也许我正在深入挖掘,任何帮助表示感谢,谢谢!

node.js docker node-gyp
1个回答
0
投票
您提到的

线程提供了如何完成此操作的线索。但看起来您需要回滚到 Node 的早期版本。

FROM --platform=linux/amd64 node:14.18.0-alpine as development WORKDIR /home/app COPY . /home/app RUN apk add --no-cache --no-progress \ python \ make \ g++ \ libexecinfo-dev \ libexecinfo RUN npm install
假设像这样简单的

package.json

{ "name": "test", "version": "1.0.0", "dependencies": { "@kafkajs/zstd": "^0.1.1" } }
    
© www.soinside.com 2019 - 2024. All rights reserved.