Deployer: git archive rather than clone

Created on 29 Jul 2016  路  10Comments  路  Source: deployphp/deployer

| Q | A |
| --- | --- |
| Issue Type | Question |
| Deployer Version | 3.3 |
| Local Machine OS | N/A |
| Remote Machine OS | N/A |

Description

I've moved a number of my projects over to deployer recently and been very happy with how it works and the ease of migrating my projects. One thing I've noticed though is that the size of the releases on the destination server has increased significantly compared to my previous deployment approach. Taking a closer look I see that the main difference is that deployer uses git clone and my previous release script, which was hand crafted, used git archive. Even though deployer uses a shallow clone, in my repo at least there's a lot of additional branch information that I don't need (or want really) deployed to the server running the application.

Before I recode the update_code step for my local deploy.php script, was there any specific reason to use clone rather than archive for the update_code step? If not would you like a revised version of update_code using git archive?

Thanks and keep up the deploying!

Steve

feature

Most helpful comment

Hi, guys! An advantage of using git archive is that we can ignore some files and folders that shouldn't be on the production server (like tests) using export-ignore in the .gitattributes file. Thus the code could be smaller than using git clone.

The OWASP Quick Reference Guide says: "Remove test code or any functionality not intended for production, prior to deployment." Having git archive would solve this issue.

All 10 comments

+1

What is pros and cons of archive vs clone? shallow clone is really fast, also allowing you to easy switch branches on staging servers for testing.

Well for the repo that I'm dealing with there is a size difference between a shallow clone and an archive. 360MB for the archive and 522MB for the clone. This is then multiplied by the number of old versions that are kept. For my deployments I never need to switch branches on the deployed systems so I don' get any advantage from the extra space.

This particular repo is likely to have ever more branches and projects in it, so this gap will grow over time, leading to wasted space and possible slower deployments - although git archive isn't' super fast itself.

But deployer use --depth 0 option. So size of archive and clone should be same.

If you want using git archive simple override deploy:update_code recipe.

It seems to use --depth 1 based on my inspection of the code. --depth 0 also seems to give an error from git.

You are right I can override the deploy function so I'll give that a try and see if it improves things for me. Thanks for the response.

--depth 1 is correct

Hi, guys! An advantage of using git archive is that we can ignore some files and folders that shouldn't be on the production server (like tests) using export-ignore in the .gitattributes file. Thus the code could be smaller than using git clone.

The OWASP Quick Reference Guide says: "Remove test code or any functionality not intended for production, prior to deployment." Having git archive would solve this issue.

@thiagolcks that's try. You can do it simply as:

task('deploy:update_code', function () {
    run('git archive --format=tar {{branch}} | (cd {{release_path}} && tar xf -)');
});

thanks @antonmedv

I had to add the repository and then it worked like a charm.

task('deploy:update_code', function () {
    run('git archive --remote {{repository}} --format tar {{branch}} | (cd {{release_path}} && tar xf -)');
});

My thanks too @antonmedv. Reduces the footprint per release from 650MB to 250MB on one of our systems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

minkbear picture minkbear  路  4Comments

sweebee picture sweebee  路  3Comments

osbulbul picture osbulbul  路  3Comments

dima-stefantsov picture dima-stefantsov  路  5Comments

flashios09 picture flashios09  路  4Comments