【发布时间】:2016-11-28 22:08:01
【问题描述】:
我正在尝试在使用 ShipIt(w ship-npm 插件)部署时在正确的环境中启动我的节点应用程序?我在登台环境中部署它,但应用程序以开发模式启动,如显示 yj-he process.env.NODE_ENV
随船部署
>$ shipit staging deploy
Starting deployment...
....
Running 'start_server' task...
Running "cd /opt/hello/releases/20161128182300 && npm start" on host "myhost.live".
@myhost.live
@myhost.live > hello-world-express@0.0.1 start /opt/hello/releases/20161128182300
@myhost.live > pm2 startOrReload ecosystem.json
@myhost.live
@myhost.live [PM2] Applying action reloadProcessId on app [hello](ids: 0)
@myhost.live [PM2] [hello](0) ✓
@myhost.live ┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬──────────
@myhost.live │ App name │ id │ mode │ pid │ status │ restart │ uptime
├──────────┼────┼──────┼──────┼────────┼──────── ──┼────────┼──────┼──────────
@myhost.live │ 你好 │ 0 │ fork │ 7224 │ 在线 │ 2 │ 0s
└──────────┴────┴──────┴──────┴────────┴──────────┴ ────────┴──────┴──────────
@myhost16.live 使用pm2 show <id|name> 获取有关应用程序的更多详细信息
9.01 秒后完成“start_server”
我认为在“暂存”模式下部署会将 NODE_ENV 设置为“暂存”...不确定
hello.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World! Now you can call Express at 3637');
});
var port = process.env.PORT || 3637;
app.listen(port);
console.log('Now on ' + process.env.NODE_ENV + ' server');
console.log('Express app listening on localhost:'+ port);
控制台日志状态:
0|hello | Now on development server
0|hello | Express app listening on localhost:3637
shipitfile.js
...
// this task starts the application with PM2
shipit.blTask('start_server', function () {
var cwd = shipit.releasePath;
return shipit.remote( "cd " + cwd + " && npm start");
});
shipit.on('deployed', function () {
console.log("Deployed !");
shipit.start('start_server');
});
...
package.json
...
"main": "hello.js",
"scripts": {
"start": "pm2 startOrReload ecosystem.json",
...
生态系统.json
{
"apps" : [
{
"name": "hello",
"cwd": "/opt/hello/current",
"script": "hello.js",
"args": "",
"watch": true,
"node_args": "",
"merge_logs": true,
"env": {
"NODE_ENV": "development"
},
"env_production": {
"NODE_ENV": "production"
},
"env_staging": {
"NODE_ENV": "staging"
}
}]
}
我的生态系统.js 文件有什么问题?
感谢反馈
【问题讨论】: