crazycode-cap-recipes 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 0
3
- :minor: 4
4
- :patch: 14
3
+ :minor: 5
4
+ :patch: 1
5
5
  :build:
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "crazycode-cap-recipes"
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["crazycode"]
@@ -103,6 +103,7 @@ Gem::Specification.new do |s|
103
103
  "lib/cap_recipes/tasks/tomcat/install.rb",
104
104
  "lib/cap_recipes/tasks/tomcat/manage.rb",
105
105
  "lib/cap_recipes/tasks/tomcat/war.rb",
106
+ "lib/cap_recipes/tasks/uhljenkins.rb",
106
107
  "lib/cap_recipes/tasks/utilities.rb",
107
108
  "lib/cap_recipes/tasks/whenever.rb",
108
109
  "lib/cap_recipes/tasks/whenever/hooks.rb",
@@ -0,0 +1,207 @@
1
+ # -*- coding: utf-8 -*-
2
+ Capistrano::Configuration.instance(true).load do |configuration|
3
+ set :use_sudo, true
4
+
5
+ _cset :deploy_to_parent, "/srv/applications"
6
+ _cset :branch, "master"
7
+
8
+ default_run_options[:pty] = true
9
+
10
+ # this is capistrano's default location.
11
+ # depending on the permissions of the server
12
+ # you may need to create it and chown it over
13
+ # to :user (e.g. chown -R robotuser:robotuser /u)
14
+ set :deploy_to do
15
+ "#{deploy_to_parent}/#{application}"
16
+ end
17
+
18
+ set :deploy_to_gitrepo do
19
+ "#{deploy_to}/repo"
20
+ end
21
+
22
+
23
+ set :local_base_dir do
24
+ "#{`pwd`}".strip
25
+ end
26
+
27
+ _cset :war_config, Array.new
28
+ _cset :war_name, ""
29
+ _cset :war_path, "not set.war"
30
+
31
+ _cset :servers, ""
32
+ _cset :deploy_to, ""
33
+
34
+ set :local_git_dir do
35
+ "/tmp/localgit_#{application}"
36
+ end
37
+ set :local_gitrepo do
38
+ "#{local_git_dir}/#{application}"
39
+ end
40
+
41
+ role :app, :primary => true do
42
+ servers.split(/[,\s]+/).collect do|s|
43
+ unless s.include?(":")
44
+ "#{s}:58422"
45
+ else
46
+ s
47
+ end
48
+ end
49
+ end
50
+
51
+ role :single, "1.1.1.1"
52
+
53
+ namespace :uhljenkins do
54
+
55
+ desc "setup remote and locate uhljenkins dir"
56
+ task :setup do
57
+ uhljenkins.setup_remote
58
+ uhljenkins.setup_local
59
+ end
60
+
61
+ desc "setup remote uhljenkins dir"
62
+ task :setup_remote do
63
+ run clone_repository_command()
64
+ end
65
+
66
+ desc "setup locate uhljenkins dir"
67
+ task :setup_local do
68
+ system clone_repository_local_command()
69
+ end
70
+
71
+ desc "just pull current build version, doesn't add tag."
72
+ task :pull do
73
+ uhljenkins.setup_local
74
+
75
+ system "cd #{local_gitrepo}; git checkout #{branch}; git fetch; git rebase origin/#{branch};"
76
+
77
+ unless war_name.empty?
78
+ puts "name=#{war_name}, war=#{war_path}"
79
+ system update_repository_local_command(war_name, war_path)
80
+ else
81
+ if war_config.nil? or war_config.size == 0
82
+ raise 'NO war_config'
83
+ end
84
+ war_config.each do |config|
85
+ puts "name=#{config[:name]}, war=#{config[:war]}"
86
+ system update_repository_local_command(config[:name], config[:war])
87
+ end
88
+ end
89
+
90
+ build_msg = war_name.empty? ? "all" : war_name
91
+ system "cd #{local_gitrepo}; git add .; git commit -m 'build for #{build_msg}'"
92
+
93
+ # push tags and latest code
94
+ system "cd #{local_gitrepo}; git push origin #{branch}"
95
+ if $? != 0
96
+ raise "git push failed"
97
+ end
98
+
99
+ end
100
+
101
+ desc "tag build version. use -s tag=xxx to set tag's name"
102
+ task :tag do
103
+ uhljenkins.setup_local
104
+ system "cd #{local_gitrepo}; git checkout #{branch}; git fetch; git rebase origin/#{branch};"
105
+
106
+ tag_name = configuration[:tag] || configuration[:build_version]
107
+ raise "NO tag. pls use -s tag=xxx set tag_name" if tag_name.nil?
108
+
109
+ system "cd #{local_gitrepo}; git tag #{tag_name};"
110
+
111
+ system "cd #{local_gitrepo}; git push origin #{branch} --tags"
112
+ if $? != 0
113
+ raise "git push --tags failed"
114
+ end
115
+ end
116
+
117
+ desc "deploy. use -s tag=xxx to set tag's name, if NOT set tag, pull the repository's last version."
118
+ task :deploy do
119
+ tag_name = configuration[:tag] || configuration[:build_version]
120
+ if tag_name.nil?
121
+ # raise "NO tag. pls use -s tag=xxx set tag_name"
122
+ run update_repository_remote_command(tag_name)
123
+ else
124
+ run pull_repository_remote_command(branch)
125
+ end
126
+ end
127
+
128
+ desc "register servers and deploy_dir on CMDB"
129
+ task :register_servers do
130
+ version = build_version
131
+ puts "version=#{version}, servers=#{servers}, deploy_dir=#{deploy_to}"
132
+ CmdbService.start_deploy_with_server(cse_base, deploy_unit_code, deploy_stage, version.strip, servers, deploy_to)
133
+ end
134
+
135
+ desc "send deploy success info to CMDB"
136
+ task :deploy_succ do
137
+ CmdbService.complete_deploy(cse_base, deploy_unit_code, deploy_stage, true, "部署成功")
138
+ end
139
+
140
+ desc "send deploy failure info to CMDB"
141
+ task :deploy_fail do
142
+ CmdbService.complete_deploy(cse_base, deploy_unit_code, deploy_stage, false, "capistrano部署失败,撤销发布。")
143
+ end
144
+
145
+
146
+ def self.clone_repository_local_command
147
+ [
148
+ "if [ ! -e #{local_git_dir} ]",
149
+ "then mkdir -p #{local_git_dir}",
150
+ "cd #{local_git_dir}",
151
+ "git clone #{repository} #{local_gitrepo}",
152
+ "fi"
153
+ ].join("; ")
154
+ end
155
+
156
+
157
+ def self.update_repository_local_command(name, war)
158
+ unless war.start_with?('/')
159
+ war_path = "#{local_base_dir}/#{war}"
160
+ else
161
+ war_path = war
162
+ end
163
+ [
164
+ "cd #{local_gitrepo}",
165
+ "if [ -e #{local_gitrepo}/#{name} ]",
166
+ "then git rm -rf #{local_gitrepo}/#{name}",
167
+ "fi",
168
+ "mkdir -p #{local_gitrepo}/#{name}",
169
+ "cd #{local_gitrepo}/#{name}",
170
+ "jar -xf #{war_path}"
171
+ ].join("; ")
172
+ end
173
+
174
+ def self.clone_repository_command
175
+ [
176
+ "if [ ! -e #{deploy_to_gitrepo} ]",
177
+ "then sudo mkdir -p #{deploy_to}",
178
+ "sudo chown #{user} #{deploy_to}",
179
+ "cd #{deploy_to}",
180
+ "git clone #{repository} #{deploy_to_gitrepo}",
181
+ "fi"
182
+ ].join("; ")
183
+ end
184
+
185
+ def self.update_repository_remote_command(tag_name)
186
+ [
187
+ # git reset --hard;git fetch;git reset --merge #{tag_name}
188
+ "cd #{deploy_to_gitrepo}",
189
+ "git reset --hard",
190
+ "git fetch",
191
+ "git reset --merge #{tag_name}",
192
+ ].join("; ")
193
+ end
194
+
195
+ def self.pull_repository_remote_command(branch)
196
+ [
197
+ # git reset --hard;git fetch;git reset --merge #{tag_name}
198
+ "cd #{deploy_to_gitrepo}",
199
+ "git reset --hard",
200
+ "git fetch",
201
+ "git rebase origin/#{branch}",
202
+ ].join("; ")
203
+ end
204
+
205
+ end
206
+
207
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crazycode-cap-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &10897720 !ruby/object:Gem::Requirement
16
+ requirement: &6223680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10897720
24
+ version_requirements: *6223680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &10896680 !ruby/object:Gem::Requirement
27
+ requirement: &6221400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *10896680
35
+ version_requirements: *6221400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: addressable
38
- requirement: &10895420 !ruby/object:Gem::Requirement
38
+ requirement: &6217940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *10895420
46
+ version_requirements: *6217940
47
47
  description: Battle-tested capistrano recipes for debian, passenger, apache, hudson,
48
48
  delayed_job, juggernaut, rubygems, backgroundrb, rails and more
49
49
  email: crazycode@gmail.com
@@ -139,6 +139,7 @@ files:
139
139
  - lib/cap_recipes/tasks/tomcat/install.rb
140
140
  - lib/cap_recipes/tasks/tomcat/manage.rb
141
141
  - lib/cap_recipes/tasks/tomcat/war.rb
142
+ - lib/cap_recipes/tasks/uhljenkins.rb
142
143
  - lib/cap_recipes/tasks/utilities.rb
143
144
  - lib/cap_recipes/tasks/whenever.rb
144
145
  - lib/cap_recipes/tasks/whenever/hooks.rb