gpt4 book ai didi

PM2:在一台服务器上部署多个环境?

转载 作者:行者123 更新时间:2023-12-02 03:33:41 24 4
gpt4 key购买 nike

我使用 PM2 进行部署/流程管理,并且该应用程序处理大量 DNS 任务,因此如果我从远程服务器运行开发应用程序,并在保存时进行 Rsyncing 或 SFTPing(仍在整理中),这是最简单的.

既然如此,开发应用程序与生产应用程序位于同一虚拟机上是理想的情况。但是,PM2 部署配置文件 (ecosystem.config.js) 的结构似乎无法实现这一点,因为当我运行 pm2 deploydevelopment 时,开发版本取代虚拟机上的生产过程。

这是我所拥有的:

module.exports = {
apps: [
{
name: "APP NAME",
script: "app.js",
env_development: {
NODE_ENV: "development",
...
},
env_production: {
NODE_ENV: "production",
...
}
}
],
deploy: {
production: {
user: "user",
host: ["123.123.123.123"],
ref: "origin/master",
repo: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bed9d7cafed9d7cad2dfdc90ddd1d3" rel="noreferrer noopener nofollow">[email protected]</a>:me/repo.git",
path: "/var/www/app",
"post-deploy":
"npm install && pm2 reload ecosystem.config.js --env production"
},
development: {
user: "user",
host: ["123.123.123.123"],
ref: "origin/master",
repo: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c4b45586c4b4558404d4e024f4341" rel="noreferrer noopener nofollow">[email protected]</a>:me/repo.git",
path: "/var/www/app-dev",
"post-deploy":
"npm install && pm2 reload ecosystem.config.js --env development"
}
}
};

对于实现这一目标的最佳方法有什么想法吗?

最佳答案

引用此PR后,我想你应该能够添加 append_env_to_name: true作为 apps 中对象的属性ecosystem.config.js 的数组:

所以你更新了ecosystem.config.js文件如下:

module.exports = {
apps: [
{
name: "APP NAME",
append_env_to_name: true // <===== add this line
script: "app.js",
env_development: {
NODE_ENV: "development",
...
},
env_production: {
NODE_ENV: "production",
...
}
}
],
deploy: {
production: {
user: "user",
host: ["123.123.123.123"],
ref: "origin/master",
repo: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72151b0632151b061e13105c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>:me/repo.git",
path: "/var/www/app",
"post-deploy":
"npm install && pm2 reload ecosystem.config.js --env production"
},
development: {
user: "user",
host: ["123.123.123.123"],
ref: "origin/master",
repo: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e09071a2e09071a020f0c400d0103" rel="noreferrer noopener nofollow">[email protected]</a>:me/repo.git",
path: "/var/www/app-dev",
"post-deploy":
"npm install && pm2 reload ecosystem.config.js --env development"
}
}
};

关于PM2:在一台服务器上部署多个环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51062396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com