Deployment

Local script

/*
 * deploy
 *
 * Deploy a release to the server. Will deploy to a specific sub folder
 * and symlink it as the current release.
 */
var time = new Date().toISOString();
var tmpDir = '/tmp/site' + time;
plan.local('deploy', function(local) {
    local.log('Copying release');
    var files = local.find('autoload.php core export index.php modules profiles robots.txt sites themes update.php vendor web.config -type f | grep -v node_modules | grep -v "sites/default" | grep -v spacecraft', {silent: true,exec: {maxBuffer: 10000*1024}});
    local.transfer(files, tmpDir);

});

var files should containt all those files and folders that we want to deploy to the remote server.

Configuration

1. Add all files and folder that should deployed followed by -type f

autoload.php core export index.php modules profiles robots.txt sites themes update.php vendor web.config -type f

2. Add files and folders that should be ignored, e.g. node_modules

Examples

  1. | grep -v node_modules - All occurences of node_modules (and sub folders) will be ignored
  2. | grep -v "sites/default" - The exact path sites/default will be ignored

Remote script

plan.remote('deploy', function(remote) {
    var root = plan.runtime.options.root;
    var targets = plan.runtime.options.targets;
    var user = plan.runtime.options.user;

    targets.forEach(function(target) {
        var dir = root + '/' + target;
        var release = dir + '/releases/' + time;

        remote.log('Deploying subsite ' + target + ' to ' + release);
        remote.sudo('cp -R ' + tmpDir + ' ' + release, { user: user }, { user: user });

        Object.keys(shared).forEach(function(key) {
            var s = dir + '/shared/' + key;
            var name = shared[key];
            if(name === true) {
                name = key;
            }
            var t = release + '/' + name;
            remote.sudo('ln -s ' + s + ' ' + t, { user: user });
        });

        remote.sudo('rm ' + dir + '/current', { failsafe: true, user: user });
        remote.sudo('ln -s ' + dir + '/releases/' + time + ' ' + dir + '/current', { user: user });

        remote.log('Checking for stale releases');
        var releases = getReleases(remote,dir);
        if (releases.length > config.keepReleases) {
            var removeCount = releases.length - config.keepReleases;
            remote.log('Removing ' + removeCount + ' stale release(s)');
            releases = releases.slice(0, removeCount);
            releases = releases.map(function (item) {
                return dir + '/releases/' + item;
            });
            remote.sudo('rm -rf ' + releases.join(' '));
        }
    });

    remote.rm('-R ' + tmpDir);
});