trešdiena, 2014. gada 3. septembris

My deployment configuration files for node/express angularjs fullstack project.

As documentation for myself. I wanted easy way to deploy my angularjs-fullstack (https://github.com/DaftMonk/generator-angular-fullstack) application to any ssh host.

Serverside

For deployment and app to work we need node installed. For starting (and keep running :) ) serverside I use upstart and forever (node app). Here goes configuration (stored at /etc/init/node-upstart-script.conf):

# /etc/init/node-upstart-script.conf
description "yourapp web application"
author "Gints Polis "

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

script
    export NODE_ENV=production

    cd /var/yourapp/current/
    exec sudo -u deploy_user NODE_ENV=production FACEBOOK_ID=your_fb_id DOMAIN=http://your_full_host_name_with_port FACEBOOK_SECRET=your_facebook_secret forever start -l "/var/log/node/yourapp.log" -a server/app.js >> /var/log/node/yourapp.log 2>&1
end script

This way you can start (enable sudo for this command to application user)

sudo start node-upstart-script

and stop your app:

forever stopall

Buildmachine

For ssh deploy I use project https://github.com/dasuchin/grunt-ssh-deploy. They lately implemented post and pre scripts to use after ssh deployments.
When this is added to your project you have to put deployment enviroment in Grunt.js file:

    environments: {
      staging: {
        options: {
          host: 'your_hostname',
          username: 'deploy_user',
          port: 22,
          password: grunt.option('password'),
          privateKey: grunt.option('keyfile') ? require('fs').readFileSync(grunt.option('keyfile')) : undefined,
          deploy_path: '/var/yourapp',
          local_path: 'dist',
          current_symlink: 'current',
          debug: true,
          run_before: 'forever stopall',
          run_after: 'cd /var/yourapp/current && npm install && sudo start node-upstart-script'
        }
      }
    },

After this you can deploy your project by issuing:

grunt ssh_deploy:staging --keyfile=/path/to/your/key/file