caploy 0.2.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f94ff6a9cd33e877b7e4549a6a9f0f388f9b21d1
4
+ data.tar.gz: 05fb7c1d5234e6b1ed6cecd37bb43bb5a4828531
5
+ SHA512:
6
+ metadata.gz: ad4eb74d7811e5f654266d2a4e592af807c65febd1fe00fc350c3305e765031cd59236c018f44e216e0431a84406c05726af5a6d4eb8a81d54ecd46ca43d585f
7
+ data.tar.gz: c39d83b0ef24bfd87973059810c8442a52e5d4692d22c3c5b0de2789006623b516935b6ad1b09dd2098ac3c61e14c8feff2bc8972255ac8aa0f150fe81f7d8fb
data/caploy.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/caploy/version', __FILE__)
4
4
  Gem::Specification.new do |spec|
5
5
  spec.authors = ['Michael Schiller']
6
6
  spec.email = ['michael.schiller@gmx.de']
7
- spec.description = %q{capistrano deployment tasks}
7
+ spec.description = %q{capistrano deployment helpling}
8
8
  spec.summary = %q{capistrano deployment tasks for different projects}
9
9
  spec.homepage = 'https://github.com/mschiller/caploy'
10
10
  spec.license = 'MIT'
@@ -12,21 +12,15 @@ Gem::Specification.new do |spec|
12
12
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
13
  spec.files = `git ls-files`.split("\n")
14
14
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- spec.name = "caploy"
15
+ spec.name = 'caploy'
16
16
  spec.require_paths = ['lib']
17
17
 
18
18
  spec.add_dependency('gemcutter')
19
19
 
20
- spec.add_dependency('capistrano', '>= 2.13.5')
21
- spec.add_dependency('capistrano-ext', '>= 1.2.1')
22
- spec.add_dependency('capistrano_colors', '>= 0.5.5')
23
- spec.add_dependency('capistrano-file_db', '>= 0.1.0')
24
- spec.add_dependency('capistrano-uptodate', '>= 0.0.2')
25
- spec.add_dependency('capistrano-multiconfig', '>= 0.0.4')
26
- spec.add_dependency('capistrano-patch', '>= 0.0.2')
27
- spec.add_dependency('capistrano-calendar', '>= 0.1.2')
28
- spec.add_dependency('rvm-capistrano', '>= 1.2.7')
29
- spec.add_dependency('erubis')
20
+ spec.add_dependency('capistrano-rails', '1.1.1')
21
+ spec.add_dependency('capistrano-bundler', '1.1.3')
22
+ spec.add_dependency('capistrano-rbenv', '2.0.2')
23
+ spec.add_dependency('capistrano3-unicorn', '0.2.1')
30
24
 
31
25
  spec.version = Caploy::VERSION
32
26
  end
@@ -0,0 +1,13 @@
1
+ require 'caploy'
2
+ require 'rails'
3
+
4
+ module Caploy
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :caploy
7
+
8
+ rake_tasks do
9
+ load File.join(File.dirname(__FILE__), "tasks/assets.rake")
10
+ #Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |f| load f }
11
+ end
12
+ end
13
+ end
@@ -1,26 +1,18 @@
1
1
  Capistrano::Configuration.instance.load do
2
-
3
- load 'deploy/assets' unless ENV['NOASSETS'] # http://guides.rubyonrails.org/asset_pipeline.html#in-production
4
-
5
- set :assets_dir, 'system' unless exists?(:assets_dir)
6
- set :local_assets_dir, 'public' unless exists?(:local_assets_dir)
7
-
8
- namespace :assets do
9
- namespace :local do
10
- desc 'Synchronize your local assets using remote assets'
11
- task :sync do
12
- if Util.prompt "Are you sure you want to erase your local assets with server assets"
13
- servers = find_servers :roles => :app
14
- [assets_dir].flatten.each do |dir|
15
- system("rsync -a --del --progress --rsh='ssh -p #{fetch(:ssh_port, 22)}' #{user}@#{servers.first}:#{shared_path}/#{dir}/ #{local_assets_dir}")
16
- end
2
+ namespace :local do
3
+ desc 'Synchronize your local assets using remote assets'
4
+ task :sync do
5
+ if Util.prompt "Are you sure you want to erase your local assets with server assets"
6
+ servers = find_servers :roles => :app
7
+ [assets_dir].flatten.each do |dir|
8
+ system("rsync -a --del --progress --rsh='ssh -p #{fetch(:ssh_port, 22)}' #{user}@#{servers.first}:#{shared_path}/#{dir}/ #{local_assets_dir}")
17
9
  end
18
10
  end
19
11
  end
12
+ end
20
13
 
21
- desc 'Synchronize your local assets using remote assets'
22
- task :pull do
23
- assets.local.sync
24
- end
14
+ desc 'Synchronize your local assets using remote assets'
15
+ task :pull do
16
+ assets.local.sync
25
17
  end
26
18
  end
@@ -1,58 +1,55 @@
1
- Capistrano::Configuration.instance.load do |instance|
2
-
3
- require File.expand_path("#{File.dirname(__FILE__)}/../../util")
4
- require File.expand_path("#{File.dirname(__FILE__)}/../../mysql")
5
-
6
- instance.set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless exists?(:local_rails_env)
7
- instance.set :db_local_clean, false unless exists?(:db_local_clean)
8
-
9
- namespace :db do
10
- namespace :remote do
11
- desc 'Synchronize the local database to the remote database'
12
- task :sync, :roles => :db do
13
- if if Util.prompt 'Are you sure you want to REPLACE THE REMOTE DATABASE with local database'
14
- Database.local_to_remote(instance)
15
- end
16
- end
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../util")
2
+ require File.expand_path("#{File.dirname(__FILE__)}/../../mysql")
3
+
4
+ instance.set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless exists?(:local_rails_env)
5
+ instance.set :db_local_clean, false unless exists?(:db_local_clean)
6
+
7
+ namespace :db do
8
+ namespace :remote do
9
+ desc 'Synchronize the local database to the remote database'
10
+ task :sync, :roles => :db do
11
+ if if Util.prompt 'Are you sure you want to REPLACE THE REMOTE DATABASE with local database'
12
+ Database.local_to_remote(instance)
17
13
  end
14
+ end
15
+ end
18
16
 
19
- namespace :local do
20
- desc 'Synchronize your local database using remote database data'
21
- task :sync, :roles => :db do
22
- puts "Local database: #{Database::Local.new(instance).database}"
23
- if rails_env == 'production'
24
- puts 'Never sync remote production database!'
25
- else
26
- if Util.prompt 'Are you sure you want to erase your local database with server database'
27
- Database.remote_to_local(instance)
28
- end
17
+ namespace :local do
18
+ desc 'Synchronize your local database using remote database data'
19
+ task :sync, :roles => :db do
20
+ puts "Local database: #{Database::Local.new(instance).database}"
21
+ if rails_env == 'production'
22
+ puts 'Never sync remote production database!'
23
+ else
24
+ if Util.prompt 'Are you sure you want to erase your local database with server database'
25
+ Database.remote_to_local(instance)
29
26
  end
30
27
  end
31
28
  end
29
+ end
32
30
 
33
- desc 'Synchronize your local database using remote database data'
34
- task :pull do
35
- db.local.sync
36
- end
31
+ desc 'Synchronize your local database using remote database data'
32
+ task :pull do
33
+ db.local.sync
34
+ end
37
35
 
38
- desc 'Synchronize the local database to the remote database'
39
- task :push do
40
- db.remote.sync
41
- end
36
+ desc 'Synchronize the local database to the remote database'
37
+ task :push do
38
+ db.remote.sync
42
39
  end
43
40
  end
44
-
45
- namespace :deploy do
46
- after 'deploy:make_symlinks', 'deploy:dynamic_migrations' if fetch(:dynamic_migration, false)
47
-
48
- task :dynamic_migrations do
49
- from = source.next_revision(current_revision)
50
- if capture("cd #{latest_release} && #{source.local.log(from)} db/migrate | wc -l").to_i > 0
51
- run "cd #{current_release} && RAILS_ENV=#{rails_env} #{rake} db:migrate"
52
- logger.info "New migrations added - running migrations."
53
- else
54
- logger.info "Skipping migrations - there are not any new."
55
- end
41
+ end
42
+
43
+ namespace :deploy do
44
+ after 'deploy:make_symlinks', 'deploy:dynamic_migrations' if fetch(:dynamic_migration, false)
45
+
46
+ task :dynamic_migrations do
47
+ from = source.next_revision(current_revision)
48
+ if capture("cd #{latest_release} && #{source.local.log(from)} db/migrate | wc -l").to_i > 0
49
+ run "cd #{current_release} && RAILS_ENV=#{rails_env} #{rake} db:migrate"
50
+ logger.info "New migrations added - running migrations."
51
+ else
52
+ logger.info "Skipping migrations - there are not any new."
56
53
  end
57
54
  end
58
- end
55
+ end
@@ -0,0 +1,219 @@
1
+
2
+ # Custom SSH Options
3
+ # ==================
4
+ # You may pass any option but keep in mind that net/ssh understands a
5
+ # limited set of options, consult[net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start).
6
+ #
7
+ # Global options
8
+ # --------------
9
+ # set :ssh_options, {
10
+ # keys: %w(/home/rlisowski/.ssh/id_rsa),
11
+ # forward_agent: false,
12
+ # auth_methods: %w(password)
13
+ # }
14
+ #
15
+ # And/or per server (overrides global)
16
+ # ------------------------------------
17
+ # server 'example.com',
18
+ # user: 'user_name',
19
+ # roles: %w{web app},
20
+ # ssh_options: {
21
+ # user: 'user_name', # overrides user setting above
22
+ # keys: %w(/home/user_name/.ssh/id_rsa),
23
+ # forward_agent: false,
24
+ # auth_methods: %w(publickey password)
25
+ # # password: 'please use keys'
26
+ # }
27
+
28
+ #set :unicorn_hard_restart, true if ENV['HARD_RESTART']
29
+
30
+ # what specs should be run before deployment is allowed to
31
+ # continue, see lib/capistrano/tasks/run_tests.cap
32
+ # set :tests, []
33
+
34
+ # files which need to be symlinked to other parts of the
35
+ # filesystem. For example nginx virtualhosts, log rotation
36
+ # init scripts etc.
37
+ # set(:symlinks, [
38
+ # {
39
+ # source: "nginx.conf",
40
+ # link: "/etc/nginx/sites-enabled/#{fetch(:full_app_name)}"
41
+ # },
42
+ # {
43
+ # source: "unicorn_init.sh",
44
+ # link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
45
+ # }
46
+ # ])
47
+
48
+ # which config files should be copied by deploy:setup_config
49
+ # see documentation in lib/capistrano/tasks/setup_config.cap
50
+ # for details of operations
51
+ # set(:config_files, %w(
52
+ # nginx.conf
53
+ # database.example.yml
54
+ # unicorn.rb
55
+ # unicorn_init.sh
56
+ # ))
57
+
58
+ # Default branch is :master
59
+ # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
60
+
61
+ # Default value for :scm is :git
62
+ # set :scm, :git
63
+
64
+ # Default value for :format is :pretty
65
+ # set :format, :pretty
66
+
67
+ # Default value for :log_level is :debug
68
+ # set :log_level, :debug
69
+
70
+ # Default value for :pty is false
71
+ # set :pty, true
72
+
73
+ # Default value for default_env is {}
74
+ # set :default_env, { path: "/opt/ruby/bin:$PATH" }
75
+
76
+ namespace :deploy do
77
+ task :restart do
78
+ invoke 'unicorn:restart'
79
+ end
80
+
81
+ desc 'build missing paperclip styles'
82
+ task :build_missing_paperclip_styles do # app
83
+ run "cd #{current_path}; RAILS_ENV=#{rails_env} #{rake} paperclip:refresh:missing_styles"
84
+ end
85
+
86
+ desc "checks whether the currently checkout out revision matches the
87
+ remote one we're trying to deploy from"
88
+ task :check_revision do
89
+ branch = fetch(:branch)
90
+ unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
91
+ puts "WARNING: HEAD is not the same as origin/#{branch}"
92
+ puts "Run `git push` to sync changes or make sure you've"
93
+ puts "checked out the branch: #{branch} as you can only deploy"
94
+ puts "if you've got the target branch checked out"
95
+ exit
96
+ end
97
+ end
98
+
99
+ desc 'compiles assets locally then rsyncs'
100
+ task :compile_assets_locally do
101
+ run_locally do
102
+ execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile"
103
+ end
104
+ on roles(:app) do |role|
105
+ run_locally do
106
+ execute "rsync -av ./public/assets/ #{role.user}@#{role.hostname}:#{release_path}/public/assets/;"
107
+ end
108
+ sudo "chmod -R 755 #{release_path}/public/assets/"
109
+ end
110
+ run_locally do
111
+ execute 'rm -rf ./public/assets'
112
+ end
113
+ end
114
+
115
+ desc 'Run the full tests on the deployed app. To deploy without tests, try cap deploy:without_tests or cap -S run_tests=0 deploy'
116
+ task :run_tests do
117
+ unless fetch(:run_tests, '1') == '0'
118
+ run "cd #{release_path} && rake db:test:prepare"
119
+ run "cd #{release_path} && nice -n 10 rake RAILS_ENV=production test"
120
+ end
121
+ end
122
+
123
+ desc 'deploy without running tests'
124
+ task :without_tests do
125
+ set(:run_tests, '0')
126
+ deploy.default
127
+ end
128
+
129
+ task :set_branch_info_file do
130
+ on roles(:app) do
131
+ run "cd #{release_path} && echo \"#{branch}\" > CURRENT_BRANCH"
132
+ end
133
+ end
134
+
135
+ namespace :cache do
136
+ desc "Flush cache"
137
+ task :clear do
138
+ on roles(:app) do
139
+ run "cd #{current_path} && #{rake} cache:clear RAILS_ENV=#{rails_env}"
140
+ end
141
+ end
142
+ end
143
+
144
+ desc 'Show deployed revision'
145
+ task :revision do
146
+ on roles(:app) do
147
+ run "cat #{current_path}/REVISION"
148
+ end
149
+ end
150
+
151
+ desc 'Show currently deployed revision on server.'
152
+ task :revisions do
153
+ on roles(:app) do
154
+ current, previous, latest = current_revision[0, 7], previous_revision[0, 7], real_revision[0, 7]
155
+ puts "\n" << "-"*63
156
+ puts "===== Master Revision: \033[1;33m#{latest}\033[0m\n\n"
157
+ puts "===== [ \033[1;36m#{application.capitalize} - #{stage.to_s.capitalize}\033[0m ]"
158
+ puts "=== Deployed Revision: \033[1;32m#{current}\033[0m"
159
+ puts "=== Previous Revision: \033[1;32m#{previous}\033[0m\n\n"
160
+
161
+ # If deployed and master are the same, show the difference between the last 2 deployments.
162
+ base_label, new_label, base_rev, new_rev = latest != current ? \
163
+ ['deployed', 'master', current, latest] : \
164
+ ['previous', 'deployed', previous, current]
165
+
166
+ # Fetch the difference between master and deployed revisions.
167
+ log_cmd = "#{source.log(previous, latest).gsub(/^git/, 'git --no-pager')} --oneline"
168
+ cfg = File.join(shared_path, strategy.configuration[:repository_cache] || "cached-copy")
169
+
170
+ diff = ''
171
+ run %Q{cd "#{cfg}" && #{log_cmd}} do |channel, stream, data|
172
+ diff = data
173
+ end
174
+
175
+ # Show difference between master and deployed revisions.
176
+ if diff != ""
177
+ # Colorize refs
178
+ diff.gsub!(/^([a-f0-9]+) /, "\033[1;32m\\1\033[0m - ")
179
+ diff = " " << diff.gsub("\n", "\n ") << "\n"
180
+ # Indent commit messages nicely, max 80 chars per line, line has to end with space.
181
+ diff = diff.split("\n").map { |l| l.scan(/.{1,80}/).join("\n"<<" "*14).gsub(/([^ ]*)\n {14}/m, "\n"<<" "*14<<"\\1") }.join("\n")
182
+ puts "=== Difference between #{base_label} revision and #{new_label} revision:\n\n"
183
+ puts diff
184
+ end
185
+ end
186
+ end
187
+ #after 'deploy', 'revisions'
188
+
189
+ after :finishing, 'deploy:cleanup'
190
+ after 'deploy:publishing', 'deploy:restart'
191
+ after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
192
+ #after('deploy:compile_assets', 'deploy:build_missing_paperclip_styles')
193
+
194
+ # make sure we're deploying what we think we're deploying
195
+ # before :deploy, 'deploy:check_revision'
196
+
197
+ # only allow a deploy with passing tests to deployed
198
+ # before :deploy, 'deploy:run_tests'
199
+
200
+ # setup section
201
+ #
202
+ # # remove the default nginx configuration as it will tend
203
+ # # to conflict with our configs.
204
+ # before 'deploy:setup_config', 'nginx:remove_default_vhost'
205
+ #
206
+ # # reload nginx to it will pick up any modified vhosts from
207
+ # # setup_config
208
+ # after 'deploy:setup_config', 'nginx:reload'
209
+
210
+ # whether we're using ssl or not, used for building nginx
211
+ # config file
212
+ # set :enable_ssl, false
213
+
214
+ #
215
+ # set :nginx_protocol, :
216
+ #
217
+ # if you want to remove the dump file after loading
218
+ # set :db_local_clean, true
219
+ end
@@ -1,38 +1,34 @@
1
- Capistrano::Configuration.instance.load do
2
-
3
- namespace :info do
4
- desc <<-DESC
1
+ namespace :info do
2
+ desc <<-DESC
5
3
  Tail all or a single remote file
6
4
 
7
5
  The logfile can be specified with a LOGFILE-environment variable.
8
6
  It defaults to RAILS_ENV.log
9
- DESC
10
- task :tail, :roles => :app do
11
- ENV["LOGFILE"] ||= "#{rails_env}.log"
12
- begin
13
- stream "tail -f #{shared_path}/log/#{ENV["LOGFILE"]}"
14
- rescue Interrupt
15
- puts "\n--interrupted by user--"
16
- puts ""
17
- end
7
+ DESC
8
+ task :tail, :roles => :app do
9
+ ENV["LOGFILE"] ||= "#{rails_env}.log"
10
+ begin
11
+ stream "tail -f #{shared_path}/log/#{ENV["LOGFILE"]}"
12
+ rescue Interrupt
13
+ puts "\n--interrupted by user--"
14
+ puts ''
18
15
  end
16
+ end
19
17
 
20
- desc "Display the currently deployed Application, Revision and Release"
21
- task :version, :roles => :app, :except => { :no_release => true } do
22
- rev = current_revision
23
- rel = current_release.split('/').pop
24
-
25
- puts ""
26
- puts " AppName: #{fetch(:application)}"
27
- puts " Version: #{rev}"
28
- puts " Release: #{rel}"
29
- puts ""
30
- end
18
+ desc 'Display the currently deployed Application, Revision and Release'
19
+ task :version, :roles => :app, :except => { :no_release => true } do
20
+ rev = current_revision
21
+ rel = current_release.split('/').pop
31
22
 
32
- desc "Display the uname"
33
- task :uname do
34
- run "uname -a"
35
- end
23
+ puts ""
24
+ puts " AppName: #{fetch(:application)}"
25
+ puts " Version: #{rev}"
26
+ puts " Release: #{rel}"
27
+ puts ""
36
28
  end
37
29
 
30
+ desc "Display the uname"
31
+ task :uname do
32
+ run "uname -a"
33
+ end
38
34
  end
@@ -1,17 +1,13 @@
1
- Capistrano::Configuration.instance.load do
2
-
3
- namespace :memcache do
4
- %w(start stop restart status).each do |step|
5
- desc "#{step} memcache"
6
- task step do
7
- try_sudo "service memcached #{step}"
8
- end
9
- end
10
-
11
- desc "Flush memcache"
12
- task :flush do
13
- run %Q{echo "flush_all" | nc -q 2 127.0.0.1 11211}
1
+ namespace :memcache do
2
+ %w(start stop restart status).each do |step|
3
+ desc "#{step} memcache"
4
+ task step do
5
+ try_sudo "service memcached #{step}"
14
6
  end
15
7
  end
16
8
 
9
+ desc "Flush memcache"
10
+ task :flush do
11
+ run %Q{echo "flush_all" | nc -q 2 127.0.0.1 11211}
12
+ end
17
13
  end