Website updating from git (over ssh)

1

I have a script that I run over SSH, which updates my website from a Git repo.

cd website-git
git checkout master
git pull

# Update protected directory
rsync -v -a --delete --exclude=db --exclude=vendor ./protected/ /home/protected

# Update public directory
rsync -v -a --delete --exclude=tmp --exclude=data ./public/ /home/public

It works fine, but the git repository has 150 MB and I pay for space used, so this is not a very good solution.

Apart from deleting the working copy (initially obtained with git clone) after taking the files form it, is there some way to save space with this setup?

MightyPork

Posted 2015-04-18T15:13:21.437

Reputation: 309

I posted an answer but this setup is really the beginning steps of you essentially reinventing the code deployment wheel. Tools like Capistrano are designed to handle tasks like this with ease. Yes, there is a slight learning curve if you have never used it before, but once you get the hang of it, Capistrano is your best bet for deployment tasks like this. – JakeGould – 2015-04-18T15:51:04.313

Answers

1

You should investigate how to use Capistrano to deploy your PHP code instead of reinventing the wheel with a Bash script like this. Capistrano is basically a series of Ruby scripts that in-turn then run a series of Bash commands to deploy code from a code repository to a remote server.

Although Capistrano is mainly used in the Ruby development world, but I have used it on tons of PHP projects and it works great. This is a nice tutorial on how to adapt Capistrano for usage in PHP applications. Ditto with this one.

If space is a concern, once you have your Capistrano scripts setup be sure to set the :keep_releases setting to something low like 2 or 3 like this in the Capistrano script:

set :keep_releases, 3

JakeGould

Posted 2015-04-18T15:13:21.437

Reputation: 38 217