This HowTo explains how to setup git repo on EC2 instance and auto deployed through a cron script.

This was tested with EC2 instance and you need to edit your ssh config so that root could login with the password.

Add you public key to the server for authentication:

cat ~/.ssh/id_rsa.pub | ssh gloss.io “cat >> .ssh/authorized_keys”

Create a Git Repo on the Server

mkdir skybound.git
cd skybound.git/
git init –bare

On the Client Side

mkdir webserver
cd webserver
git init
git remote add origin ssh://SERVERHOSTNAME/path/to/git/repo
ADD SOME DATA TO COMMIT IT TO REMOTE REPO
git add .
git commit -m “testcommit”
git push origin master

Cloning the repo on the webserver from where the application is to be hosted for me it was /var/www/repo

mkdir repo
cd repo
git clone ssh://SERVERHOSTNAME/path/to/git/repo.git

Update

git pull origin master

Create a script for updating with every push and add a cronjob

vi gitupdate
—-
#!/bin/bash
#CONFIG
LIVE=”/root/repo/skybound/”
cd $LIVE
git pull origin master
—-
chmod +x gitupdate

* * * * * /root/gitupdate

remove origin in case you get error and redo the client side configuration

git remote rm origin

Advertisements