cap-git-deploy 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,2 +1,64 @@
1
- capistrano-git-deploy
2
- =====================
1
+ # Installation
2
+
3
+ ```bash
4
+ gem install cap-git-deploy
5
+ ```
6
+
7
+ or inside your Gemfile:
8
+
9
+ ```ruby
10
+ group :development do
11
+ gem 'cap-git-deploy'
12
+ end
13
+ ```
14
+
15
+ # How to use
16
+
17
+ cap-git-deploy disables the use of the symlinks for version control in favor of a tag-style mechanism with git: every deploy is marked with a git tag. A rollback is a checkout to a tag.
18
+
19
+ The following is a sample recipe that uses git-deploy as deployment procedure:
20
+
21
+ ```ruby
22
+ require 'cap-git-deploy'
23
+
24
+ set :repository, 'git@my-host.com:my-app.git'
25
+ set :deploy_to, '/var/apps/my-app'
26
+ role :app, 'my-host.com'
27
+ role :web, 'my-host.com'
28
+ role :db, 'my-host.com'
29
+ ```
30
+
31
+ In addition, cap-git-deploy stores some deploy info inside a revision file (called REVISION by default) on the remote host.
32
+ After each deploy the commit sha, the branch name, the user name and the current date are stored inside this file.
33
+ To show the deploy infos you can launch the revision:get task:
34
+
35
+ ```bash
36
+ cap revision:get
37
+ ```
38
+
39
+ ## Note: Current Branch
40
+
41
+ By default, your current branch will be deployed.
42
+ However, when working with staging environments, usually you want to deploy a particular branch unless specified. In this case insert the following in your deploy.rb file:
43
+
44
+ ```ruby
45
+ set :branch, ENV['branch'] || 'master'
46
+ ```
47
+
48
+ In this way, 'cap deploy' will deploy the 'master' branch, instead 'cap deploy branch=foo' will deploy the branch 'foo'.
49
+
50
+ For production environments **you should** use something like the following code:
51
+
52
+ ```ruby
53
+ set :branch, 'master'
54
+ ```
55
+
56
+ ## Note: Setup
57
+
58
+ To setup your environment, when your recipes are ready, type the following command from your rails app:
59
+
60
+ ```bash
61
+ cap deploy:setup
62
+ ```
63
+
64
+ This will setup your git repository on the remote host.
@@ -9,6 +9,7 @@ module Cap
9
9
  module Deploy
10
10
  # utility functions
11
11
 
12
+ # The name of the branch we are deploying
12
13
  def self.current_branch
13
14
  repo = Grit::Repo.new '.'
14
15
  branch = repo.head
@@ -16,6 +17,7 @@ module Cap
16
17
  branch && branch.name || 'master'
17
18
  end
18
19
 
20
+ # The name of the current logged user
19
21
  def self.current_user
20
22
  "#{Etc.getlogin}@#{Socket.gethostname}"
21
23
  end
@@ -1,7 +1,7 @@
1
1
  module Cap
2
2
  module Git
3
3
  module Deploy
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -1,15 +1,13 @@
1
1
  set :rolling_back, false
2
2
  set :scm, :git
3
3
  set :logged_user, Cap::Git::Deploy.current_user
4
- set :branch, ENV['branch'] || Cap::Git::Deploy.current_branch unless exists? :branch
4
+ unless exists? :branch
5
+ set :branch, ENV['branch'] || Cap::Git::Deploy.current_branch
6
+ end
7
+ set(:latest_release) { fetch :current_path }
8
+ set(:current_release) { fetch :current_path }
5
9
 
6
10
  namespace :deploy do
7
- task :default do
8
- update
9
- update_revision
10
- restart
11
- end
12
-
13
11
  desc "Setup a GitHub-style deployment"
14
12
  task :setup, :except => { :no_release => true } do
15
13
  dirs = [deploy_to, shared_path]
@@ -22,17 +20,11 @@ namespace :deploy do
22
20
  # This is where the log files will go
23
21
  run "mkdir -p #{current_path}/log" rescue 'no problem if log already exist'
24
22
 
25
- # This is to make sure we are on the correct branch
26
- run "cd #{current_path}; git checkout -b #{branch} --track origin/#{branch}" if branch != 'master'
27
- end
28
-
29
- desc "Update the deployed code"
30
- task :update_code, :except => { :no_release => true } do
31
- # If we are rolling back branch is a commit
32
- branch_name = rolling_back && branch || "origin/#{branch}"
33
-
34
- run "cd #{current_path} && git fetch" unless rolling_back
35
- run "cd #{current_path} && git reset --hard #{branch_name}"
23
+ branch = fetch :branch, 'master'
24
+ if branch != 'master'
25
+ # This is to make sure we are on the correct branch
26
+ run "cd #{current_path} && git checkout -b #{branch} --track origin/#{branch}"
27
+ end
36
28
  end
37
29
 
38
30
  namespace :rollback do
@@ -53,63 +45,33 @@ namespace :deploy do
53
45
  end
54
46
  end
55
47
 
56
- task :create_symlink, :except => { :no_release => true } do
57
- # This empty task is needed to override the default :create_symlink task
58
- end
59
-
60
- task :create_symlink, :except => { :no_release => true } do
61
- # This empty task is needed to override the default :symlink task
62
- end
63
-
64
- task :migrate, :roles => :db, :only => { :primary => true } do
65
- rake = fetch :rake, "rake"
66
- bundler = fetch :bundler, "bundler"
67
- rails_env = fetch :rails_env, "production"
68
- migrate_env = fetch :migrate_env, ""
69
-
70
- run "cd #{current_path}; RAILS_ENV=#{rails_env} #{bundler} exec #{rake} db:migrate #{migrate_env}"
71
- end
72
-
73
- desc "Create a REVISION file containing the SHA of the deployed commit"
74
- task :update_revision, :except => { :no_release => true } do
75
- # If for some reason we cannot find the commit sha, then we'll use the branch name
76
- sha = "origin/#{branch}"
77
- run "cd #{current_path}; git rev-parse origin/#{branch}" do |channel, stream, data|
78
- sha = data.strip
48
+ task :update, :except => { :no_release => true } do
49
+ transaction do
50
+ update_code
51
+ insert_tag
79
52
  end
80
-
81
- commands = []
82
- commands << "cd #{current_path}"
83
- commands << "echo '#{sha}' > REVISION"
84
- commands << "echo '#{branch}' >> REVISION"
85
- commands << "echo '#{logged_user}' >> REVISION"
86
- commands << "echo '#{Time.now}' >> REVISION"
87
- run commands.join ' && '
88
53
  end
89
54
 
90
- task :start do ; end
91
- task :stop do ; end
92
- task :restart, :roles => :app, :except => { :no_release => true } do
93
- # Restart in Passenger way
94
- run "touch #{File.join(current_path,'tmp','restart.txt')}"
95
- end
55
+ desc "Update the deployed code"
56
+ task :update_code, :except => { :no_release => true } do
57
+ # If we are rolling back branch, then this is a commit
58
+ if rolling_back
59
+ branch_name = branch
60
+ else
61
+ branch_name = "origin/#{fetch :branch, 'master'}"
62
+ end
96
63
 
97
- desc "Runs bundle for production environments"
98
- task :bundle do
99
- bundler = fetch :bundler, "bundler"
100
- run "cd #{current_path}; #{bundler} install --deployment --without mac development test"
64
+ run "cd #{current_path} && git fetch" unless rolling_back
65
+ run "cd #{current_path} && git reset --hard #{branch_name}"
101
66
  end
102
- end
103
67
 
104
- desc "Get info about last deploy"
105
- task :get_revision do
106
- keys = %w(SHA Branch Author Date).reverse
107
- run "cat #{current_path}/REVISION" do |c, s, data|
108
- data.strip.lines.each do |line|
109
- puts "#{keys.pop}: #{line.strip}" if keys.any?
110
- end
68
+ task :insert_tag, :except => { :no_release => true } do
69
+ timestamp = Time.now.strftime '%Y%m%d%H%M%S'
70
+ run "cd #{current_path}; git tag deploy_#{timestamp}" unless rolling_back
111
71
  end
112
72
  end
113
73
 
114
- after "deploy:restart", "deploy:migrate"
115
- after "deploy:update_code", "deploy:bundle"
74
+ # launch bundle:install after update task if it's detected
75
+ # because it will not run with his standard behavior (before deploy:finalize_update)
76
+ # as we are using this custom git-style deployment procedure
77
+ after 'deploy:update', 'bundle:install' if find_task 'bundle:install'
@@ -0,0 +1,32 @@
1
+ set :revision_file, 'REVISION'
2
+
3
+ namespace :revision do
4
+ desc "Create a REVISION file containing the SHA of the deployed commit"
5
+ task :set, :except => { :no_release => true } do
6
+ # If for some reason we cannot find the commit sha, then we'll use the branch name
7
+ sha = "origin/#{branch}"
8
+ run "cd #{current_path}; git rev-parse origin/#{branch}" do |channel, stream, data|
9
+ sha = data.strip
10
+ end
11
+
12
+ commands = []
13
+ commands << "cd #{current_path}"
14
+ commands << "echo '#{sha}' > #{revision_file}"
15
+ commands << "echo '#{branch}' >> #{revision_file}"
16
+ commands << "echo '#{logged_user}' >> #{revision_file}"
17
+ commands << "echo '#{Time.now}' >> #{revision_file}"
18
+ run commands.join ' && '
19
+ end
20
+
21
+ desc "Get info about last deploy"
22
+ task :get do
23
+ keys = %w(SHA Branch Author Date).reverse
24
+ run "cat #{current_path}/#{revision_file}" do |c, s, data|
25
+ data.strip.lines.each do |line|
26
+ puts "#{keys.pop}: #{line.strip}" if keys.any?
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ after 'deploy:update_code', 'revision:set'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-git-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-29 00:00:00.000000000Z
12
+ date: 2012-05-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &70255335369120 !ruby/object:Gem::Requirement
16
+ requirement: &70216834563020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70255335369120
24
+ version_requirements: *70216834563020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: grit
27
- requirement: &70255335368700 !ruby/object:Gem::Requirement
27
+ requirement: &70216834562600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70255335368700
35
+ version_requirements: *70216834562600
36
36
  description: Mikamai-style deploy strategy
37
37
  email:
38
38
  - projects@mikamai.com
@@ -47,6 +47,7 @@ files:
47
47
  - lib/cap-git-deploy.rb
48
48
  - lib/cap-git-deploy/version.rb
49
49
  - lib/recipes/fast-git-deploy.rb
50
+ - lib/recipes/git-revisioning.rb
50
51
  homepage: http://www.mikamai.com
51
52
  licenses: []
52
53
  post_install_message: