I have setup push-to-deploy with my production server by setting up a --bare
directory at /home/ubuntu/push-to-deploy/test.git
, using that as my remote and adding a hooks/post-receive
inside the --bare
looking like this:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "production" == "$branch" -o "master" == "$branch" ]; then
git --work-tree=/var/www/test/ checkout -f $branch
sudo chown -R ubuntu:www-data /var/www/test
echo 'Changes pushed to Amazon EC2 PROD.'
fi
done
This works great when pushing to this new remote from my localhost. The post-receive
script executes as it should and the content updates are reflected in the /var/www/test
directory as they should be. The only thing is that my git log
inside /var/www/test
is not matching my localhost at all. Is this normal behavior of --work-tree
? If so, what can I do to retain this push-to-deploy
functionality and still have my git log copied over to the production directory as well as the content?
Also
When my content copies into the production directory (/var/www/test
) all the file ownerships are overrode to ubuntu:ubuntu
which makes the www-data
not be able to do its thing. I put a line in my post-receive
to update the ownership after each receive but is there another way (a better way) to do this?
UPDATE
The way to ensure that www-data
is retained as the group is to set the directory's guid like this:
chmod -R g+s /var/www/test
This will set it to whatever the current group of the directory is, so if you want it to be www-data
then make sure you set the group to www-data
before you issue that command.
Thanks
git log --git-dir=/home/ubuntu/push-to-deploy/test.git
should work just fine when executed from/var/www/test
. – Fangit --git-dir=/home/ubuntu/push-to-deploy/test.git log
– Fan/var/www/test/.git/config
to change thegit-dir
to/home/ubuntu/push-to-deploy/test.git
so I don't have to specify that--git-dir
option for each command like that? – RattlerGIT_DIR
. – Fancut -d/
is not quite right: if there's a ref of the formrefs/tags/master/v2
, for instance,cut
will extract field 3 which will bemaster
. It's probably fine in this particular case, but in general you should just test"$ref" == refs/heads/master
for instance. – Vachon