I was searching for a fast and easy way to setup git server, and I found one, but I was not fully happy with it, so lets have a look on another way:
ssh mpapis@niczsoft.com -C "mkdir -p repos/library2.git; cd repos/library2.git; git --bare init"
git clone mpapis@niczsoft.com:repos/library2.git
cd library2/
touch test.txt
git add .
git commit -a -m "1st"
git push origin master
This is good way to keep Your private repo, just as central repo or backup, no packages needed, just git on both sides
The same can be done on local filesystem like shared storage(nfs or smb):
cd /remote
mkdir test.git
cd test.git/
git --bare init
cd
git clone /remote/test.git/
cd test/
touch test.txt
git add .
git commit -a -m "1st"
git push origin master
From now on it will be working by simply calling “git pull” and “git push”.
Today I was coding just for fun … and wrote my own Capistrano script for deployment, during this I have found great way to invoke remote tasks.
The method is easy, add following code to your config/deploy.rb file:
set :sudo_call, ''
desc 'makes remote/rake calls to be executed with sudo'
task :use_sudo do
set :sudo_call, 'sudo'
end
desc 'run rake task'
task :rake do
ARGV.values_at(Range.new(ARGV.index('rake')+1,-1)).each do |task|
run "cd #{current_path}; #{sudo_call} RAILS_ENV=production rake #{task}"
end
exit(0)
end
desc 'run remote command'
task :remote do
command=ARGV.values_at(Range.new(ARGV.index('remote')+1,-1))
run "cd #{current_path}; #{sudo_call} RAILS_ENV=production #{command*' '}"
exit(0)
end
desc 'run specified rails code on server'
task :runner do
command=ARGV.values_at(Range.new(ARGV.index('runner')+1,-1))
run "cd #{current_path}; RAILS_ENV=production script/runner '#{command*' '}'"
exit(0)
end
Now try your new tool with following commands:
cap rake db:migrate
cap use_sudo rake db:migrate
cap remote "tail -n 10 log/production.log"
cap use_sudo remote cat /etc/passwd
cap runner p User.all
cap runner "User.all.each{ |u| p u }"
In the third call I have used parentheses to hide “-n” form Capistrano, because it is its parameter, to see whole list of Capistrano parameters call it with “cap –help”. For the last command I have used parentheses again because now it contained bash special characters.
Did You liked this post or maybe not, vote on it at dzone.