capistrano-deploy-tagger 2.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.
- data/lib/capistrano/deploy/tagger.rb +85 -0
- metadata +83 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
def git(cmd, opts={:output => false})
|
5
|
+
opts[:output] ? `git #{cmd} #{debug}`.chomp : system("git #{cmd} > /dev/null 2>&1")
|
6
|
+
end
|
7
|
+
|
8
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
9
|
+
|
10
|
+
namespace :deploy do
|
11
|
+
|
12
|
+
after "deploy", "tagger:tag"
|
13
|
+
|
14
|
+
namespace :tagger do
|
15
|
+
desc "Manage git tags to indicate current deployed codebase, and keep a history of the most recent deploys."
|
16
|
+
|
17
|
+
task :tag do
|
18
|
+
|
19
|
+
update_tag = fetch(:update_deploy_tags) rescue true
|
20
|
+
tag_name = fetch(:latest_deploy_tag) rescue "inproduction"
|
21
|
+
# keep_deploy_tags = fetch(:keep_deploy_tags) rescue 10
|
22
|
+
current_branch = fetch(:branch)
|
23
|
+
|
24
|
+
if update_tag
|
25
|
+
|
26
|
+
user = git("config --get user.name", {:output => true})
|
27
|
+
email = git("config --get user.email", {:output => true})
|
28
|
+
|
29
|
+
puts "[Capistrano-Deploy-Tagger] Updating deployment Git tags...\n\n"
|
30
|
+
|
31
|
+
git "fetch --tags", {:output => true}
|
32
|
+
|
33
|
+
# Remove any existing deploy-branch-date tags first - this is in case of multiple deploys of the same revision,
|
34
|
+
# we don't want multiple copies of those tags to start stacking up on the same revision.
|
35
|
+
# git("tag -l --contains #{revision} deploy-#{current_branch}-*", {:output => true}).to_a.each do |tag|
|
36
|
+
# git "tag -d #{tag}"
|
37
|
+
# git "push origin :#{tag}"
|
38
|
+
# end
|
39
|
+
|
40
|
+
# Create a tag for the current deploy with time and date, we'll keep a few of these for history.
|
41
|
+
deploy_tag_string = Time.now.strftime("deploy-%Y%m%d-%H%M-%S")
|
42
|
+
git "tag #{deploy_tag_string} #{revision} -m \"Deployment by #{user} <#{email}>.\""
|
43
|
+
|
44
|
+
# Remove older deploy tags, ensuring we keep at least ':keep_deploy_tags' of the more recent deploy tags.
|
45
|
+
# expired_deploy_tags = git("tag -l deploy-#{current_branch}-*", {:output => true}).to_a
|
46
|
+
# expired_deploy_tags.pop(keep_deploy_tags)
|
47
|
+
|
48
|
+
# expired_deploy_tags.each do |tag|
|
49
|
+
# git "tag -d #{tag}"
|
50
|
+
# git "push origin :#{tag}"
|
51
|
+
# end
|
52
|
+
|
53
|
+
# Remove an existing 'latest_deploy_tag' tag, then recreate it at the current revision.
|
54
|
+
if git("tag -l #{tag_name}", {:output => true}) == tag_name
|
55
|
+
git "tag -d #{tag_name}", {:output => true}
|
56
|
+
git "push origin :#{tag_name}", {:output => true}
|
57
|
+
end
|
58
|
+
git "tag #{tag_name} #{revision} -m \"Latest deploy tag updated by #{user} <#{email}>.\"", {:output => true}
|
59
|
+
|
60
|
+
git "push --tags", {:output => true}
|
61
|
+
|
62
|
+
else
|
63
|
+
|
64
|
+
puts "[Capistrano-Deploy-Tagger] Not updating deployment Git tags..."
|
65
|
+
puts "To enable this behaviour, add the following to your deploy.rb: 'set :update_deploy_tags, true'."
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
task :automatic do
|
74
|
+
# The EC2 autoscale self deploy tool calls 'bundle exec cap automatic deploy' to trigger this.
|
75
|
+
# We set 'update_selfdeploy_tag' to false so the selfdeploy_tag isn't altered during autoscaling.
|
76
|
+
# We also override the branch to deploy from to be the selfdeploy_tag.
|
77
|
+
|
78
|
+
set :deploy_via, :export # Git + capistrano don't like switching to a tag from master
|
79
|
+
set :update_deploy_tags, false
|
80
|
+
|
81
|
+
tag_name = fetch(:latest_deploy_tag) rescue "inproduction"
|
82
|
+
set :branch, tag_name
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-deploy-tagger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryan Conway
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-08-01 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: capistrano
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Capistrano-Deploy-Tagger creates and updates certain tags in Git each time you perform a deploy. The first tag defaults to 'inproduction' and is always updated to refer to the revision that was just deployed. The second tag is a timestamp applied to every revision that is deployed to production.
|
38
|
+
email:
|
39
|
+
- ryan.conway@forward.co.uk
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- lib/capistrano/deploy/tagger.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/rylon/capistrano-deploy-tagger
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: capistrano-deploy-tagger
|
78
|
+
rubygems_version: 1.6.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Capistrano-Deploy-Tagger creates and updates certain tags in Git each time you perform a deploy.
|
82
|
+
test_files: []
|
83
|
+
|