Deployer: Clone/Checkout a specific branch/revision

Created on 14 Feb 2015  路  11Comments  路  Source: deployphp/deployer

At the moment, the common.php file does not provide a way to clone/deploy a specific branch/revision (it will clone the HEAD of the remote repository).

I think it is critical for deployer to support the deployment of specific branch/revision for it to be successful.

Here are the requirements:

  • Support cloning with submodules
  • If the deployment method is cloning, prefer --depth=1 (already supported)
  • Support checking out a specific branch/revision
feature

Most helpful comment

Done!

server(...)
    ->env('branch', 'master');

server(...)
    ->env('branch', 'develop');

All 11 comments

Yes, it's thinks must to have.

Capistrano's take on this is to have a {deploy_path}/repo directory where they clone the entire repository. When they want to deploy, they only have to fetch the latest changes from the repository, checkout the appropriate branch/revision and then rsync the folder to the {release_path}.

It is a pretty elegant solution in that, compare to cloning like we currently do, it uses the fact that most of the repository is already available locally. The downside is that if your repository is big, you'll have it hanging around in your {deploy_path}.

Since clone/checkout is already a task (deploy:update_code), I think what makes the most sense would be to have this configurable as some sort of strategy.

I'll think a little bit more about the problem and I'll see if I can provide a PR.

Cool! I think it's good to have options/strategies.

Done! :beers:
To deploy specific branch:

set('branch', 'master');

To deploy specific tag:

dep deploy --tag="v3.0.0"

And even more. To deploy production stage:

dep deploy production

:gem: :gem: :gem:

Reference: 4a1c93f2d245b425fb3c288e04952cc43b1b22c2

I've left a couple comments in the 4a1c93f2d245b425fb3c288e04952cc43b1b22c2 commit for you to review.

I think it'd be also nice to implement the alternative solution of cloning/fetching from a /repos folder and then rsync-ing/copying the repos content to the /release folder.

I have a question.
I defined two servers, dev-svr and prod-svr. My repo has two branchs, develop and master
I want deploy branch develop on dev-svr before merged to branch master and deploy on prod-svr. Can you support my case?
I expect code:

<?php
// ....
server('dev-svr', '192.168.1.2', 22)
    ->env('deploy_path', '/var/www/apps/dev')
    ->user('dev')
    ->forwardAgent()
    ->stage(['dev'])
    ->branch('develop')
;
server('prod-svr', '192.168.1.2', 22)
    ->env('deploy_path', '/var/www/apps/prod')
    ->user('dev')
    ->forwardAgent()
    ->stage(['prod'])
    ->branch('master')
;
// ...

@oanhnn With the current implementation, no, but that would indeed be interesting. I think it would be better to have branches as environment variables, so it can be used like @oanhnn suggests.

If the user passes a tag (which should have been a revision) then it'd force/prefer that tag over the branch.

@oanhnn will implement it soon.

thank you @elfet

Done!

server(...)
    ->env('branch', 'master');

server(...)
    ->env('branch', 'develop');
Was this page helpful?
0 / 5 - 0 ratings

Related issues

krve picture krve  路  4Comments

khoanguyen96 picture khoanguyen96  路  5Comments

antonmedv picture antonmedv  路  5Comments

ElForastero picture ElForastero  路  3Comments

timkley picture timkley  路  4Comments