Deploying Drupal Updates with Gulp

gulpfile.js

var gulp = require('gulp');
var rsync = require('gulp-rsync');
var ssh = require('gulp-ssh')({
  sshConfig: {
    host: 'yourdomain.com',
    username: 'chris',
    privateKey: require('fs').readFileSync(
      process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'] + '/.ssh/id_rsa'
    )
  }
});

/**
 * Put site in maintenance mode
 */
gulp.task('offline', function() {
    return ssh.shell([
      'cd /path/to/your/website',
      'drush vset maintenance_mode 1'
    ]);
});

/**
 * Upload website files 
 */
gulp.task('rsync', ['offline'], function() {
  return gulp.src('htdocs')
    .pipe(rsync({
      root: 'htdocs',
      hostname: 'yourdomain.com',
      username: 'chris',
      destination: '/path/to/your/website',
      recursive: true,
      clean: true,
      exclude: [
        '.git',
        'sites/default/settings.php',
        'sites/default/files/'
      ]
    }));
});

/**
 * Run database updates
 */
gulp.task('update-db', ['rsync'], function() {
  return ssh.shell([
    'cd /path/to/your/website',
    'yes | drush updatedb'
  ]);
});

/**
 * Take site out of maintenance mode
 */
gulp.task('online', ['update-db'], function() {
    return ssh.shell([
      'cd /path/to/your/website',
      'drush vset maintenance_mode 0'
    ]);
});

/**
 * Deploy website update
 */
gulp.task('deploy', ['offline', 'rsync', 'update-db', 'online'], function() {
  console.log('Deployed!');
});

Keywords

  • B-Splines 1
  • Bezier 1
  • Canvas 1 2
  • Curves 1
  • Drupal 1
  • Gulp 1
  • JavaScript 1 2
  • PHP 1
  • Xdebug 1