Created
April 15, 2020 18:17
-
-
Save dylangolow/c9116406ce0a0dbce117b80e307f8296 to your computer and use it in GitHub Desktop.
pm2 ecosystem sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BRANCH = 'demo-app'; | |
const REPO = 'git@gitlab.com:path/to/repo.git'; | |
const DEPLOY_PATH = '/home/ec2-user/AWS_PATH'; | |
const HOST = 'APP.YOUR_URL.COM'; | |
const USER = 'ec2-user'; // AWS user | |
module.exports = { | |
apps: [{ | |
name: 'API', | |
script: 'dist/server.js', | |
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/ | |
args: 'one two', | |
instances: 1, | |
autorestart: true, | |
watch: false, | |
max_memory_restart: '1G', | |
env: { | |
NODE_ENV: 'development' | |
}, | |
env_production: { | |
NODE_ENV: 'production' | |
} | |
}], | |
deploy: { | |
production: { | |
user: USER, | |
host: HOST, | |
ref: "origin/" + BRANCH, | |
repo: REPO, | |
path: DEPLOY_PATH, | |
// rm -rf ${DEPLOY_PATH}/* | |
"pre-setup" : `echo 'pre-setup'; echo 'clearing DEPLOY_PATH folder'; rm -rf ${DEPLOY_PATH}/*`, | |
// Commands / path to a script on the host machine | |
// This will be executed on the host after cloning the repository | |
// eg: placing configurations in the shared dir etc | |
// "post-setup": "echo 'post-setup'; ls -la", | |
// Commands to execute locally (on the same machine you deploy things) | |
// Can be multiple commands separated by the character ";" | |
"pre-deploy-local" : `echo 'pre-deploy-local'`, | |
// "pre-deploy": "git fetch --all; git checkout demo-app; echo `git branch`", | |
"post-deploy": "npm i --no-optional && npm run build && pm2 start ecosystem.config.js --env production --time && pm2 save" | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment