deployphp / deployer

The PHP deployment tool with support for popular frameworks out of the box
https://deployer.org
MIT License
10.61k stars 1.49k forks source link

Clone/Checkout a specific branch/revision #179

Closed tomzx closed 9 years ago

tomzx commented 9 years ago

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:

antonmedv commented 9 years ago

Yes, it's thinks must to have.

tomzx commented 9 years ago

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.

antonmedv commented 9 years ago

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

antonmedv commented 9 years ago

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:

tomzx commented 9 years ago

Reference: 4a1c93f2d245b425fb3c288e04952cc43b1b22c2

tomzx commented 9 years ago

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.

oanhnn commented 9 years ago

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')
;
// ...
tomzx commented 9 years ago

@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.

antonmedv commented 9 years ago

@oanhnn will implement it soon.

oanhnn commented 9 years ago

thank you @elfet

antonmedv commented 9 years ago

Done!

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

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