18 апреля, 2015

How to deploy node / iojs application to production server



This guide will lead you through the process of node.js / io.js application deployment to production server using pm2

You'll need to:
1. install pm2:

$ npm i -g pm2

2. Generate ssh key for server on localhost

3. If you are using private git repository, generate ssh key for git server on your server (github guide)

Then $ cd /to/your/app and generate sample ecosystem.json file

$ pm2 ecosystem

Modify ecosystem.json file according your needs, don't forget to specify your server ssh key:

  "production" : {
      "key"  : "/path/to/some.pem",

Commit and push your ecosystem.json file. Now you are ready to initialize remote app:

$ pm2 deploy ecosystem.json production setup

This command will clone your app from git repository to your server. Now you are ready to start your app:

$ pm2 deploy ecosystem.json production update

This command trigger post-deploy commands, specified in config
"post-deploy" : "pm2 startOrRestart ecosystem.json --env production"

You can modify this setting to something like (if you are using nvm):
"post-deploy": "source ~/.nvm/nvm.sh && npm install && pm2 startOrRestart ecosystem.json --env production"

Because current pm2-deploy version ignores bash variables (#issue 41) so you can't install your packages with npm.

Комментариев нет:

Отправить комментарий