capistrano-git 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'capistrano_colors', '0.5.5'
4
+
5
+ group :development do
6
+ gem 'jeweler', '~> 1.6.4'
7
+ end
@@ -0,0 +1,17 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ capistrano_colors (0.5.5)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.2.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ capistrano_colors (= 0.5.5)
17
+ jeweler (~> 1.6.4)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ryan Moran
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = capistrano-git
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to capistrano-git
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Ryan Moran. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "capistrano-git"
18
+ gem.homepage = "http://github.com/ryanmoran/capistrano-git"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Capistrano recipe for deploying from git}
21
+ gem.description = %Q{Capistrano recipe for deploying from git}
22
+ gem.email = "ryan.moran@gmail.com"
23
+ gem.authors = ["Ryan Moran"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capistrano-git}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Ryan Moran}]
12
+ s.date = %q{2011-11-21}
13
+ s.description = %q{Capistrano recipe for deploying from git}
14
+ s.email = %q{ryan.moran@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "capistrano-git.gemspec",
28
+ "lib/capistrano/git/bootstrap.rb",
29
+ "lib/capistrano/git/overrides.rb",
30
+ "lib/capistrano/git/strategy.rb",
31
+ "test/helper.rb",
32
+ "test/test_capistrano-git.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/ryanmoran/capistrano-git}
35
+ s.licenses = [%q{MIT}]
36
+ s.require_paths = [%q{lib}]
37
+ s.rubygems_version = %q{1.8.6}
38
+ s.summary = %q{Capistrano recipe for deploying from git}
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<capistrano_colors>, ["= 0.5.5"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
46
+ else
47
+ s.add_dependency(%q<capistrano_colors>, ["= 0.5.5"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<capistrano_colors>, ["= 0.5.5"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ end
54
+ end
55
+
@@ -0,0 +1,5 @@
1
+ require 'capistrano'
2
+ require 'capistrano_colors'
3
+
4
+ require 'capistrano/git/strategy'
5
+ require 'capistrano/git/overrides'
@@ -0,0 +1,209 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :deploy do
3
+ desc <<-DESC
4
+ Deploys your project. This calls both `update' and `restart'. Note that \
5
+ this will generally only work for applications that have already been deployed \
6
+ once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
7
+ task, which handles the cold start specifically.
8
+ DESC
9
+ task :default do
10
+ update
11
+ restart
12
+ end
13
+
14
+ desc <<-DESC
15
+ Prepares one or more servers for deployment. Before you can use any \
16
+ of the Capistrano deployment tasks with your project, you will need to \
17
+ make sure all of your servers have been prepared with `cap deploy:setup'.
18
+ DESC
19
+ task :setup, :except => { :no_release => true } do
20
+ strategy.setup!
21
+ end
22
+
23
+ desc <<-DESC
24
+ Copies your project to the remote servers. This is the first stage \
25
+ of any deployment; moving your updated code and assets to the deployment \
26
+ servers. You will rarely call this task directly, however; instead, you \
27
+ should call the `deploy' task (to do a complete deploy) or the `update' \
28
+ task (if you want to perform the `restart' task separately).
29
+
30
+ You will need to make sure you set the :scm variable to the source \
31
+ control software you are using (it defaults to :subversion), and the \
32
+ :deploy_via variable to the strategy you want to use to deploy (it \
33
+ defaults to :checkout).
34
+ DESC
35
+ task :update_code, :except => { :no_release => true } do
36
+ on_rollback { strategy.rollback! }
37
+ strategy.deploy!
38
+ finalize_update
39
+ end
40
+
41
+ task :finalize_update, :except => { :no_release => true } do
42
+ end
43
+
44
+ task :symlink, :except => { :no_release => true } do
45
+ end
46
+
47
+ namespace :bundle do
48
+ desc "Wipe out and rebuild the existing bundle."
49
+ task :rebuild do
50
+ strategy.rebuild_bundle!
51
+ end
52
+ end
53
+
54
+ desc <<-DESC
55
+ Copy files to the currently deployed version. This is useful for updating \
56
+ files piecemeal, such as when you need to quickly deploy only a single \
57
+ file. Some files, such as updated templates, images, or stylesheets, \
58
+ might not require a full deploy, and especially in emergency situations \
59
+ it can be handy to just push the updates to production, quickly.
60
+
61
+ To use this task, specify the files and directories you want to copy as a \
62
+ comma-delimited list in the FILES environment variable. All directories \
63
+ will be processed recursively, with all files being pushed to the \
64
+ deployment servers.
65
+
66
+ $ cap deploy:upload FILES=templates,controller.rb
67
+
68
+ Dir globs are also supported:
69
+
70
+ $ cap deploy:upload FILES='config/apache/*.conf'
71
+ DESC
72
+ task :upload, :except => { :no_release => true } do
73
+ files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
74
+ abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
75
+
76
+ files.each { |file| top.upload(file, File.join(current_path, file)) }
77
+ end
78
+
79
+ desc <<-DESC
80
+ Restarts your application. This works by calling the script/process/reaper \
81
+ script under the current path.
82
+
83
+ If you are deploying a Rails 2.3.x application, you will need to install \
84
+ these http://github.com/rails/irs_process_scripts (more info about why \
85
+ on that page.)
86
+
87
+ By default, this will be invoked via sudo as the `app' user. If \
88
+ you wish to run it as a different user, set the :runner variable to \
89
+ that user. If you are in an environment where you can't use sudo, set \
90
+ the :use_sudo variable to false:
91
+
92
+ set :use_sudo, false
93
+ DESC
94
+ task :restart, :roles => :app, :except => { :no_release => true } do
95
+ strategy.restart!
96
+ end
97
+
98
+ namespace :rollback do
99
+ desc <<-DESC
100
+ Will rollback to the last tagged revision.
101
+ DESC
102
+ task :revision, :except => { :no_release => true } do
103
+ strategy.rollback!
104
+ end
105
+
106
+ task :cleanup, :except => { :no_release => true } do
107
+ end
108
+
109
+ desc <<-DESC
110
+ Rolls back to the previously deployed version. You'll generally want \
111
+ to call `rollback' instead, as it performs a `restart' as well.
112
+ DESC
113
+ task :code, :except => { :no_release => true } do
114
+ revision
115
+ cleanup
116
+ end
117
+
118
+ desc <<-DESC
119
+ Rolls back to a previous version and restarts. This is handy if you ever \
120
+ discover that you've deployed a lemon; `cap rollback' and you're right \
121
+ back where you were, on the previously deployed version.
122
+ DESC
123
+ task :default do
124
+ revision
125
+ restart
126
+ cleanup
127
+ end
128
+ end
129
+
130
+ desc <<-DESC
131
+ Migrates the DB.
132
+ DESC
133
+ task :migrate, :roles => :db, :only => { :primary => true } do
134
+ strategy.migrate!
135
+ end
136
+
137
+ desc <<-DESC
138
+ Deploy and run pending migrations. This will work similarly to the \
139
+ `deploy' task, but will also run any pending migrations (via the \
140
+ `deploy:migrate' task). Note that the update in this case it is not \
141
+ atomic, and transactions are not used, because migrations are not \
142
+ guaranteed to be reversible.
143
+ DESC
144
+ task :migrations do
145
+ update_code
146
+ migrate
147
+ symlink
148
+ restart
149
+ end
150
+
151
+ task :cleanup, :except => { :no_release => true } do
152
+ end
153
+
154
+ task :check, :except => { :no_release => true } do
155
+ end
156
+
157
+ desc <<-DESC
158
+ Deploys and starts a `cold' application. This is useful if you have not \
159
+ deployed your application before, or if your application is (for some \
160
+ other reason) not currently running. It will deploy the code, run any \
161
+ pending migrations, and then instead of invoking `deploy:restart', it will \
162
+ invoke `deploy:start' to fire up the application servers.
163
+ DESC
164
+ task :cold do
165
+ update
166
+ migrate
167
+ start
168
+ end
169
+
170
+ desc <<-DESC
171
+ Start the application servers. \
172
+
173
+ By default, the script will be executed via sudo as the `app' user. If \
174
+ you wish to run it as a different user, set the :runner variable to \
175
+ that user. If you are in an environment where you can't use sudo, set \
176
+ the :use_sudo variable to false.
177
+ DESC
178
+ task :start, :roles => :app do
179
+
180
+ end
181
+
182
+ desc <<-DESC
183
+ Stop the application servers. \
184
+
185
+ By default, the script will be executed via sudo as the `app' user. If \
186
+ you wish to run it as a different user, set the :runner variable to \
187
+ that user. If you are in an environment where you can't use sudo, set \
188
+ the :use_sudo variable to false.
189
+ DESC
190
+ task :stop, :roles => :app do
191
+
192
+ end
193
+
194
+ namespace :pending do
195
+ task :diff, :except => { :no_release => true } do
196
+ end
197
+
198
+ task :default, :except => { :no_release => true } do
199
+ end
200
+ end
201
+
202
+ namespace :web do
203
+ task :disable, :roles => :web, :except => { :no_release => true } do
204
+ end
205
+ task :enable, :roles => :web, :except => { :no_release => true } do
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,91 @@
1
+ require 'capistrano/recipes/deploy/strategy/base'
2
+
3
+ module Capistrano
4
+ module Deploy
5
+ module Strategy
6
+
7
+ class Awesome < Base
8
+
9
+ def setup!
10
+ run "sudo rm -rf #{configuration[:deploy_to]}"
11
+ run "sudo mkdir -p #{configuration[:deploy_to]} && sudo chown -R #{configuration[:passenger_user]}:#{configuration[:passenger_user]} #{configuration[:deploy_to]}"
12
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git clone #{configuration[:repository]} ."
13
+ run "sudo mkdir -p #{configuration[:deploy_to]}/log && sudo mkdir -p #{configuration[:deploy_to]}/tmp"
14
+ deploy_no_tag
15
+ end
16
+
17
+ def check!
18
+
19
+ end
20
+
21
+ def deploy!
22
+ puts "\n\n### DEPLOY!: Deploying...\n\n"
23
+ unless @tag_created
24
+ create_tag
25
+ @tag_created = true
26
+ end
27
+ get_tag
28
+ deploy_no_tag
29
+ end
30
+
31
+ def rollback!
32
+ puts "\n\n### ROLLBACK!: Rolling back...\n\n"
33
+ unless @got_tag
34
+ get_tag
35
+ @got_tag = true
36
+ end
37
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout ."
38
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout #{@tag}"
39
+ end
40
+
41
+ def migrate!
42
+ puts "\n\n### MIGRATE!: Migrating...\n\n"
43
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout #{configuration[:branch]}"
44
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git pull"
45
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} #{configuration[:ruby_bin_dir]}/bundle exec rake db:migrate --trace RAILS_ENV=#{configuration[:rails_env]}"
46
+ end
47
+
48
+ def restart!
49
+ puts "\n\n### RESTART!: Restarting the Passengers...\n\n"
50
+ run "sudo chown -R #{configuration[:passenger_user]}:#{configuration[:passenger_group]} #{configuration[:deploy_to]}"
51
+ run "sudo touch #{configuration[:deploy_to]}/tmp/restart.txt"
52
+ end
53
+
54
+ protected
55
+
56
+ def create_tag
57
+ puts "\n\n### CREATE TAG: Tagging the current version before updating...\n\n"
58
+ @tag = "#{configuration[:application]}_#{Time.now.strftime("%Y%m%d%H%M%S")}"
59
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git tag #{@tag}", :roles => :app, :only => { :primary => true }
60
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git push --tags", :roles => :app, :only => { :primary => true }
61
+ # Create an empty file with our tag name, so we can easily go grab the tagname for rollback
62
+ run "sudo rm -f #{File.join(configuration[:latest_tag_dir], '*')}"
63
+ run "sudo mkdir -p #{configuration[:latest_tag_dir]}"
64
+ run "sudo touch #{File.join(configuration[:latest_tag_dir], @tag)}"
65
+ puts "\nSetting latest tag as #{@tag}\n"
66
+ end
67
+
68
+ def get_tag
69
+ puts "\n\n### GET TAG: Retrieving the latest version...\n\n"
70
+ run "ls " + File.join(configuration[:latest_tag_dir]).to_s, :roles => :app, :only => { :primary => true } do |ch, stream, data|
71
+ if stream == :err
72
+ puts "capured output on STDERR: #{data}"
73
+ else # stream == :out
74
+ data = data.strip
75
+ @tag = data
76
+ puts "\nLatest tag is #{@tag}\n\n"
77
+ end
78
+ end
79
+ end
80
+
81
+ def deploy_no_tag
82
+ puts "\n\n### DEPLOY NO TAG: Deploying to #{configuration[:stage]} at #{configuration[:deploy_to]}\n\n"
83
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout . && sudo -u #{configuration[:sudo_user]} git checkout #{configuration[:branch]}" # make sure we're on the right branch
84
+ run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git pull" # get head
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'capistrano-git'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCapistranoGit < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-git
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Ryan Moran
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ hash: 1
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 5
31
+ version: 0.5.5
32
+ version_requirements: *id001
33
+ name: capistrano_colors
34
+ prerelease: false
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 7
43
+ segments:
44
+ - 1
45
+ - 6
46
+ - 4
47
+ version: 1.6.4
48
+ version_requirements: *id002
49
+ name: jeweler
50
+ prerelease: false
51
+ type: :development
52
+ description: Capistrano recipe for deploying from git
53
+ email: ryan.moran@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - LICENSE.txt
60
+ - README.rdoc
61
+ files:
62
+ - .document
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION
69
+ - capistrano-git.gemspec
70
+ - lib/capistrano/git/bootstrap.rb
71
+ - lib/capistrano/git/overrides.rb
72
+ - lib/capistrano/git/strategy.rb
73
+ - test/helper.rb
74
+ - test/test_capistrano-git.rb
75
+ homepage: http://github.com/ryanmoran/capistrano-git
76
+ licenses:
77
+ - MIT
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.6
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Capistrano recipe for deploying from git
108
+ test_files: []
109
+