kstrano 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kstrano.rb +28 -28
- metadata +2 -2
data/lib/kstrano.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
set :jenkins_base_uri, ""
|
1
|
+
set :jenkins_base_uri, ""
|
2
2
|
set :jenkins_base_job_name, "Default"
|
3
3
|
set :jenkins_poll_timeout, 300
|
4
4
|
set :jenkins_poll_interval, 2
|
@@ -19,27 +19,27 @@ set :symfony_console, app_path + "/console"
|
|
19
19
|
require "#{File.dirname(__FILE__)}/helpers/git_helper.rb"
|
20
20
|
require "#{File.dirname(__FILE__)}/helpers/jenkins_helper.rb"
|
21
21
|
require "#{File.dirname(__FILE__)}/helpers/airbrake_helper.rb"
|
22
|
-
require "#{File.dirname(__FILE__)}/helpers/campfire_helper.rb"
|
23
|
-
require "#{File.dirname(__FILE__)}/helpers/kuma_helper.rb"
|
22
|
+
require "#{File.dirname(__FILE__)}/helpers/campfire_helper.rb"
|
23
|
+
require "#{File.dirname(__FILE__)}/helpers/kuma_helper.rb"
|
24
24
|
require 'rexml/document'
|
25
25
|
require 'etc'
|
26
26
|
|
27
27
|
namespace :kuma do
|
28
|
-
|
28
|
+
|
29
29
|
desc "Run fixcron for the current project"
|
30
30
|
task :fixcron do
|
31
31
|
sudo "sh -c 'if [ -f /opt/kDeploy/tools/fixcron.py ] ; then cd /opt/kDeploy/tools/; python fixcron.py #{application}; fi'"
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
desc "Run fixperms for the current project"
|
35
35
|
task :fixperms do
|
36
36
|
sudo "sh -c 'if [ -f /opt/kDeploy/tools/fixperms.py ] ; then cd /opt/kDeploy/tools/; python fixperms.py #{application}; fi'"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
end
|
40
40
|
|
41
41
|
namespace :airbrake do
|
42
|
-
|
42
|
+
|
43
43
|
desc "Register a deploy with airbrake.io"
|
44
44
|
task :notify do
|
45
45
|
if !airbrake_api_key.nil?
|
@@ -50,11 +50,11 @@ namespace :airbrake do
|
|
50
50
|
Kumastrano.say "Failed notifying airbrake of the new deploy" unless success
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
55
|
|
56
56
|
namespace :campfire do
|
57
|
-
|
57
|
+
|
58
58
|
desc "Say something on campfire"
|
59
59
|
task:say do
|
60
60
|
if !campfire_room.nil?
|
@@ -63,11 +63,11 @@ namespace :campfire do
|
|
63
63
|
exit
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
end
|
68
68
|
|
69
69
|
namespace :jenkins do
|
70
|
-
|
70
|
+
|
71
71
|
desc "create a job for the current branch and application on Jenkins"
|
72
72
|
task:create_job do
|
73
73
|
## 1. locate the job in jenkins
|
@@ -103,20 +103,20 @@ namespace :jenkins do
|
|
103
103
|
else
|
104
104
|
Kumastrano.say "there was already a job available on Jenkins for branch #{current_branch} on #{application}"
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
current_job_url
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
desc "Try to build the current branch on Jenkins"
|
111
111
|
task:build do
|
112
112
|
current_job_url = jenkins::create_job
|
113
113
|
current_branch = Kumastrano::GitHelper.branch_name
|
114
|
-
|
114
|
+
|
115
115
|
if !current_job_url.nil?
|
116
116
|
job_name = Kumastrano::JenkinsHelper.make_safe_job_name(application, current_branch)
|
117
117
|
prev_build = Kumastrano::JenkinsHelper.last_build_number current_job_url
|
118
118
|
Kumastrano.say "start building build ##{(prev_build + 1)} on job #{job_name}, this can take a while"
|
119
|
-
|
119
|
+
|
120
120
|
result, last_build_info = Kumastrano::JenkinsHelper.build_and_wait current_job_url, jenkins_poll_timeout, jenkins_poll_interval
|
121
121
|
|
122
122
|
message = ""
|
@@ -127,17 +127,17 @@ namespace :jenkins do
|
|
127
127
|
Kumastrano.say "the build failed"
|
128
128
|
message = "failed"
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
Kumastrano::CampfireHelper.speak campfire_account, campfire_token, campfire_room, "#{Etc.getlogin.capitalize} just builded a new version of #{current_branch} on #{application} and it #{message}. You can view the results here #{current_job_url}/lastBuild."
|
132
132
|
else
|
133
133
|
Kumastrano.say "no job found for #{job_name}, cannot build"
|
134
134
|
end
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
end
|
138
138
|
|
139
139
|
namespace :deploy do
|
140
|
-
|
140
|
+
|
141
141
|
task :symlink, :except => { :no_release => true } do
|
142
142
|
on_rollback do
|
143
143
|
if previous_release
|
@@ -149,7 +149,7 @@ namespace :deploy do
|
|
149
149
|
|
150
150
|
try_sudo "ln -sfT #{latest_release} #{current_path}"
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
end
|
154
154
|
|
155
155
|
## Capistrano callbacks ##
|
@@ -163,13 +163,13 @@ before :deploy do
|
|
163
163
|
can_deploy = false
|
164
164
|
current_branch = Kumastrano::GitHelper.branch_name
|
165
165
|
current_hash = Kumastrano::GitHelper.commit_hash
|
166
|
-
|
166
|
+
|
167
167
|
if Kumastrano::JenkinsHelper.available? jenkins_base_uri
|
168
168
|
## Allways fetch the latest information from git
|
169
169
|
Kumastrano::GitHelper.fetch
|
170
|
-
|
170
|
+
|
171
171
|
job_name = Kumastrano::JenkinsHelper.make_safe_job_name(application, current_branch)
|
172
|
-
current_job_url = Kumastrano::JenkinsHelper.job_url_for_name(jenkins_base_uri, job_name)
|
172
|
+
current_job_url = Kumastrano::JenkinsHelper.job_url_for_name(jenkins_base_uri, job_name)
|
173
173
|
|
174
174
|
if current_job_url.nil?
|
175
175
|
## No job exists for the current branch, we'll create a job.
|
@@ -183,7 +183,7 @@ before :deploy do
|
|
183
183
|
last_build_info = Kumastrano::JenkinsHelper.build_info current_job_url
|
184
184
|
result = last_build_info['result'] ## SUCCESS or FAILURE
|
185
185
|
build_hash = Kumastrano::JenkinsHelper.fetch_build_hash_from_build_info(last_build_info, current_branch)
|
186
|
-
|
186
|
+
|
187
187
|
if !build_hash.nil?
|
188
188
|
if build_hash == current_hash
|
189
189
|
if "SUCCESS" == result
|
@@ -206,7 +206,7 @@ before :deploy do
|
|
206
206
|
else
|
207
207
|
merge_base = Kumastrano::GitHelper.merge_base(build_hash, current_hash)
|
208
208
|
if merge_base == build_hash
|
209
|
-
## The build commit is an ancestor of HEAD
|
209
|
+
## The build commit is an ancestor of HEAD
|
210
210
|
if Kumastrano.ask "the last build for the branch #{current_branch} is from an older commit do you want to build again? (jenkins=#{build_hash}, local=#{current_hash})", 'y'
|
211
211
|
prev_build = Kumastrano::JenkinsHelper.last_build_number current_job_url
|
212
212
|
Kumastrano.say "start building build ##{(prev_build + 1)} on job #{job_name}, this can take a while"
|
@@ -252,7 +252,7 @@ before :deploy do
|
|
252
252
|
end
|
253
253
|
end
|
254
254
|
end
|
255
|
-
|
255
|
+
|
256
256
|
if !can_deploy
|
257
257
|
if Kumastrano.ask "no valid build found for #{current_hash} on branch #{current_branch}, do you still want to deploy?"
|
258
258
|
Kumastrano::CampfireHelper.speak campfire_account, campfire_token, campfire_room, "#{Etc.getlogin.capitalize} ignored the fact there was something wrong with #{current_branch} on #{application} and still went on with deploying it!!"
|
@@ -302,11 +302,11 @@ end
|
|
302
302
|
after :deploy do
|
303
303
|
current_branch = Kumastrano::GitHelper.branch_name
|
304
304
|
Kumastrano::CampfireHelper.speak campfire_account, campfire_token, campfire_room, "#{Etc.getlogin.capitalize} successfuly deployed #{current_branch} for #{application}"
|
305
|
-
|
306
|
-
deploy::cleanup ## cleanup old releases
|
307
|
-
kuma::fixcron
|
305
|
+
sudo "/etc/init.d/php5-fpm reload"
|
308
306
|
serverproject = domain.split('.')[0]
|
309
307
|
sudo "sh -c 'curl https://raw.github.com/gist/2868838/ > /home/projects/#{serverproject}/site/apcclear.php'"
|
310
308
|
sudo "chmod 777 /home/projects/#{serverproject}/site/apcclear.php"
|
311
309
|
sudo "curl http://#{domain}/apcclear.php"
|
310
|
+
kuma::fixcron
|
311
|
+
deploy::cleanup ## cleanup old releases
|
312
312
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kstrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|