Tasks

Define you own tasks, use the task function. Also you can setup description for task with desc function:

desc('My task');
task('my_task', function () {
    run(...);
});

To run your tasks:

dep my_task

To list all available commands:

dep list

To run a task only on a specified server or stage:

dep deploy main

If you task contains only run calls or just one bash command, you can simplify task definition:

task('build', 'npm build');

Or you can use multi line script:

task('build', '
    gulp build;
    webpack -p;
    echo "Build done";
');

Task grouping

You can combine tasks in groups:

task('deploy', [
    'deploy:prepare',
    'deploy:update_code',
    'deploy:vendors',
    'deploy:symlink',
    'cleanup'
]);

Before and after

You can define tasks to be run before or after some tasks.

task('deploy:done', function () {
    write('Deploy done!');
});

after('deploy', 'deploy:done');

After the deploy task is be called, deploy:done will be executed.

Only on

You can specify on which server to run task with onlyOn method:

desc('Run tests for application.');
task('test', function () {
    ...
})->onlyOn('test_server');

Also you can specify a group of servers to run as arguments: onlyOn('server1', 'server2', ...) or as an array onlyOn(['server1', 'server2', ...]).

To run task only on specified stages use onlyForStage:

task('notify', function () {
    ...
})->onlyForStage('prod');

Also you can specify a group of stages to run as arguments: onlyForStage('stage1', 'stage2', ...) or as an array onlyForStage(['stage1', 'stage2', ...]).

Once

Mark task once to run it locally and only one time, independent of servers count.

task('notify', function () {
    ...
})->once();

Note what calling run inside that task will have same effect as calling runLocally.

Reconfigure

You can reconfigure tasks, e.g. provided by 3rd part recipes by retrieving them by name:

task('notify')->onlyOn([
  'firstserver',
  'thirdserver',
]);

Using input options

You can define additional input options and arguments, before defining tasks:

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

argument('stage', InputArgument::OPTIONAL, 'Run tasks only on this server or group of servers.');
option('tag', null, InputOption::VALUE_OPTIONAL, 'Tag to deploy.');

To get the input inside a task this can be used:

task('foo:bar', function() {
    // For arguments
    $stage = null;
    if (input()->hasArgument('stage')) {
        $stage = input()->getArgument('stage');
    }

    // For option
    $tag = null;
    if (input()->hasOption('tag')) {
        $tag = input()->getOption('tag');
    }
}

Parallel task execution

When deploying to multiple server, Deployer will run by one task on each server:

Task 1 Task 1 Task 1 Task 1 Task 2 Task 2 Task 2 Task 2 Server 1 Server 2 Server 3 Server 4

To speedup deployment add --parallel or -p option with will run tasks in parallel on each server. If one of server executing task longer then another, Deployer will wait until all servers finish tasks.

Task 1 Task 1 Task 1 Task 1 Task 2 Task 2 Task 2 Task 2 Server 1 Server 2 Server 3 Server 4

Next: servers configuration.