Ich habe eine Datei "ecosystem.json" für meine Knoten-App, die ich mithilfe von PM2 bereitstellen kann.Wie kann ich mithilfe von PM2 meine node.js-App in mehreren Umgebungen und auf demselben Server bereitstellen?
Ich habe versucht, es eine Reihe von verschiedenen Möglichkeiten, die Konfiguration, haben aber kein Glück hatte mein Ziel zu erreichen, das ist:
- der Lage sein, entweder die Produktion oder Staging-Umgebung bereitstellen (derzeit beide auf demselben Server).
- Bei der Bereitstellung sollte die andere ebenfalls ausgeführt werden.
- Die 2 verschiedenen Umgebungen sollten
auf verschiedenen Ports (prod = 8000, staging = 3000) sein Was je nachdem, was Befehl bereitstellen passiert ist, ich zum ersten Mal Gewinne laufen.
Also wenn ich pm2 deploy production
und dann pm2 deploy staging
, nur die Produktion App/Port Combo läuft auf dem Server, und umgekehrt, wenn ich die Reihenfolge wechseln.
EDIT: Wenn ich das conf unten verwende, wird es 2 apps laufen in pm2 status
, aber wenn ich eine netstat
mache, sehe ich nur den ersten Port. (centos 6)
Ich fühle mich wie ich muss etwas offensichtlich fehlen. Hier ist meine ecosystem.json Datei, ich habe es mit und ohne mehrere App-Deklarationen oben versucht.
{
/**
* Here we declare the apps that must be managed by PM2
* All options are listed here:
* https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#json-app-declaration
*
*/
apps : [
{
"name" : "myapp-staging",
"script" : "app.js",
"instances" : "1",
"error_file" : "/var/log/nodejs/myapp.mydomain.com-staging-err.log",
"out_file" : "/var/log/nodejs/myapp.mydomain.com-staging-out.log",
"pid_file" : "/home/node/myapp.mydomain.com-staging.pid",
"exec_mode" : "cluster_mode",
"env_staging" : {
"NODE_ENV": "staging", "PORT": 3000
},
"env_production" : {
"NODE_ENV": "production", "PORT": 8000
}
},
{
"name" : "myapp-production",
"script" : "app.js",
"instances" : "1",
"error_file" : "/var/log/nodejs/myapp.mydomain.com-staging-err.log",
"out_file" : "/var/log/nodejs/myapp.mydomain.com-staging-out.log",
"pid_file" : "/home/node/myapp.mydomain.com-staging.pid",
"exec_mode" : "cluster_mode",
"env_production" : {
"NODE_ENV": "production", "PORT": 8000
}
}
],
/**
* PM2 help you to deploy apps over your servers
* For more help go to :
* https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#deployment-pm2--090
*/
deploy : {
production : {
user : "node",
host : "node01.mydomain.com",
ref : "origin/master",
repo : "[email protected]:mydomain/mydomain-myapp.git",
path : "/var/production/myapp.mydomain.com-production/",
"post-deploy" : "npm prune && npm install -l && pm2 startOrGracefulReload ecosystem.json --env production",
env : {
NODE_ENV: "production",
PORT: 8000
}
},
staging : {
user : "node",
host : "node01.mydomain.com",
ref : "origin/master",
repo : "[email protected]:mydomain/mydomain-myapp.git",
path : "/var/production/myapp.mydomain.com-staging/",
"post-deploy" : "npm prune && npm install -l && pm2 startOrGracefulReload ecosystem.json --env staging",
env : {
NODE_ENV: "staging",
PORT: 3000
}
}
}
}
Ich kam zu der gleichen Schlussfolgerung und würde mich freuen, eine bessere Lösung zu finden. Vorteil ist, dass die Namen in pm2 unter verschiedenen Namen erscheinen. Z.B. App-Staging und App-Prod – Bryan