Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Wednesday, January 25, 2017

setting up automatic deployment via git

If you wish to have automatic deployment with rails and thin, here is an example:

1st, clone your repository on server to a path.
Next, vi .git/hooks/post-merge
add in your bash script to run after git is pull
example:
bash -lc /pathtoroot/deploy.sh

chmod a+x .git/hooks/post-merge

in your git repository, add a file called: deploy.sh, you may code any deployment command after git pull, example:
RAILS_ENV=production
cd /pathtoroot
echo "deploy.sh: bundle install"
bundle install
echo "deploy.sh: rake db:migrate"
bundle exec rake db:migrate
echo "deploy.sh: rake assets:precompile"
bundle exec rake assets:precompile
echo "deploy.sh: restarting"
bundle exec thin -C config/thin.yml restart
bundle exec sidekiqctl stop tmp/sidekiq.pid 0
bundle exec sidekiq -d -P tmp/sidekiq.pid -L log/sidekiq.log
echo "deploy.sh: Done!"

makesure you have chmod a+x deploy.sh and commit this file via git on your local machine.

on server, add a cron job to automatically pull on a period basis:
crontab -e
---
* * * * * bash -lc "cd /pathtoroot/ && git pull"
* * * * * sleep 30 && bash -lc "cd /pathtoroot/ && git pull"
---

2nd command allows you to run git pull within 30seconds.

Once git pull is successful, it will auto trigger post-merge and run your deploy.sh

hope it helps :)





Wednesday, December 14, 2011

I was doing my coding in netbean as usual, and was shock to find my changes been replaced and deleted by git. im not sure where went wrong, is it netbean commit that didnt register, or is it git messed up by replacing my commit with its old version.

Wondering how to revert a pull which messed up your code?
run:
git reflog
#example return:

d5ca5a5 HEAD@{0}: pull : Merge made by recursive.
772321b HEAD@{1}: commit: ....
585e66b HEAD@{2}: commit: ....
5a61fe4 HEAD@{3}: commit: ....

run:
git reset 772321b
#reset to a version before the merge was made

then go to netbean and revert all modification done.
This modification basically meants changes that reverse your commit to the older version


then make a copy of the version you have else where.
then run:
git pull
#redo the merge again , which messed up.

#then run meld and compare both directory and put back your latest files and updates into the working directory.
#then recommit your changes.
#then run:
git push
#again.


Thursday, February 4, 2010

GIT Howto sync to remote via push?

From CVS to SVN, and now GIT.
Git is the latest version control system created by Linus,
a big applause to him, one of opensource greatest gurus and leader :)

How to use?
1st, local:
cd to your source directory
type:
git init
git add .
git commit

next, ssh into your remote host,
example: /home/myname
mkdir mygit
cd mygit
git init
git config --bool core.bare true

go back to local source directory
type:
git push ssh://myname@[host]:port#/home/myname/mygit master
git config remote.origin.url ssh://myname@[host]:port#/home/myname/mygit

Done!
Updates: mar 3, 2011:
Later version of git forbids pushing an existing git.
So, you may just upload the .git directory from your local source directory to remote directory:
Example /home/myname/mygit/.git -> (remote) /home/myname/mygit/.git
Next, run git config --bool core.bare true (on remote machine)
Then, you may run git config to setup the git default push and pull on local machine.
Both copy shall have the same version :)

So if you ever want to push to remote again, simply type:
git push

And to update, type:
git pull

And if you are sharing this git with someone else to commit, you may set it to :
git config core.sharedRepository true

And make sure all users of the git should have the same group name.

To add a user to the git:
/usr/sbin/useradd -g groupname newusername
sudo passwd newusername

next, set the permission to the git directory on remote
chmod g+w -R .


Reference: