Deployer: How to set branch for local build command

Created on 17 Oct 2017  路  16Comments  路  Source: deployphp/deployer

| Q | A
| ----------------- | ---
| Issue Type | Question
| Deployer Version | 5.1.3
| Local Machine OS | Linux
| Remote Machine OS | Linux

Description

I'm using the local build (like described here: https://deployer.org/docs/advanced/deploy-strategies) to process my frontend assets using npm / grunt (which is not available on my production server)

I needed to specify the branch in order to clone the correct version (see build task below).

Example:
dep deploy staging <- should use my-staging-branch
dep deploy testing <- should use my-testing-branch

Currently I have an additional server configuration for localhost which is used no matter what host is deployed. Is there a way to use the actual host configuration?

Content of inventory.yml

localhost: local: true roles: - build repository: [email protected]:user/repo.git branch: my-branch keep_releases: 1

Content of deploy.php

````
desc('Deploy your project');
task('deploy', [
'build',
'release',
'cleanup',
'success'
]);

task('release', [
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:upload',
'deploy:vendors',
'deploy:clear_paths',
'deploy:symlink',
'deploy:unlock',
]);

task('build', function () {
set('deploy_path', __DIR__ . '/.build');

// Set default config from localhost
set('repository', host('localhost')->get('repository')); // <- what I want to get rid of!
set('branch', host('localhost')->get('branch')); // <- what I want to get rid of!
set('keep_releases', host('localhost')->get('keep_releases'));

invoke('deploy:prepare');
invoke('deploy:release');
invoke('deploy:update_code');
invoke('npm:install');
invoke('assets:build');
invoke('deploy:symlink');
invoke('cleanup');

})->local();
````

Most helpful comment

Will do. Also working on documentation.

All 16 comments

Create build hosts.

localhost('build')

task('build', function () {
    set('deploy_path', __DIR__ . '/.build');

    // Set default config from localhost
    set('repository', host('localhost')->get('repository')); // <- what I want to get rid of!
    set('branch', host('localhost')->get('branch')); // <- what I want to get rid of!
    set('keep_releases', host('localhost')->get('keep_releases'));

    invoke('deploy:prepare');
    invoke('deploy:release');
    invoke('deploy:update_code');
    invoke('npm:install');
    invoke('assets:build');
    invoke('deploy:symlink');
    invoke('cleanup');
})->onHost('build');

Sorry for the late response...

I'm already using a localhost host (see my inventory yaml file above), so I'm not quite sure how to do this. Do I need to create a related build host for every of my "real" hosts (in my case prod, stage, dev environments on my server)? Or is there a way to use the branch of my actual deploy task started?

I guess I'm missing the "onHost()" directive, so it should look more like this?

````

task('build', function () {
set('deploy_path', __DIR__ . '/.build');

// Set default config from localhost
//set('repository', host('localhost')->get('repository'));
//set('branch', host('localhost')->get('branch'));
set('keep_releases', host('localhost')->get('keep_releases'));

...
})->onHosts(['localhost']);
````

Can you elaborate a little more on this?

Yes, your exampke is correct, you can use onHosts for now.
Also I think to create set of special task for simplify local building.

Tried this again but I'm not able to remove the additional set() directives, otherwise the default branch is used. In addition, even if it works without the set(), I guess I would need to define an extra built host for each of my hosts -- at least if they use different branches.

I guess this would really need to have a special task or a more complex example in the docs.

Anyway, thanks a lot for your help and Deployer in general!

I guess this would really need to have a special task or a more complex example in the docs.

I've ended up this some extra tasks as well. Now, I'm working on special helper tasks for this.

@antonmedv Until there is a real solution could you post some of the tasks you have used to work around the problem?

I think, I can't find it any more. :)

A little bit out of context.

Any news on this?

@antonmedv Can you have another look at this and let us know if there is a workaround for the latest version?

Will take a look.

Any news on this?

Should be fixed in #1904

@antonmedv Thanks, can you add a short snippet here how the configuration should look like in v7 for this? Or is this a pure internal change?

Will do. Also working on documentation.

Until this is released we use this for Deployer 6.x:

set('branch', function () {
    $stage = input()->getArgument('stage');

    return host($stage)->get('branch');
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

krve picture krve  路  4Comments

osbulbul picture osbulbul  路  3Comments

exts picture exts  路  3Comments

ovaiskhan11 picture ovaiskhan11  路  4Comments

greatwitenorth picture greatwitenorth  路  4Comments