I would like to deploy staging and production on the same server with different names, but i don't see anyway to achieve this given the documentation for pm2 ecosystem files. here is my ecosystem.config.js
below:
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'
}
}
};
Is there anyway i might achieve this, given that deploy
config doesn't give name
as an option?
I made different app name in my project but i don't use pm2 deloy, hope that you can use the same way for different app name based on environment,
First you need run deloy command from npm script, because you can attach env to it)
{
"scripts": {
"deloy:staging": "cross-env NODE_ENV=staging pm2 deploy ecosystem.config.js staging",
"deloy:prod": "cross-env NODE_ENV=production pm2 deploy ecosystem.config.js production",
},
"devDependencies": {
"cross-env": "^5.2.0",
}
}
Then just use NODE_ENV for making different app name in ecosystem.config.js:
const name = 'frontend_' + process.env.NODE_ENV
module.exports = {
apps : [{
name: name,
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'
}
}
};