create git hook to push code on server
Login to the server 
ssh root@IP
sudo apt-get update
sudo apt-get install apache2
 
sudo chown -R `whoami`:`id -gn` /var/www/html
 sudo apt-get install git
mkdir ~/proj 
cd ~/proj 
git init --bare
.git in a conventional setup are in the main directory itself.We need to create another git hook. This time, we are interested in the
post-receive hook, which is run on the server receiving a git push.  Open this file in your editor:
nano hooks/post-receive
  put below content in post-recieve file  #!/bin/bash
while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch to production..."
        git --work-tree=/home/ec2-user/app --git-dir=/home/ec2-user/proj checkout -f
      # sudo  /etc/init.d/nginx restart cd /home/ec2-user/ywrstaging/ywroom-staging &&  source 
~/.rvm/scripts/rvm && bundle install && rake db:migrate
       sudo  /etc/init.d/nginx restart
    else
        echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
    fi
done    When you are finished, save and close the file.
Remember, we must make the script executable for the hook to work:
chmod +x hooks/post-receive 
chmod +x hooks/post-receive  
 
Now, we can set up access to this remote server on our client.
 
Now, we can set up access to this remote server on our client.
Configure the Remote Server on your Client Machine
Back on your client (development) machine, go back into the working directory of your project:cd ~/projInside, add the remote server as a remote called production.
  You will need to know the username that you used on your production 
server, as well as its IP address or domain name. You will also need to 
know the location of the bare repository you set up in relation to the 
user's home directory.
The command you type should look something like this:
git remote add production demo@server_domain_or_IP:proj
 
git push production master
 
Comments
Post a Comment