pm2 - pm2 将生产和登台部署到具有不同应用程序名称的相同服务
问题描述
我想在具有不同名称的同一台服务器上部署登台和生产,但鉴于 pm2 生态系统文件的文档,我无论如何都看不到实现这一点。这是我的ecosystem.config.js
以下内容:
module.exports = {
apps : [{
name: 'frontend',
script: 'server/index.js',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '256M',
env: {
NODE_ENV: 'development'
},
env_staging: {
NODE_ENV: 'staging',
PORT: 3001
},
env_production: {
NODE_ENV: 'production',
PORT: 3002
}
}],
deploy : {
production : {
user : '<redacted>',
host : ['<redacted>'],
ref : 'origin/master',
repo : '<redacted>',
path : '<redacted>/production',
'pre-deploy': 'git fetch --all',
'post-deploy' : 'npm install -d && npm run build:production && pm2 reload ecosystem.config.js --env production',
'post-setup' : 'npm install -d && npm run build:production && pm2 reload ecosystem.config.js --env production'
},
staging : {
user : '<redacted>',
host : ['<redacted>],
ref : 'origin/development',
repo : '<redacted>',
path : '<redacted>/staging',
'pre-deploy': 'git fetch --all',
'post-deploy' : 'npm install -d && npm run build:staging && pm2 reload ecosystem.config.js --env staging',
'post-setup' : 'npm install -d && npm run build:staging && pm2 reload ecosystem.config.js --env staging'
}
}
};
deploy
鉴于配置没有name
作为选项提供,我是否可以实现这一点?
解决方案
那么为什么不创建具有不同名称的不同应用程序呢?
[{
name: 'frontendDev',
script: 'server/index.js',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '256M',
env: {
NODE_ENV: 'development'
},
}, {
name: 'frontendStag',
script: 'server/index.js',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '256M',
env_staging: {
NODE_ENV: 'staging',
PORT: 3001
},
},{
name: 'frontendProd',
script: 'server/index.js',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '256M',
env_production: {
NODE_ENV: 'production',
PORT: 3002
}
}],
您还可以拆分为差异文件。
推荐阅读
- excel - Excel图表显示案例加载时间线
- regex - 正则表达式用空格替换所有下划线
- java - CXF Http Conduit - 超时被忽略(JAVA)
- yaml - 可以在 YAML 中使用 IP 地址吗
- macos - iokit 驱动程序中的全局变量
- python - Python 3.6 - 将输出作为新列添加到数据框,然后输出到 excel
- c# - 如何在 Gridview 中使用单个 LinkButton 来更新 aspx 页面上其他地方的 TextBox
- sqlite - 带有 where 子句的 SQLite 查询
- java - java.net.UnknownHostException:运行 Rest Assured 时出现 HTTPS 异常
- javascript - ng-repeat 如何使重复键无效但保留行数据?