Answer the question
In order to leave comments, you need to log in
How to organize the synchronization of the site with the bare-repository on the server?
Hello.
Installed gitolite on the server (under the git user). In "/home/git/repositories/site.com.git" is the bare repository of the site with the "master" and "test" branches. There is also a "site.com" folder, where the site is located, and a "test.site.com" folder, where the test version of the site is located, the owner is user.
Now the problem is: how to properly synchronize the files of the site and its test version with the repository?
Create in the folders with the site and the test version of the repository, and write a hook that, when pushing to the master branch of the bare repository, pushes to the folder with the site, and when pushing to the test branch, pushes to the folder with the test version?
Or are there smarter and more time-tested ways?
Answer the question
In order to leave comments, you need to log in
It just doesn’t push, but goes to the desired directory and pulls from there.
For example like this:
branch=$(git rev-parse --symbolic --abbrev-ref $1)
if [ $(git rev-parse --is-bare-repository) = true ]
then
rep=$(basename "$PWD"|sed 's/.git//')
else
rep=$(basename $(readlink -nf "$PWD"/..|sed 's/.git//'))
fi
/home/scripts/git/post-update.sh $rep $branch
#!/bin/sh
DATADIR=/var/www/$1/$2
REPO=$1
BRANCH=$2
if [ ! -d $DATADIR ]
then
mkdir -p $DATADIR
git clone [email protected]:$REPO $DATADIR
cd $DATADIR
git checkout $BRANCH
else
cd $DATADIR
/usr/bin/git config user.email "[email protected]"
/usr/bin/git config user.name "Deploy Robot"
/usr/bin/git fetch origin
/usr/bin/git reset --hard origin/$BRANCH
/usr/bin/git stash
/usr/bin/git checkout
/usr/bin/git pull
fi
The easiest way to do this is through a web request.
Write hooks that will pull the url at a given address, process this request on the site itself so that git pull can be done.
Your situation, of course, is simpler - a repository and a deployment on the same machine, but this method is the most versatile.
Yes, and in the future it will come in handy if you do auto-deploy from bitbucket, for example. There, they won’t let you write hooks manually, but they have a ready-made hook with an http request.
A universal solution would be to use a Continuous Integration
server , such as Jenkins .
Make 2 tasks on it, one for the master branch, the second for the test roll. In these tasks, in response to the appearance of commits in the branch, publish to the site via SSH, FTP, or simple copy.
The advantage of the approach is that all information about deployment is concentrated in one place - Jenkins tasks, for different projects you can organize uploading files to the server in different ways, but in principle the tasks will be the same.
If we go further, then in the same tasks you can run automatic testing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question