Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (47 sloc) 3.937 kB
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
1 Easy git deployment
2 ===================
6f5052a @mislav git deployment made easy
authored
3
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
4 Straightforward, [Heroku][]-style, push-based deployment. Your deploys will look like this:
6f5052a @mislav git deployment made easy
authored
5
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
6 $ git push production master
6f5052a @mislav git deployment made easy
authored
7
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
8 To get started, install the "git-deploy" gem.
323f0ed @mislav gem release v0.2.0
authored
9
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
10 $ gem install git-deploy
11
12
13 What application frameworks/languages are supported?
14 ----------------------------------------------------
15
16 Regardless of the fact that this tool is mostly written in Ruby, git-deploy can be useful for any kind of code that needs deploying on a remote server. The default scripts are suited for Ruby web apps, but can be edited to accommodate other frameworks.
17
18 Your deployment is customized with per-project callback scripts which can be written in any language.
19
20 The assumption is that you're deploying to a single host to which you connect over SSH using public/private key authentication.
21
323f0ed @mislav gem release v0.2.0
authored
22
6f5052a @mislav git deployment made easy
authored
23 Setup steps
24 -----------
25
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
26 1. Create a git remote for where you'll push the code on your server. The name of this remote in the examples is "production", but it can be whatever you wish ("online", "website", or other).
6f5052a @mislav git deployment made easy
authored
27
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
28 $ git remote add production user@example.com:/path/to/myapp
6f5052a @mislav git deployment made easy
authored
29
30 The "/path/to/myapp" is the directory where your code will reside. It doesn't have to exist; it will be created for you during this setup.
31
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
32 2. Run the setup task:
6f5052a @mislav git deployment made easy
authored
33
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
34 $ git deploy setup -r production
6f5052a @mislav git deployment made easy
authored
35
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
36 This will initialize the remote git repository in the target directory ("/path/to/myapp" in the above example) and install the remote git hooks.
37
38 3. Run the init task:
39
40 $ git deploy init
41
42 This generates default deploy callback scripts in the "deploy/" directory. You must check them in version control. They are going to be executed on the server on each deploy.
43
44 4. Push the code.
45
46 $ git push production master
6f5052a @mislav git deployment made easy
authored
47
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
48 3. Login to your server and manually perform necessary one-time administrative operations. This might include:
6f5052a @mislav git deployment made easy
authored
49 * set up the Apache/nginx virtual host for this application;
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
50 * check your "config/database.yml" and create the production database.
6f5052a @mislav git deployment made easy
authored
51
52
53 Deployment
54 ----------
55
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
56 If you've set your app correctly, visiting "http://example.com" in your browser should show it up and running.
6f5052a @mislav git deployment made easy
authored
57
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
58 Now, subsequent deployments are done simply by pushing to the branch that is currently checked out on the remote:
6f5052a @mislav git deployment made easy
authored
59
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
60 $ git push production master
6f5052a @mislav git deployment made easy
authored
61
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
62 Because the deployments are done with git, not everyone on the team had to install git-deploy. Just the person who was doing the setup.
6f5052a @mislav git deployment made easy
authored
63
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
64 Deployments are logged to "log/deploy.log" in your application.
6f5052a @mislav git deployment made easy
authored
65
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
66 On every deploy, the "deploy/after_push" script performs the following:
6f5052a @mislav git deployment made easy
authored
67
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
68 1. updates git submodules (if there are any);
69 2. runs `bundle install --deployment` if there is a Gemfile;
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
70 3. runs `rake db:migrate` if new migrations have been added;
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
71 4. clears cached CSS/JS assets in "public/stylesheets" and "public/javascripts";
72 5. restarts the web application.
aeeba16 @mislav a note about "post-reset" execution
authored
73
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
74 You can customize all of this by editing scripts in the "deploy/" directory of your app.
6f5052a @mislav git deployment made easy
authored
75
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
76 How it works
77 ------------
6f5052a @mislav git deployment made easy
authored
78
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
79 The "setup" task installed a "post-receive" hook in the remote git repository. This is how your working copy on the server is kept up to date. This hook, after checking out latest code, asynchronously dispatches to "deploy/after_push" script in your application. This script executes on the server and also calls "deploy/before_restart", "restart", and "after_restart" callbacks if they are present.
80
81 These scripts are ordinary unix executable files. The ones which are generated for you are written in shell script and Ruby.
6f5052a @mislav git deployment made easy
authored
82
013b39a @mislav big rewrite: scripts are now in per-project "deploy/" dir
authored
83 It's worth remembering that "after_push" is done **asynchronously from your git push**. This is because migrating the database and updating submodules might take a long time and you don't want to wait for all that during a git push. But, this means that when the push is done, the server has *not yet restarted*. You might need to wait a few seconds or a minute.
6f5052a @mislav git deployment made easy
authored
84
85
6884ebd @mislav big rewrite to not depend on Capistrano anymore
authored
86 [heroku]: http://heroku.com/
Something went wrong with that request. Please try again.