Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Deprecate local recipe #125

Closed
3 tasks done
antonmedv opened this issue Apr 4, 2017 · 15 comments
Closed
3 tasks done

Deprecate local recipe #125

antonmedv opened this issue Apr 4, 2017 · 15 comments

Comments

@antonmedv
Copy link
Member

antonmedv commented Apr 4, 2017

Now local recipe is a copy of common recipe with replaced run calls by runLocally calls.
I would like to leave only one copy of those recipes – common.

To do so, in Deployer v5 was introduced task(...)->local() api.

@johnny-bit @nickdenardis let's talk about it.

For example, to make a task local:

task('deploy:update_code')->local();

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

But now it will not work, because localhost created inside SeriesExecutor and you can't set proper deploy_path for it.

Maybe to solve it lets run all local tasks on first localhost if deployer->hosts? Then this will be possible:

localhost()->set('deploy_path', '/some/build/path');

Main goal to achieve easily configuration of tasks.

For example. Simple recipe there deploy process split into two phases: build and deploy:

task('build', [
    'deploy:update_code',
    'deploy:vendors',
    'yarn:install',
    'npm:build',
    'deploy:clear_paths',
])->local();

task('deploy', [
    'deploy:prepare',
    'deploy:release',
    'rsync',
    'deploy:shared',
    'deploy:writable',
    'deploy:symlink',
    'cleanup',
    'success'
]);

before('deploy', 'build');

But now it does not work, group tasks doesn't supports become local. (what to do if one task persists in two groups: one local, one remote?)

So, what I propose to do:

  • Run all local() task on first defined localhost()
  • Allow group task to become local
  • Check all common task if they can be ran locally and what config they require
@johnny-bit
Copy link
Contributor

johnny-bit commented Apr 4, 2017 via email

@nickdenardis
Copy link
Contributor

I agree with @johnny-bit this sounds like a good idea.

I'm not as familiar with the inner workings of deployer, need to get up to speed with the v5 codebase.

But that two phase example you provided is spot on!

@antonmedv
Copy link
Member Author

antonmedv commented Apr 8, 2017

I found a nice solution without complicating code. I think what build always should be performed on one host.

task('build', function () {
    set('deploy_path', __DIR__ . '/.build');
    invoke('deploy:prepare');
    invoke('deploy:release');
    invoke('deploy:update_code');
    invoke('deploy:vendors');

    $releasePath = get('release_path');
    on(Deployer::get()->hosts, function () use ($releasePath) {
        set('build_path', "$releasePath/");
    });
})->local();

task('upload', function () {
    upload('{{build_path}}', '{{release_path}}');
});

task('deploy', [
    'deploy:prepare',
    'deploy:release',
    'upload',
    'deploy:shared',
    'deploy:writable',
    'deploy:symlink',
    'cleanup',
    'success'
]);

before('deploy', 'build');

And this is already working! More, it's possible to specify different host for as build machine(!) not only localhost.

task('build', function () {
    invoke('deploy:prepare');
    invoke('deploy:release');
    invoke('deploy:update_code');
    invoke('deploy:vendors');

    $releasePath = get('release_path');
    on(roles('app'), function () use ($releasePath) {
        set('build_path', "$releasePath/");
    });
})->onRoles('build');

@johnny-bit
Copy link
Contributor

johnny-bit commented Apr 8, 2017 via email

@antonmedv
Copy link
Member Author

antonmedv commented Apr 8, 2017

Or even simpler(!)

task('build', function () {
    set('deploy_path', __DIR__ . '/.build');
    invoke('deploy:prepare');
    invoke('deploy:release');
    invoke('deploy:update_code');
    invoke('deploy:vendors');
    invoke('deploy:symlink');
})->local();

task('upload', function () {
    upload(__DIR__ . "/.build/current/", '{{release_path}}');
});

task('deploy', [
    'build',
    'deploy:prepare',
    'deploy:release',
    'upload',
    'deploy:shared',
    'deploy:writable',
    'deploy:symlink',
    'cleanup',
    'success'
]);

Works as a charm.

@antonmedv
Copy link
Member Author

@johnny-bit
Copy link
Contributor

Migrating from "old" ways would be great too ;)

@antonmedv
Copy link
Member Author

@johnny-bit can you write about it in UPGRADE.md later? :)

@johnny-bit
Copy link
Contributor

johnny-bit commented Apr 8, 2017 via email

@nickdenardis
Copy link
Contributor

I really like the direction of this!

The deploy path switching makes sense now that I see the second example, much cleaner.

If I can help let me know, I may have some time in the next week or two, hopefully.

@antonmedv
Copy link
Member Author

@nickdenardis will be cool if you can write new article about new local deploy strategy. Also planning to release v5 on next weeks.

@nickdenardis
Copy link
Contributor

@antonmedv for sure, not a problem :)

@lorisleiva
Copy link

Hello, thank you for this helpful thread. How difficult would it be to add a set method on the Deployer\Task\Task class, that redefines a variable only inside that task?

This would enable us to transform

task('build', function () {
    set('deploy_path', __DIR__ . '/.build');
    invoke('deploy:prepare');
    invoke('deploy:release');
    invoke('deploy:update_code');
    invoke('deploy:vendors');
    invoke('deploy:symlink');
})->local();

into

task('build', [
    'deploy:prepare',
    'deploy:release',
    'deploy:update_code',
    'deploy:vendors',
    'deploy:symlink',
])->local()->set('deploy_path', __DIR__ . '/.build');

As an alternative we could let the local method accept an optional local deploy_path, like so:

task('build', [
    'deploy:prepare',
    'deploy:release',
    'deploy:update_code',
    'deploy:vendors',
    'deploy:symlink',
])->local(__DIR__ . '/.build');

What do you think? 🙂

@antonmedv
Copy link
Member Author

I came out with better solution for local builds for v7. Will be simple and instead of adding set on tasks.

Just need to find time to implement it) now all my free time in Deployer Pro project. Hope to get some money to support open source development.

@lorisleiva
Copy link

Cool, looking forward to see that. No problem take you time :)

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

No branches or pull requests

4 participants