Docker Build在GCP Cloud Build中失败-在localhost中成功

时间:2019-09-24 17:37:59

标签: node.js docker npm google-cloud-platform google-cloud-build

以下Dockerfile在GCP Cloud Build中的npm install --production处失败

FROM node:10.15.3-slim 

RUN sh -c 'apt-get update && apt-get install -y build-essential && apt-get install -y python'

COPY src /home/$user/
WORKDIR /home/$user

RUN npm install --production

CMD [ "npm", "start" ]

这是package.json

{
    "name": "generic-cloud-node-sql",
    "version": "1.0.0",
    "private": true,
    "scripts": {
        "start": "node ./bin/www",          
    },
    "dependencies": {
        "@google-cloud/bigquery": "^4.0.0",
        "@google-cloud/storage": "^2.5.0",
        "body-parser": "*",
        "cron": "^1.7.1",
        "dateformat": "^3.0.2",
        "express": "*",
        "form-data": "*",
        "multer": "^1.4.1",
        "njwt": "*",
        "promise-mysql": "^3.3.1",
        "request": "^2.88.0",
        "request-ip": "^2.1.3",
        "throw.js": "*",
        "bcrypt": "^3.0.6",
        "winston": "*",
        "winston-gke": "*"
    },
    "devDependencies": {
        "chai": "^4.2.0",
        "mocha": "^5.2.0",
        "chai-http": "*"
    }
}

尝试通过消息安装bcrypt时失败

Step #1: > bcrypt@3.0.6 install /home/node_modules/bcrypt
Step #1: > node-pre-gyp install --fallback-to-build
Step #1:
Step #1: node-pre-gyp WARN Using request for node-pre-gyp https download
Step #1: node-pre-gyp ERR! Completion callback never invoked!
Step #1: node-pre-gyp ERR! System Linux 4.15.0-1044-gcp
Step #1: node-pre-gyp ERR! command "/usr/local/bin/node" "/home/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
Step #1: node-pre-gyp ERR! cwd /home/node_modules/bcrypt
Step #1: node-pre-gyp ERR! node -v v10.15.3
Step #1: node-pre-gyp ERR! node-pre-gyp -v v0.12.0
Step #1: node-pre-gyp ERR! This is a bug in `node-pre-gyp`.
Step #1: node-pre-gyp ERR! Try to update node-pre-gyp and file an issue if it does not help:

但是,当我在本地运行docker build时,上述Dockerfile和package.json成功运行了。

  • 没有将node_modules复制到docker镜像
  • 未将package_lock.json复制到Docker映像
  • 在没有更改任何相关文件(Dockerfile,package.json等)的情况下,构建过程开始失败

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

这看起来更像是节点预石膏问题,而不是Cloud Build问题。我在GitHub上发现了this个问题,该问题与您遇到的问题相匹配。绝对值得一看。