About
This is simple and flexible deployment solution based on Git post-receive hook.
- You don’t have to install anything on your server
- It works with whichever thinkable solution, Rails, Merb, Rango, Sinatra or even Django or static pages, it just doesn’t matter!
- Deployment to more servers is supported.
Usage
- Run
gem install git-deployer --development
- Add following lines to your file with Nake tasks (I’ll refer this file as
tasks.rb
):
begin load "git-deployer.nake" Task["deployer:setup"].config[:servers] = { server1: { user: "www", host: "127.0.0.1", repo: "/var/sources/deploy-test.git", path: "/var/www/deploy-test" } } rescue LoadError warn "You have to install git-deployer gem if you want to deploy to remote servers!" end
- Install hooks via
./tasks.rb deployer:install
- Edit
hooks/clone
andhooks/update
- Install
post-receive
hook and create necessary directories via./tasks.rb deployer:setup
- Push your changes via
git push origin master
That’s it. When you run git push origin master
for the first time, it should found that given branch isn’t cloned yet, so it should
Available tasks
Task deployer:install
This task will copy hooks/clone
and hooks/update
hooks to your project. This step is mandatory.
Task deployer:setup
It can take one or more optional arguments with
It takes the same arguments resp. configuration options as deployer:compile_hook
task
Task deployer:compile_hook
This task will copy hooks/post-receive
hook to your project. This step is optional and you will use the task you in case that you aren’t happy with the default post-receive
hook distributed with git-deployer and you want to customize things. But you shouldn’t need this, there is a bunch of arguments which you can use for influencing the generated post-receive
hook.
Task deployer:remote:copy_hook
Again, you typically don’t need this task, because it run during deployer:setup
. However if you changed something in the post-receive
hook, you might want to run this task which will install post-receive
on remote servers. By default the hook will be installed to all the servers, but you can specify just a subset via ./tasks.rb deployer:remote:copy_hook server1 server2
.
Setup
Restricting Just for deploy
Branch
You might not want to deploy every branch you push to origin.
Task deployer:run
If you pushed to the remote server but the hook failed, this is the way how you can re-run it. Just fix the problem and run ./tasks.rb deployer:run
. By default it runs on all the servers, but you can run it just on some servers via ./tasks.rb deployer:run server1 server2
.
Task deploy
This task is useful for deployment to multiple servers. Just run git push server1 master && git push server1 master
or ./tasks.rb deploy
which is a shortcut for pushing current branch to all or specified remote servers.
FAQ
Q: I had typo in my hooks, so it failed during deploy, how can I rerun it?
A: ./tasks.rb deployer:run
with optional argument which
Q: You are using Nake, but everyone’s using Rake. Is there any chance that you will support Rake in future?
A: The trouble with Rake is that Rake doesn’t support configuration and it also really suck in command-line parsing. If Rake will support at least the command line arguments in a reasonable way, I can think about it.