当使用sdk-for-nodejs buildpack将应用程序部署到Bluemix时,如果我不希望它运行npm install.我该如何阻止它? [英] 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?

查看:131
本文介绍了当使用sdk-for-nodejs buildpack将应用程序部署到Bluemix时,如果我不希望它运行npm install.我该如何阻止它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Bluemix DevOps Pipelines将Node.js应用程序作为Cloud Foundry应用程序部署到Bluemix.它使用 sdk-for-nodejs 内置(尽管我没有指定,但它正在检测package.json文件).

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).

上架该应用程序需要很长时间.查看日志,这是因为它似乎正在运行npm install.但是,我已经设置好管道,以便在更早的阶段调用npm install,并且要部署的构建工件已经包含已安装的node_modules,因此,如果我必须重新安装它,它应该很快,因为它不必再次安装所有模块.

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"

我的Procfile也包含相同的命令:

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`

我的package.json文件中的脚本未运行npm install:

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)

在这里我已经省略了100多个行,而这似乎是在缓慢地安装一些东西.

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

还有:

> 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.

我已经尝试告诉它运行npm run start:prod-如何阻止它运行这些安装步骤?

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

推荐答案

看着buildpack代码,我看不到禁用npm install的标志.

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

选项1

创建一个没有列出依赖项的package_nodependencies.json文件.在构建步骤使用常规package.json运行npm install之后,删除package.json并将package_nodependencies.json重命名为package.json.

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现在应该很快.确保您的.cfignore文件中没有node_modules

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

选项2

将所有依赖项移动到package.json中的devDependencies.在构建期间,运行不带PRODUCTION的npm install

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

NODE_ENV =开发npm install

NODE_ENV=development npm install

这篇关于当使用sdk-for-nodejs buildpack将应用程序部署到Bluemix时,如果我不希望它运行npm install.我该如何阻止它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆