Deployment instructions using github hooks to Ec2 or any cloud VS like HEROKU does | deployment, github hooks, heroku, set production server, set server, EC2

Prepare your github repo on /var/www folder to follow the best practice.
$cd /var/www
Create a source code folder with your application name
$ sudo mkdir <Project Name>.com
Create a folder for github source code
$ sudo mkdir <Project Name>.com.git
Change to project github repo folder
$cd img-cloud-qa.com.git/
Initiate github bare to prepare folder
$sudo git init --bare
Jump to hooks to prepare your hooks for git preparation of project so you can start pushing your code to github.
$cd hooks
Now we are ready with hooks set to your project, create a post-receive file to execute your steps with shell script, below example is a node project and i am doing npm install and restarting web server.
$sudo nano post-receive

#!/bin/sh
error_exit ()
{
echo "$1" 1>&2
exit 1
}
git --work-tree=/var/www/<Project Name>.com --git-dir=/var/www/<Project Name>.com.git checkout -f
cd /var/www/<Project Name>.com || error_exit "error changing directory!. now exiting..."
npm install || error_exit "error running npm install! now exiting ..."
FOREVER_ROOT=/etc/forever forever restart -l /etc/forever/<Project Name>.log bin/www || error_exit "error starting forever server! now exiting ..."
Finally assign the proper permissions to the user to write files to to folder
$sudo chown -R deploy:deploy www/
Once all above steps done you are ready to deploy push your code to your project with below steps
git add remote <user>@<ip or host>:/var/www/<Project Name>.com.git
git push master
Ex:-

git add remote prod deploy@gsrao.xyz:/var/www/myapp.com.git
git push prod master

Comments

Popular posts from this blog

Rails Memcache issues

scp command usage guide

ROR HEROKU Working with file storage like paperclip in heroku for free of cost ( paperclip and dropbox) paperclip-dropbox config | ROR, HEROKU, file storage, paperclip, in heroku, free of cost, paperclip, dropbox, paperclip-dropbox config