Skip to content

Instantly share code, notes, and snippets.

@bradyvercher
Created June 1, 2015 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradyvercher/5aaa4a4fcbb39f73e473 to your computer and use it in GitHub Desktop.
Save bradyvercher/5aaa4a4fcbb39f73e473 to your computer and use it in GitHub Desktop.
Cedaro Blog: Deploying packages with Shipit.js
{
"name": "project-name",
"version": "1.0.0",
"devDependencies": {
"moment": "^2.10.3",
"shipit-cli": "^1.2.1"
}
}
var moment = require( 'moment' ),
package = require( __dirname + '/package.json' ),
path = require( 'path' );
module.exports = function ( shipit ) {
shipit.initConfig({
staging: {
servers: 'staging.example.com',
deployRoot: '/srv/www/staging.example.com/deploy/themes/',
publicPath: '/srv/www/staging.example.com/public/wp-content/themes/'
}
});
shipit.task( 'deploy', function() {
shipit.archiveFile = package.name + '-' + package.version + '.zip';
shipit.deployPath = shipit.config.deployRoot + package.name + '/releases/';
return createDeploymentPath()
.then( copyProject )
.then( unpackDeployment )
.then( updateSymlink )
.then( cleanOldReleases );
});
function createDeploymentPath() {
return shipit.remote( 'mkdir -p ' + shipit.deployPath );
}
function copyProject() {
return shipit.remoteCopy( 'dist/' + shipit.archiveFile, shipit.deployPath );
}
function unpackDeployment() {
var cmd = [];
shipit.deployTime = moment().utc().format( 'YYYYMMDDHHmmss' );
cmd.push( 'cd ' + shipit.deployPath );
cmd.push( 'unzip -q ' + shipit.archiveFile );
cmd.push( 'mv ' + package.name + ' ' + shipit.deployTime );
cmd.push( 'rm ' + shipit.archiveFile );
return shipit.remote( cmd.join( ' && ' ) );
}
function updateSymlink() {
var cmd = [];
cmd.push( 'cd ' + shipit.config.publicPath );
cmd.push( 'ln -sn ' + shipit.deployPath + shipit.deployTime + ' ' + package.name + '-temp' );
cmd.push( 'mv -T ' + package.name + '-temp ' + package.name );
return shipit.remote( cmd.join( ' && ' ) );
}
function cleanOldReleases() {
var cmd = '';
cmd += '(';
cmd += 'ls -rd ' + shipit.deployPath + '*|head -n 5;';
cmd += 'ls -d ' + shipit.deployPath + '*';
cmd += ')';
cmd += '|sort|uniq -u|xargs rm -rf';
return shipit.remote( cmd );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment