cap-git-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/Gemfile +4 -0
- data/README.md +2 -0
- data/cap-git-deploy.gemspec +24 -0
- data/lib/cap-git-deploy/version.rb +7 -0
- data/lib/cap-git-deploy.rb +31 -0
- data/lib/recipes/fast-git-deploy.rb +115 -0
- metadata +74 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cap-git-deploy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cap-git-deploy"
|
7
|
+
s.version = Cap::Git::Deploy::VERSION
|
8
|
+
s.authors = ["Nicola Racco"]
|
9
|
+
s.email = ["nicola@mikamai.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Mikamai-style deploy strategy}
|
12
|
+
s.description = %q{Mikamai-style deploy strategy}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here; for example:
|
20
|
+
# s.add_development_dependency "rspec"
|
21
|
+
#
|
22
|
+
s.add_runtime_dependency "capistrano"
|
23
|
+
s.add_runtime_dependency "grit"
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require "cap-git-deploy/version"
|
3
|
+
|
4
|
+
require 'grit'
|
5
|
+
require 'etc'
|
6
|
+
|
7
|
+
module Cap
|
8
|
+
module Git
|
9
|
+
module Deploy
|
10
|
+
# utility functions
|
11
|
+
|
12
|
+
def self.current_branch
|
13
|
+
repo = Grit::Repo.new '.'
|
14
|
+
branch = repo.head
|
15
|
+
# if branch is nil, we are in a spurius commit, then we should use master
|
16
|
+
branch && branch.name || 'master'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.current_user
|
20
|
+
"#{Etc.getlogin}@#{Socket.gethostname}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if Capistrano::Configuration.instance
|
27
|
+
Capistrano::Configuration.instance.load_paths << File.join(File.dirname(__FILE__), "recipes")
|
28
|
+
Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).sort.each do |f|
|
29
|
+
Capistrano::Configuration.instance.load f
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
set :rolling_back, false
|
2
|
+
set :scm, :git
|
3
|
+
set :logged_user, Cap::Git::Deploy.current_user
|
4
|
+
set :branch, ENV['branch'] || Cap::Git::Deploy.current_branch unless exists? :branch
|
5
|
+
|
6
|
+
namespace :deploy do
|
7
|
+
task :default do
|
8
|
+
update
|
9
|
+
update_revision
|
10
|
+
restart
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Setup a GitHub-style deployment"
|
14
|
+
task :setup, :except => { :no_release => true } do
|
15
|
+
dirs = [deploy_to, shared_path]
|
16
|
+
dirs += shared_children.map do |shared_child|
|
17
|
+
File.join shared_path, shared_child
|
18
|
+
end
|
19
|
+
run "mkdir -p #{dirs.join ' '} && chmod g+w #{dirs.join ' '}"
|
20
|
+
run "git clone #{repository} #{current_path}"
|
21
|
+
|
22
|
+
# This is where the log files will go
|
23
|
+
run "mkdir -p #{current_path}/log" rescue 'no problem if log already exist'
|
24
|
+
|
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}"
|
36
|
+
end
|
37
|
+
|
38
|
+
namespace :rollback do
|
39
|
+
desc "Rollback to previous release"
|
40
|
+
task :default, :except => { :no_release => true } do
|
41
|
+
latest_tag = nil
|
42
|
+
run "cd #{current_path}; git describe --tags --match deploy_* --abbrev=0 HEAD^" do |channel, stream, data|
|
43
|
+
latest_tag = data.strip
|
44
|
+
end
|
45
|
+
|
46
|
+
if latest_tag
|
47
|
+
set :branch, latest_tag
|
48
|
+
set :rolling_back, true
|
49
|
+
deploy::default
|
50
|
+
else
|
51
|
+
STDERR.puts "ERROR: Couldn't find tag to rollback to. Maybe you're already at the oldest possible tag?"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
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
|
79
|
+
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
|
+
end
|
89
|
+
|
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
|
96
|
+
|
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"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
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
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
after "deploy:restart", "deploy:migrate"
|
115
|
+
after "deploy:update_code", "deploy:bundle"
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap-git-deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicola Racco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: &70289454584000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70289454584000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: grit
|
27
|
+
requirement: &70289454583580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70289454583580
|
36
|
+
description: Mikamai-style deploy strategy
|
37
|
+
email:
|
38
|
+
- nicola@mikamai.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- Gemfile
|
44
|
+
- README.md
|
45
|
+
- cap-git-deploy.gemspec
|
46
|
+
- lib/cap-git-deploy.rb
|
47
|
+
- lib/cap-git-deploy/version.rb
|
48
|
+
- lib/recipes/fast-git-deploy.rb
|
49
|
+
homepage: ''
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.10
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Mikamai-style deploy strategy
|
73
|
+
test_files: []
|
74
|
+
has_rdoc:
|