deployer
deployer copied to clipboard
Group tasks ignore selectors on child tasks
Deployer Version 7.3.1
Group tasks currently ignore any selectors on child tasks, for example considering the following deploy.php:
task('frontend', function() {
output()->writeln('Running task "frontend" on host "' . currentHost()->getHostName() . '"');
})
->select('servertype=frontend');
task('backend', function() {
output()->writeln('Running task "backend" on host "' . currentHost()->getHostName() . '"');
})
->select('servertype=backend');
task('cronjobs', function() {
output()->writeln('Running task "cronjobs" on host "' . currentHost()->getHostName() . '"');
})
->select('servertype=cronjobs');
task('deploy:application', [
'frontend',
'backend',
'cronjobs',
])->select('servertype=frontend,servertype=backend,servertype=cronjobs');
host('frontend')->set('labels', ['servertype' => 'frontend']);
host('backend')->set('labels', ['servertype' => 'backend']);
host('cronjobs')->set('labels', ['servertype' => 'cronjobs']);
Running this with dep deploy:application will lead to the output:
Running task "frontend" on host "frontend"
Running task "frontend" on host "backend"
Running task "frontend" on host "cronjobs"
Running task "backend" on host "frontend"
Running task "backend" on host "backend"
Running task "backend" on host "cronjobs"
Running task "cronjobs" on host "frontend"
Running task "cronjobs" on host "backend"
Running task "cronjobs" on host "cronjobs"
But the expected output is:
Running task "frontend" on host "frontend"
Running task "backend" on host "backend"
Running task "cronjobs" on host "cronjobs"
Is this behaviour intended?
If yes, I suggest adding it to the documentation, currently nothing about it is mentioned.
Otherwise I suggest checking the selectors in the GroupTask::run() method:
public function run(Context $context): void
{
$host = $context->getHost();
foreach ($this->group as $item) {
if(Selector::apply(task($item)->getSelectors(), $host)) {
invoke($item);
}
}
}
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
I had expected that the child tasks would be checked again to see if they were allowed to run on the respective host and was surprised to find that this was not the case and that tasks were being run on hosts on which they were not supposed to run.