Create a gist now

Instantly share code, notes, and snippets.

@esender /deploy.js
Last active Jan 13, 2016

What would you like to do?
Simple deploy tasks for Gulp
'use strict';
var gulp = require('gulp');
var path = require('path');
var GulpSSH = require('gulp-ssh');
var shell = require('gulp-shell');
var moment = require('moment');
var config = {
host: '192.168.0.1',
port: 22,
username: 'username',
agent: process.env.SSH_AUTH_SOCK
};
var archiveName = 'deploy.tgz';
var timestamp = moment().format('YYYYMMDDHHmmssSSS');
var buildPath = './dist';
var rootPath = '/home/project/root/directory/';
var releasesPath = rootPath + 'releases/';
var symlinkPath = rootPath + 'current';
var releasePath = releasesPath + timestamp;
var gulpSSH = new GulpSSH({
ignoreErrors: false,
sshConfig: config
});
gulp.task('deploy:compress', ['build'], shell.task("tar -czvf ./" + archiveName + " --directory=" + buildPath + " ."));
gulp.task('deploy:prepare', function() {
return gulpSSH.exec("cd " + releasesPath + " && mkdir " + timestamp);
});
gulp.task('deploy:upload', ['deploy:prepare', 'deploy:compress'], function() {
return gulp.src(archiveName)
.pipe(gulpSSH.sftp('write', releasePath + '/' + archiveName))
});
gulp.task('deploy:uncompress', ['deploy:upload'], function() {
return gulpSSH.exec("cd " + releasePath + " && tar -xzvf " + archiveName);
});
gulp.task('deploy:symlink', ['deploy:uncompress'], function() {
return gulpSSH.exec("rm " + symlinkPath + " &&" +
" ln -s " + releasePath + " " + symlinkPath);
});
gulp.task('deploy:clean', ['deploy:symlink'], shell.task('rm ' + archiveName, {ignoreErrors: true}));
gulp.task('clean:build', ['deploy:symlink'], function () {
return gulp.start('clean')
});
gulp.task('deploy', ['build',
'deploy:compress',
'deploy:prepare',
'deploy:upload',
'deploy:uncompress',
'deploy:symlink',
'deploy:clean',
'clean:build']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment