capistrano-deploy 0.0.1
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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +83 -0
- data/Rakefile +2 -0
- data/capistrano-deploy.gemspec +14 -0
- data/lib/capistrano-deploy/bundle.rb +15 -0
- data/lib/capistrano-deploy/deploy.rb +59 -0
- data/lib/capistrano-deploy/multistage.rb +26 -0
- data/lib/capistrano-deploy/unicorn.rb +15 -0
- data/lib/capistrano-deploy/whenever.rb +16 -0
- metadata +77 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Capistrano recipes
|
2
|
+
==================
|
3
|
+
|
4
|
+
Deploy
|
5
|
+
------
|
6
|
+
|
7
|
+
Git-based deployment process.
|
8
|
+
|
9
|
+
Minimal Capfile for deploy:
|
10
|
+
|
11
|
+
require 'capistrano-lest/deploy'
|
12
|
+
|
13
|
+
server 'server name or ip address', :web, :app, :db, :primary => true
|
14
|
+
set :user, 'user for deploy'
|
15
|
+
set :deploy_to, '/deploy/to/path'
|
16
|
+
set :repository, 'your git repository'
|
17
|
+
|
18
|
+
To setup:
|
19
|
+
|
20
|
+
!!!plain
|
21
|
+
cap deploy:setup
|
22
|
+
|
23
|
+
Then when you push some changes to git repository simply run:
|
24
|
+
|
25
|
+
!!!plain
|
26
|
+
cap deploy
|
27
|
+
|
28
|
+
If you have migrations instead of previous command run:
|
29
|
+
|
30
|
+
!!!plain
|
31
|
+
cap deploy:migrations
|
32
|
+
|
33
|
+
To look through changes to be deployed:
|
34
|
+
|
35
|
+
!!!plain
|
36
|
+
cap deploy:pending
|
37
|
+
|
38
|
+
Multistage
|
39
|
+
----------
|
40
|
+
|
41
|
+
require 'capistrano-lest/multistage'
|
42
|
+
|
43
|
+
set :default_stage, :development
|
44
|
+
|
45
|
+
define_stage :development do
|
46
|
+
...
|
47
|
+
end
|
48
|
+
|
49
|
+
define_stage :production do
|
50
|
+
...
|
51
|
+
end
|
52
|
+
|
53
|
+
Bundle
|
54
|
+
------
|
55
|
+
|
56
|
+
require 'capistrano-lest/bundle'
|
57
|
+
|
58
|
+
To automatically install missing gems:
|
59
|
+
|
60
|
+
after 'deploy:update_code', 'bundle:install'
|
61
|
+
|
62
|
+
Unicorn
|
63
|
+
-------
|
64
|
+
|
65
|
+
require 'capistrano-lest/unicorn'
|
66
|
+
|
67
|
+
Now you can setup to reload unicorn on `deploy:restart`:
|
68
|
+
|
69
|
+
after 'deploy:restart', 'unicorn:reload'
|
70
|
+
|
71
|
+
Whenever
|
72
|
+
--------
|
73
|
+
|
74
|
+
require 'capistrano-lest/whenever'
|
75
|
+
|
76
|
+
To automatically update crontab file:
|
77
|
+
|
78
|
+
after 'deploy:restart', 'whenever:update_crontab'
|
79
|
+
|
80
|
+
You can also clear crontab file with command:
|
81
|
+
|
82
|
+
!!!plain
|
83
|
+
cap whenever:clear_crontab
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'capistrano-deploy'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ['Just Lest']
|
7
|
+
s.email = ['just.lest@gmail.com']
|
8
|
+
s.homepage = 'https://github.com/lest/capistrano-deploy'
|
9
|
+
s.summary = 'Capistrano deploy recipes'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :bundle do
|
3
|
+
desc 'Install gems'
|
4
|
+
task :install, :except => {:no_release => true} do
|
5
|
+
bundle_cmd = fetch(:bundle_cmd, 'bundle')
|
6
|
+
bundle_flags = fetch(:bundle_flags, '--deployment --quiet')
|
7
|
+
bundle_without = [*fetch(:bundle_without, [:development, :test])].compact
|
8
|
+
|
9
|
+
args = [bundle_flags.to_s]
|
10
|
+
args << "--without #{bundle_without.join(' ')}" unless bundle_without.empty?
|
11
|
+
|
12
|
+
run "cd #{deploy_to} && #{bundle_cmd} install #{args.join(' ')}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
ssh_options[:forward_agent] = true
|
3
|
+
|
4
|
+
set(:application) { repository.slice(/[^\/:]+?(?=\.git$)/) }
|
5
|
+
set(:repository) { abort "Please specify repository, set :repository, 'foo'" }
|
6
|
+
set(:deploy_to) { abort "Please specify deploy directory, set :deploy_to, '/deploy/to/path'" }
|
7
|
+
|
8
|
+
set :branch, 'master'
|
9
|
+
|
10
|
+
set(:current_revision) { capture("cd #{deploy_to} && git rev-parse HEAD").chomp }
|
11
|
+
|
12
|
+
namespace :deploy do
|
13
|
+
desc 'Deploy'
|
14
|
+
task :default do
|
15
|
+
update
|
16
|
+
restart
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Deploy & migrate'
|
20
|
+
task :migrations do
|
21
|
+
update_code
|
22
|
+
migrate
|
23
|
+
restart
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Setup'
|
27
|
+
task :setup, :except => {:no_release => true} do
|
28
|
+
run "mkdir -p `dirname #{deploy_to}` && git clone --no-checkout #{repository} #{deploy_to}"
|
29
|
+
update_code
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Update'
|
33
|
+
task :update do
|
34
|
+
update_code
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Update the deployed code'
|
38
|
+
task :update_code, :except => {:no_release => true} do
|
39
|
+
run "cd #{deploy_to} && git fetch origin && git reset --hard origin/#{branch}"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Run migrations'
|
43
|
+
task :migrate, :roles => :db, :only => {:primary => true} do
|
44
|
+
rake = fetch(:rake, 'rake')
|
45
|
+
rails_env = fetch(:rails_env, 'production')
|
46
|
+
run "cd #{deploy_to} && RAILS_ENV=#{rails_env} #{rake} db:migrate"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Restart'
|
50
|
+
task :restart do
|
51
|
+
# nothing
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Show pending commits'
|
55
|
+
task :pending do
|
56
|
+
system("git log --pretty=medium --stat #{current_revision}..origin/#{branch}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
set :multistage_stages, []
|
3
|
+
|
4
|
+
def define_stage(name, &block)
|
5
|
+
multistage_stages << name
|
6
|
+
callbacks[:start].detect { |c| c.source == 'multistage:ensure' }.except << name.to_s
|
7
|
+
task(name) do
|
8
|
+
set :stage, name
|
9
|
+
block.call
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :multistage do
|
14
|
+
task :ensure do
|
15
|
+
unless exists?(:stage)
|
16
|
+
if exists?(:default_stage)
|
17
|
+
find_and_execute_task(default_stage)
|
18
|
+
else
|
19
|
+
abort "No stage specified. Please specify one of: #{multistage_stages.join(', ')} (e.g. `cap #{multistage_stages.first} #{ARGV.last}')"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
on :start, 'multistage:ensure'
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
set(:unicorn_pid) { "`cat #{deploy_to}/tmp/pids/unicorn.pid`" }
|
3
|
+
|
4
|
+
namespace :unicorn do
|
5
|
+
desc 'Reload unicorn'
|
6
|
+
task :reload, :roles => :app, :except => {:no_release => true} do
|
7
|
+
run "kill -HUP #{unicorn_pid}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Stop unicorn'
|
11
|
+
task :stop, :roles => :app, :except => {:no_release => true} do
|
12
|
+
run "kill -QUIT #{unicorn_pid}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
set(:whenever_cmd) { 'whenever' }
|
3
|
+
set(:whenever_identifier) { application }
|
4
|
+
|
5
|
+
namespace :whenever do
|
6
|
+
desc 'Update crontab file'
|
7
|
+
task :update_crontab, :roles => :db, :only => {:primary => true} do
|
8
|
+
run "cd #{deploy_to} && #{whenever_cmd} --update-crontab #{whenever_identifier}"
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Clear crontab file'
|
12
|
+
task :clear_crontab, :roles => :db, :only => {:primary => true} do
|
13
|
+
run "cd #{deploy_to} && #{whenever_cmd} --clear-crontab #{whenever_identifier}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Just Lest
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-11 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email:
|
24
|
+
- just.lest@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- capistrano-deploy.gemspec
|
37
|
+
- lib/capistrano-deploy/bundle.rb
|
38
|
+
- lib/capistrano-deploy/deploy.rb
|
39
|
+
- lib/capistrano-deploy/multistage.rb
|
40
|
+
- lib/capistrano-deploy/unicorn.rb
|
41
|
+
- lib/capistrano-deploy/whenever.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: https://github.com/lest/capistrano-deploy
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.5.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Capistrano deploy recipes
|
76
|
+
test_files: []
|
77
|
+
|