I would like to know how to use pm2 to "rollback" a recent code change.
Our team's change process requires us to have a "rollback" plan in the case of a problem with a deploy. We normally just document that the rollback plan will be to git checkout CHANGESET to go back to the previous version of the code while we fix the issue and test it in dev.
How can I achieve a similar rollback using pm2? Our new-ish deploy process is pm2 deploy production and my ecosystem.json is included below. Currently both UAT and production use origin/master as the "ref". I was thinking maybe to use a tag or something, but not sure the best approach. Perhaps I should just continue to do a git checkout COMMIT in these rare rollback cases, but looking for other ideas.
{
"apps": [{ blah... }],
"deploy": {
"UAT": {
"user": "USER_HERE",
"host": ["IP_HERE", "IP_HERE"],
"ref": "origin/master",
"repo": "[email protected]:USER/REPO.git",
"path": "/home/USER/node",
"post-deploy": "bash ./update.sh"
},
"production": {
"user": "USER_HERE",
"host": ["IP_HERE", "IP_HERE"],
"ref": "origin/master",
"repo": "[email protected]:USER/REPO.git",
"path": "/home/USER/node",
"post-deploy": "bash ./update.sh"
}
}
The tool pm2 deploy provides the command revert. So, you can do:
pm2 deploy ecosystem.json revert
This "rollback" your app to the previous deploy. You can specify also how many last deployment revert to.
See also the command [ref] combined with list, curr or prev:
https://github.com/Unitech/PM2/blob/0.14.7/ADVANCED_README.md#deployment-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With