Skip to content

Instantly share code, notes, and snippets.

@gcamrit
Last active August 29, 2015 14:22
Show Gist options
  • Save gcamrit/8d24a8a707bcbded0f7d to your computer and use it in GitHub Desktop.
Save gcamrit/8d24a8a707bcbded0f7d to your computer and use it in GitHub Desktop.
/**
* Created by amrit on 2/12/15.
*/
var plan = require('flightplan');
plan.target('demo-beehrm', [
{
host: 'host',
username: 'username',
password: 'password',
agent: process.env.SSH_AUTH_SOCK
},
], {
webRoot: '/home/beehrm/www/demo/'
});
// run commands on localhost
plan.local(['sync-dbm'], function (local) {
var includeVendor = local.prompt('Do you want to pull files from git ? [yes]');
if (includeVendor.indexOf('yes') !== -1) {
local.log('Pulling latest files from git');
local.exec('git pull');
local.log('Pulled latest files from git');
}
var includeVendor = local.prompt('Do you want to run composer update ? [yes]');
if (includeVendor.indexOf('yes') !== -1) {
local.exec('sudo composer update');
}
local.log('Optimizing Laravel Framework');
local.exec('php artisan optimize --force');
local.log('Optimization finished');
var includeVendor = local.prompt('Do you want to upload vendor directory ? [yes]');
if (includeVendor.indexOf('yes') === -1) {
var search = 'git ls-files';
} else {
local.log('Including vendor directory too :)');
var search = 'git ls-files;find vendor -type f';
}
local.log('Searching for file to upload');
var filesToCopy = local.exec(search, {silent: true});
// rsync files to all the destination's hosts
local.log('Search Complete.........');
var webRoot = plan.runtime.options.webRoot;
local.log('Uploading files to :: ' + webRoot);
local.transfer(filesToCopy, webRoot);
local.log('Uploading Complete.......');
});
// run commands on the target's remote hosts
plan.remote(['sync-dbm'], function (remote) {
var webRoot = plan.runtime.options.webRoot;
remote.log('changing permission of all files to 644');
remote.exec('find ' + webRoot + ' -type f -exec chmod 644 {} +');
remote.log('changing permission of all folders to 755');
remote.exec('find ' + webRoot + ' -type d -exec chmod 755 {} +');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment