Skip to content

Instantly share code, notes, and snippets.

@esender
Last active December 25, 2021 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save esender/cba7fbb6099cf17dea7f to your computer and use it in GitHub Desktop.
Save esender/cba7fbb6099cf17dea7f to your computer and use it in GitHub Desktop.
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