Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow task servers to override story servers #128

Closed
amsoell opened this issue Dec 7, 2018 · 8 comments
Closed

Allow task servers to override story servers #128

amsoell opened this issue Dec 7, 2018 · 8 comments

Comments

@amsoell
Copy link

amsoell commented Dec 7, 2018

Happy to take a stab at a PR here but I wanted to confirm I wasn't missing something. Consider the case where you want to update multiple staging servers, and as part of it download a production db snapshot and restore it to staging:

@servers(['staging-servers' => ['alpha.staging.example.com', 'beta.staging.example.com'], 'staging-primary' => 'alpha.staging.example.com'])

@story('stage', [ 'on' => 'staging-servers' ])
    down
    pull
    dependencies
    restoredb
    migrate
    up
@endstory

Most of these task, of course, we want to run on all servers. However, we have a "restoredb" task that grabs the latest production database backup and restores it to staging, so we can work with the latest data. We obviously only want this to run one time.

I would expect that I could override the on setting on the restoredb task specifically:

@task('restoredb', [ 'on' => 'staging-primary' ])
    ...
@endtask

But that doesn't seem to work. So first, is this expected? Second, if it is expected, is there a different way we ought go about this, and is there a downside to changing behavior so it does work this way?

@driesvints
Copy link
Member

I think you've misread the docs a bit. Can you try the example from below?

@servers(['staging1' => 'alpha.staging.example.com', 'staging2' => 'beta.staging.example.com'])

@story('stage', [ 'on' => ['staging1', 'staging2'])
    down
    pull
    dependencies
    restoredb
    migrate
    up
@endstory

@task('restoredb', [ 'on' => 'staging1'])
    ...
@endtask

@amsoell
Copy link
Author

amsoell commented Dec 7, 2018

@driesvints Here's an easier example, which I think fits your format:

@servers(['amsoell' => 'amsoell.com', 'plexz' => 'asteria.feralhosting.com'])

@story('deploy', ['on' => ['amsoell', 'plexz']])
    touch1
    touch2
@endstory

@task('touch1')
    touch one
@endtask

@task('touch2', ['on' => 'plexz'])
    touch two
@endtask

When I run this and check the amsoell.com server I see both files, which should not be the case.

@driesvints
Copy link
Member

driesvints commented Dec 7, 2018

Okay, I went through the internals a bit and managed to figure out what's wrong. Because of the line below, the macro/story options always overwrite the task options. I'm not sure what the correct expectation would be. Either the current behavior or the other way around.

$options = array_merge($this->getTaskOptions($task), $macroOptions);

I any case if we were to flip the params in the array_merge I believe it would use the behavior you described above. However, this would be a severe breaking change and would have to target the next major version at least. At the moment I'm not sure if it's wise to change it. We'll need some more opinions on this first.

I'll mark this as an enhancement since it's not actually a bug.

@amsoell
Copy link
Author

amsoell commented Dec 7, 2018

Thanks for checking into that for me. I can’t imagine a scenario where someone would want the story servers to override task, but I suppose that doesn’t mean they don’t exist.

Short of changing this, if I put the work on not adding a single_server argument similar to the parallel argument, would that be viewed as a good, merge-worthy feature?

@driesvints
Copy link
Member

@amsoell I don't think so. It'll be a band-aid for the real problem. I don't think it'd get merged.

@driesvints
Copy link
Member

I've sent in a PR for this here: #157

@driesvints
Copy link
Member

We've reverted this as this started to break people's apps. We won't be reconsidering this sorry.

#186

@Tofandel
Copy link

Tofandel commented Apr 27, 2022

Well actually there could have been a way to fix the issue without reverting the change, the problem seems to be that the task has a default 'on' when not specified which targets all server, and so the story 'on' gets overridden even though there is no 'on', this could have been caught with some unit test, the default 'on' should only be applied after merge

But ideally we could just look for an option in story called opts_override and if set to false change the inheritance behaviour which wouldn't be a breaking change

Because right now file inheritance is unusable because of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants