deployer icon indicating copy to clipboard operation
deployer copied to clipboard

multiple select on deploy task executes tasks that are exclusive for single host

Open hardikdangar opened this issue 3 years ago • 9 comments

  • Deployer version: Deployer 7.0.0
  • Deployment OS: Ubuntu 20.04.4 LTS

`<?php namespace Deployer;

require 'recipe/laravel.php';

// Config

set('repository', '[email protected]:user/repo.git'); add('shared_files', []); add('shared_dirs', ['public/uploads']); add('writable_dirs', []);

// Hosts

host('setup') ->setHostname('newpanda') ->set('labels', ['stage' => 'setupnode']) ->set('deploy_path', '/home/panda/code/flow/setup');

host('host1') ->setHostname('newpanda') ->set('labels', ['stage' => 'prod']) ->set('deploy_path', '/home/panda/code/flow/host1');

host('host2') ->setHostname('newpanda') ->set('labels', ['stage' => 'prod']) ->set('deploy_path', '/home/panda/code/flow/host2');

host('staging') ->setHostname('newpanda') ->set('branch','staging') ->set('labels', ['stage' => 'staging']) ->set('deploy_path', '/home/panda/code/flow/staging');

after('deploy:failed', 'deploy:unlock');

task('custom:task',function(){ writeln(' current path is : {{release_path}}'); })->select('stage=setupnode');

task('deploy', [ 'deploy:prepare', 'custom:task', 'deploy:publish' ])->select('stage=prod, stage=setupnode');

task('deploystaging', [ 'deploy:prepare', 'deploy:vendors', 'deploy:publish'
])->select('stage=staging');`

If you look at this example, if i run dep deploy all it will run custom task(custom:task) on all three hosts whereas if you look the task defination i have specified stage in that task using select so it should run on stage setupnode only.

if i remove ->select('stage=prod, stage=setupnode') line from deploy task group it works perfectly. but i need to run my deploy task in only those two groups. I am assuming this is a bug. please correct me if it is not.

hardikdangar avatar Aug 03 '22 14:08 hardikdangar

Can you create a simple test case to show the issue?

antonmedv avatar Aug 03 '22 18:08 antonmedv

@antonmedv Here is simple gist you can execute in your local environment, https://gist.github.com/hardikdangar/3048eaed1afee35464335c612b30b8d3

now when you run dep deployer all it executes 'custom:task' but if you see the output,

$ dep deploy all -v task custom:task [host1] executed [setup] executed [host2] executed

You can see it executes in all three hosts but in custom:task i have set ->select('stage=setupnode') so it should execute for only that node. I tried to debug this but couldn't understand this behaviour because if i remove ->select('stage=prod, stage=setupnode') from deploy task it works exactly as expected.

hardikdangar avatar Aug 04 '22 06:08 hardikdangar

I see. This is because how group tasks are working. Selectors are passed from top to buttom:

https://github.com/deployphp/deployer/blob/0e8356cbdc1b708f44503cde2781949dde04d369/src/Task/ScriptManager.php#L98

antonmedv avatar Aug 04 '22 07:08 antonmedv

so is there a way around this? as i want to run that task on single host only.

hardikdangar avatar Aug 04 '22 07:08 hardikdangar

Just remove select from the group task. Or create a second group task on top and move the task there.

antonmedv avatar Aug 04 '22 10:08 antonmedv

that would require me to run two diffrent commands when i want to deploy. isn't there a way to do this in simpler manner? Or is there a way to exclude domain instead of select ?

hardikdangar avatar Aug 04 '22 10:08 hardikdangar

okay so i found a hack. i have added once() after ->select('stage=setupnode')->once() so it will executed only once. and that is what i want. although this is not a solution to this problem but for my usecase it works.

@antonmedv i can clarify this in docs. but i am new to this repo. is there a separate repo for documentation ?

hardikdangar avatar Aug 04 '22 11:08 hardikdangar

Its same repo, docs folder. If I can understand you problem more, maybe some solution can be implemented.

Right now I don’t get the select on group.

antonmedv avatar Aug 04 '22 12:08 antonmedv

@antonmedv Yeah so let me explain what i am trying to do.

I have server with similar laravel structure and similar code they all have diffrent directories i.e. abc.host.com, xyz.host.com. I want to share node_modules and composer vendor folder using symlink between all of them so i have created setup host and in that host i am doing composer install and npm install and then switching symlinks between all hosts.

so i need to run certain tasks in only one setup node like composer install and npm install and then use symlink to all other hosts.

but then i have staging server which will have always diffrent composer.json and node modules as it will have latest features and it is on the same server. so i don't want to run my deploy tasks on that server so what i did

task('deploy', [ ... ])->select('stage=prod, stage=setupnode');

task('deploystaging', [ ... ])->select('stage=staging');`

So i encountered this bug and so this issue as my deploy task executes that function. I hope this makes sense now. let me know if you think i can approach this some other way.

hardikdangar avatar Aug 04 '22 12:08 hardikdangar

Added documentation https://deployer.org/docs/7.x/selector

antonmedv avatar Sep 09 '22 17:09 antonmedv