When deploying an app to Bluemix using the sdk-for-nodejs buildpack, it's running npm install when I don't want it to. How can I stop it?

天大地大妈咪最大 提交于 2019-12-25 08:39:23

问题


I'm using Bluemix DevOps Pipelines to deploy a Node.js app to Bluemix as a Cloud Foundry app. It is using the sdk-for-nodejs buildback (although I haven't specified that, it's detecting the package.json file).

It takes a long time to stage the app. Looking at the logs, this is because it appears to be running npm install. However, I have set up my pipeline so that npm install is called in an earlier stage, and the build artifact that is to be deployed already contains the installed node_modules, so if I have to restage it should be quick, as it shouldn't have to install all the modules again.

This is the command that my pipeline is using to deploy:

cf push "${CF_APP}" -c "npm run start:prod"

My Procfile also contains the same command:

web: npm run start:prod
node: npm run start:prod

(I've tried it both with and without the second line. I think the logs from below were when it contained both lines.)

And indeed towards the end of my deployment logs it says

App mcp-server was started using this command `npm run start:prod`

That script in my package.json file does not run npm install:

"scripts": {
    ...
    "start:prod": "cross-env NODE_ENV=production node index.js",

The logs that make it look like it's re-installing the modules are:

Staging...
-----> IBM SDK for Node.js Buildpack v3.11-20170303-1144
-----> Creating runtime environment

       NPM_CONFIG_PRODUCTION=true
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.npm (package.json):   unspecified (use default)
       Resolving node version >=4 via 'node-version-resolver'
       Installing IBM SDK for Node.js (4.8.0) from cache
       Using default npm version: 2.15.11
-----> Restoring cache
       Loading 2 from cacheDirectories (default):
       - node_modules (exists - skipping)
       - bower_components (not cached - skipping)
-----> Building dependencies
       Rebuilding any native modules

       > radium@0.18.2 postinstall /tmp/app/node_modules/radium

       > dtrace-provider@0.8.1 install /tmp/app/node_modules/dtrace-provider

       > pre-commit@1.2.2 install /tmp/app/node_modules/pre-commit

       > spawn-sync@1.0.15 postinstall /tmp/app/node_modules/spawn-sync
       > node postinstall


Completed: 0.1% (0.1mb / 78.2mb)
...
Completed: 99.9% (78.2mb / 78.2mb)
inside extract, run complete
       Completed: 0.0% (0.0mb / 78.2mb)
Completed: 0.1% (0.0mb / 78.2mb)
Completed: 2.6% (2.0mb / 78.2mb)
Completed: 8.3% (6.5mb / 78.2mb)
Completed: 43.1% (33.7mb / 78.2mb)
Completed: 44.3% (34.7mb / 78.2mb)
Completed: 45.5% (35.6mb / 78.2mb)
Completed: 64.2% (50.2mb / 78.2mb)
Completed: 65.0% (50.8mb / 78.2mb)
Completed: 66.5% (52.1mb / 78.2mb)
Completed: 71.4% (55.8mb / 78.2mb)

       > node-gyp rebuild

       make: Entering directory `/tmp/app/node_modules/nodejieba/build'
...
> spawn-sync@1.0.15 postinstall /tmp/app/node_modules/spawn-sync


> npm run clean && npm run build

> myapp@2.0.0 clean /tmp/app

> myapp@2.0.0 build /tmp/app
> cross-env NODE_ENV=production webpack --config webpack.config.js

Of particular note are the lines:

Completed: 0.1% (0.1mb / 78.2mb)
...
Completed: 99.9% (78.2mb / 78.2mb)

where I've omitted well over 100 lines where it seems to be installing something very slowly.

And also:

> npm run clean && npm run build

> myapp@2.0.0 clean /tmp/app

> myapp@2.0.0 build /tmp/app
> cross-env NODE_ENV=production webpack --config webpack.config.js

which are scripts from my app that I really don't want to be running at deployment time.

I've already tried to tell it to run npm run start:prod - how can I stop it from running these install steps?


回答1:


Looking at the buildpack code, I don't see a flag to disable npm install.

https://github.com/cloudfoundry/nodejs-buildpack/blob/master/lib/dependencies.sh#L80

Option 1

Create a package_nodependencies.json file with no dependencies listed. After your build steps runs the npm install using your regular package.json, delete the package.json and rename package_nodependencies.json to package.json.

rm package.json && mv package_nodependencies.json package.json

npm install on cf push should now be quick. Be sure that you don't have node_modules in your .cfignore file

Option 2

Move all your dependencies to devDependencies in package.json. During your build, run npm install without PRODUCTION

NODE_ENV=development npm install



来源:https://stackoverflow.com/questions/43917508/when-deploying-an-app-to-bluemix-using-the-sdk-for-nodejs-buildpack-its-runnin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!