Skip to content

Instantly share code, notes, and snippets.

@alexventuraio
Forked from learncodeacademy/flightplan-deploy.md
Created September 22, 2016 05:17
Show Gist options
  • Save alexventuraio/2a524774be38e16d4b5984f7b244884a to your computer and use it in GitHub Desktop.
Save alexventuraio/2a524774be38e16d4b5984f7b244884a to your computer and use it in GitHub Desktop.

Revisions

  1. @learncodeacademy learncodeacademy revised this gist Dec 15, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions flightplan-deploy.md
    Original file line number Diff line number Diff line change
    @@ -21,21 +21,21 @@ var tmpDir = appName+'-' + new Date().getTime();
    plan.target('staging', [
    {
    host: '104.131.93.214',
    username: 'deploy',
    username: username,
    agent: process.env.SSH_AUTH_SOCK
    }
    ]);

    plan.target('production', [
    {
    host: '104.131.93.215',
    username: 'deploy',
    username: username,
    agent: process.env.SSH_AUTH_SOCK
    },
    //add in another server if you have more than one
    // {
    // host: '104.131.93.216',
    // username: 'deploy',
    // username: username,
    // agent: process.env.SSH_AUTH_SOCK
    // }
    ]);
  2. @learncodeacademy learncodeacademy revised this gist Dec 15, 2014. 1 changed file with 21 additions and 26 deletions.
    47 changes: 21 additions & 26 deletions flightplan-deploy.md
    Original file line number Diff line number Diff line change
    @@ -9,41 +9,36 @@
    - create a flightplan.js file

    ```javascript
    var Flightplan = require('flightplan');
    var plan = require('flightplan');

    var appName = 'node-app';
    var username = 'deploy';
    var startFile = 'bin/www';

    var tmpDir = appName+'-' + new Date().getTime();

    var plan = new Flightplan();

    // configuration
    plan.briefing({
    debug: false,
    destinations: {
    'staging': {
    host: '104.131.93.214',
    username: 'deploy',
    agent: process.env.SSH_AUTH_SOCK
    },
    'production': [
    {
    host: '104.131.93.215',
    username: 'deploy',
    agent: process.env.SSH_AUTH_SOCK
    },
    //add in another server if you have more than one
    // {
    // host: '104.131.93.216',
    // username: 'deploy',
    // agent: process.env.SSH_AUTH_SOCK
    // }

    ]
    plan.target('staging', [
    {
    host: '104.131.93.214',
    username: 'deploy',
    agent: process.env.SSH_AUTH_SOCK
    }
    });
    ]);

    plan.target('production', [
    {
    host: '104.131.93.215',
    username: 'deploy',
    agent: process.env.SSH_AUTH_SOCK
    },
    //add in another server if you have more than one
    // {
    // host: '104.131.93.216',
    // username: 'deploy',
    // agent: process.env.SSH_AUTH_SOCK
    // }
    ]);

    // run commands on localhost
    plan.local(function(local) {
  3. @learncodeacademy learncodeacademy revised this gist Oct 16, 2014. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion flightplan-deploy.md
    Original file line number Diff line number Diff line change
    @@ -74,4 +74,7 @@ plan.remote(function(remote) {
    ```

    ##Deploy!
    - `fly staging` or `fly production`
    - `fly staging` or `fly production`

    ##Take it to the next level
    [Run your node app as a system service so it runs after server reboots](https://gist.github.com/learncodeacademy/3a96aa1226c769adba39)
  4. @learncodeacademy learncodeacademy renamed this gist Oct 16, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @learncodeacademy learncodeacademy revised this gist Oct 15, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion flightplay-deploy.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ##Setup your server
    (this would ideally be done with automated provisioning)
    - add a deploy user with password-less ssh
    - add a deploy user with password-less ssh [see this gist](https://gist.github.com/learncodeacademy/3cdb928c9314f98404d0)
    - install forever `npm install -g forever`

    ##Install flightplan
  6. @learncodeacademy learncodeacademy created this gist Oct 15, 2014.
    77 changes: 77 additions & 0 deletions flightplay-deploy.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    ##Setup your server
    (this would ideally be done with automated provisioning)
    - add a deploy user with password-less ssh
    - install forever `npm install -g forever`

    ##Install flightplan
    - `npm install -g flightplan`
    - in your project folder `npm install flightplan --save-dev`
    - create a flightplan.js file

    ```javascript
    var Flightplan = require('flightplan');

    var appName = 'node-app';
    var username = 'deploy';
    var startFile = 'bin/www';

    var tmpDir = appName+'-' + new Date().getTime();

    var plan = new Flightplan();

    // configuration
    plan.briefing({
    debug: false,
    destinations: {
    'staging': {
    host: '104.131.93.214',
    username: 'deploy',
    agent: process.env.SSH_AUTH_SOCK
    },
    'production': [
    {
    host: '104.131.93.215',
    username: 'deploy',
    agent: process.env.SSH_AUTH_SOCK
    },
    //add in another server if you have more than one
    // {
    // host: '104.131.93.216',
    // username: 'deploy',
    // agent: process.env.SSH_AUTH_SOCK
    // }

    ]
    }
    });

    // run commands on localhost
    plan.local(function(local) {
    // uncomment these if you need to run a build on your machine first
    // local.log('Run build');
    // local.exec('gulp build');

    local.log('Copy files to remote hosts');
    var filesToCopy = local.exec('git ls-files', {silent: true});
    // rsync files to all the destination's hosts
    local.transfer(filesToCopy, '/tmp/' + tmpDir);
    });

    // run commands on remote hosts (destinations)
    plan.remote(function(remote) {
    remote.log('Move folder to root');
    remote.sudo('cp -R /tmp/' + tmpDir + ' ~', {user: username});
    remote.rm('-rf /tmp/' + tmpDir);

    remote.log('Install dependencies');
    remote.sudo('npm --production --prefix ~/' + tmpDir + ' install ~/' + tmpDir, {user: username});

    remote.log('Reload application');
    remote.sudo('ln -snf ~/' + tmpDir + ' ~/'+appName, {user: username});
    remote.exec('forever stop ~/'+appName+'/'+startFile, {failsafe: true});
    remote.exec('forever start ~/'+appName+'/'+startFile);
    });
    ```

    ##Deploy!
    - `fly staging` or `fly production`