【发布时间】:2022-06-21 01:03:57
【问题描述】:
环境:M1(Apple Silicon)/macOS Monterey 12.3/Docker 4.8.1
我有一个 node.js 项目,其中包含 MongoDB、mongoose、aws、Twilio 作为一些主要依赖项。该项目目前正在使用 Dockerfile 和在 EC2 实例上运行的容器进行部署。
以前,在我无法确定的更改之前,部署工作完美。
最近,在对某些 API 进行了一些更改(不包括安装额外的软件包)之后,部署开始失败,并出现令人讨厌的冗长消息,这些消息似乎指向 bcrypt(某种依赖问题?)和 python(未安装?) 作为罪魁祸首。
我有点不知所措,因为我没有更改配置,并且通过重新安装依赖项并专门针对上述两个依赖项进行了几天的调试后,部署仍然无法正常工作。
崩溃发生在最后一步,RUN npm ci --only=production。
我已经尝试过什么
- 在有人链接到this 相关的 SO 线程之前,我已经尝试过了,但似乎对我不起作用。
- 使用以下命令修改 Dockerfile
RUN apt-get update -y && apt-get install -y rsync build-essential nodejs
RUN npm install -g node-gyp
Dockerfile
FROM node:16 AS base
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
# install project dependencies
# a wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
FROM base AS main
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "yarn", "start" ]
FROM main AS test
CMD [ "yarn", "test" ]
FROM main AS builder
RUN apt-get update -y && apt-get install -y rsync
ENV NODE_ENV production
# compile JS according to tsconfig.json to dist/
RUN yarn build
FROM node:16-alpine AS deploy
RUN apk --no-cache add curl
ENV NODE_ENV production
ENV PATH /app/node_modules/.bin:$PATH
WORKDIR /app
COPY package*.json ./
COPY --from=builder /app/dist ./dist/
RUN mkdir -p uploads/
RUN npm ci --only=production
CMD ["node", "dist/server.js"]
错误消息
=> ERROR [deploy 7/7] RUN npm ci --only=production 26.5s
------
> [deploy 7/7] RUN npm ci --only=production:
#19 5.326 npm WARN deprecated request-promise@4.2.6: request-promise has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
#19 5.490 npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
#19 5.511 npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
#19 7.381 npm WARN deprecated har-validator@5.1.5: this library is no longer supported
#19 9.930 npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
#19 19.32 npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
#19 19.98 npm WARN deprecated uuid@3.3.2: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
#19 26.40 npm notice
#19 26.40 npm notice New minor version of npm available! 8.5.5 -> 8.10.0
#19 26.40 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.10.0>
#19 26.40 npm notice Run `npm install -g npm@8.10.0` to update!
#19 26.40 npm notice
#19 26.40 npm ERR! code 1
#19 26.40 npm ERR! path /app/node_modules/bcrypt
#19 26.40 npm ERR! command failed
#19 26.40 npm ERR! command sh -c node-pre-gyp install --fallback-to-build
#19 26.40 npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/app/node_modules/bcrypt/lib/binding/napi-v3 --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
#19 26.40 npm ERR! node-pre-gyp info it worked if it ends with ok
#19 26.40 npm ERR! node-pre-gyp info using node-pre-gyp@1.0.9
#19 26.40 npm ERR! node-pre-gyp info using node@16.15.0 | linux | arm64
#19 26.40 npm ERR! node-pre-gyp info check checked for "/app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" (not found)
#19 26.40 npm ERR! node-pre-gyp http GET https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-arm64-musl.tar.gz
#19 26.40 npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-arm64-musl.tar.gz
#19 26.40 npm ERR! node-pre-gyp WARN Pre-built binaries not installable for bcrypt@5.0.1 and node@16.15.0 (node-v93 ABI, musl) (falling back to source compile with node-gyp)
#19 26.40 npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-arm64-musl.tar.gz
#19 26.40 npm ERR! gyp info it worked if it ends with ok
#19 26.40 npm ERR! gyp info using node-gyp@9.0.0
#19 26.40 npm ERR! gyp info using node@16.15.0 | linux | arm64
#19 26.40 npm ERR! gyp info ok
#19 26.40 npm ERR! gyp info it worked if it ends with ok
#19 26.40 npm ERR! gyp info using node-gyp@9.0.0
#19 26.40 npm ERR! gyp info using node@16.15.0 | linux | arm64
#19 26.40 npm ERR! gyp ERR! find Python
#19 26.40 npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
#19 26.40 npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
#19 26.40 npm ERR! gyp ERR! find Python checking if "python3" can be used
#19 26.40 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#19 26.40 npm ERR! gyp ERR! find Python checking if "python" can be used
#19 26.40 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#19 26.40 npm ERR! gyp ERR! find Python
#19 26.40 npm ERR! gyp ERR! find Python **********************************************************
#19 26.40 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
#19 26.40 npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
#19 26.40 npm ERR! gyp ERR! find Python you can try one of the following options:
#19 26.40 npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
#19 26.40 npm ERR! gyp ERR! find Python (accepted by both node-gyp and npm)
#19 26.40 npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
#19 26.40 npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
#19 26.40 npm ERR! gyp ERR! find Python npm config set python "/path/to/pythonexecutable"
#19 26.40 npm ERR! gyp ERR! find Python For more information consult the documentation at:
#19 26.40 npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
#19 26.40 npm ERR! gyp ERR! find Python **********************************************************
#19 26.40 npm ERR! gyp ERR! find Python
#19 26.40 npm ERR! gyp ERR! configure error
#19 26.40 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
#19 26.40 npm ERR! gyp ERR! stack at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
#19 26.40 npm ERR! gyp ERR! stack at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
#19 26.40 npm ERR! gyp ERR! stack at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
#19 26.40 npm ERR! gyp ERR! stack at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
#19 26.40 npm ERR! gyp ERR! stack at exithandler (node:child_process:406:5)
#19 26.40 npm ERR! gyp ERR! stack at ChildProcess.errorhandler (node:child_process:418:5)
#19 26.40 npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
#19 26.40 npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
#19 26.40 npm ERR! gyp ERR! stack at onErrorNT (node:internal/child_process:478:16)
#19 26.40 npm ERR! gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:83:21)
#19 26.40 npm ERR! gyp ERR! System Linux 5.10.104-linuxkit
#19 26.40 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/app/node_modules/bcrypt/lib/binding/napi-v3" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
#19 26.40 npm ERR! gyp ERR! cwd /app/node_modules/bcrypt
【问题讨论】:
-
在任何时候看起来都没有安装 Python。不知道为什么 node-gyp 依赖它,但您可以使用
RUN apt-get install -y python3添加它。 -
@Ouroborus 感谢您的建议,但我也已经尝试过了,结果仍然与 OP 相同!