quiverstaskrunner 0.1.40704
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/quiverstaskrunner/azuresetup.rb +266 -0
- data/lib/quiverstaskrunner/helpers/envhelper.rb +18 -0
- data/lib/quiverstaskrunner/helpers/rakehelper.rb +43 -0
- data/lib/quiverstaskrunner/helpers/settingshelper.rb +16 -0
- data/lib/quiverstaskrunner/helpers/xmlhelper.rb +57 -0
- data/lib/quiverstaskrunner/replacetokens.rb +22 -0
- data/lib/quiverstaskrunner/restorepoints.rb +42 -0
- data/lib/quiverstaskrunner/version.rb +1 -0
- data/lib/quiverstaskrunner.rb +8 -0
- data/quiverstaskrunner.gemspec +41 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b209cdea61e88d3f5521ed36fd48f92a24a0ae8
|
4
|
+
data.tar.gz: 8bd5e19d3b8e1e64d66f3fe5573cedebc2c786b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b973d62b2d2304e6b04cd528251eac72e2d48d77f1ab85e899b3a180f1d5a1b8cfc38af0e7165a57d3d48766ff1548b602c28f2938dec2a36abe763e2b9d59ea
|
7
|
+
data.tar.gz: 9deb32c00ccfab9afaa2eecfa2be98be100ec3e6e8985dcb4ede51ff83e6a7782134bcbe28166a7c24b53ca747edb1cc8af3cfcb06677da86b3bf430d6df6b53
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in quivers-taskrunner.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# Fork from original project. This is because the original project contains a series of bugs
|
7
|
+
# as well as a few missing features
|
8
|
+
gem "azure", :git => "https://github.com/nicolasdao/azure-sdk-for-ruby.git"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ndao
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# QuiversTaskrunner
|
2
|
+
|
3
|
+
Set of modules which defines common tasks to build, deploy C# projects. It also allows to query details about the project's hosting environment in Azure
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'quiverstaskrunner'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install quiverstaskrunner
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Typically used inside a Rakefile
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://daonicolas@bitbucket.org/quivers/quivers.taskrunner/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'azure'
|
3
|
+
require 'colorize'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'SecureRandom'
|
6
|
+
require "quiverstaskrunner/helpers/envhelper"
|
7
|
+
require "quiverstaskrunner/helpers/xmlhelper"
|
8
|
+
require "quiverstaskrunner/helpers/settingshelper"
|
9
|
+
|
10
|
+
include QuiversTaskrunner
|
11
|
+
|
12
|
+
module QuiversTaskrunner
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def is_update_message_on
|
16
|
+
update_message_on = true
|
17
|
+
begin
|
18
|
+
update_message_on = (EnvHelper.get_env("update_message_on") == "true")
|
19
|
+
rescue
|
20
|
+
update_message_on = true
|
21
|
+
end
|
22
|
+
return update_message_on
|
23
|
+
end
|
24
|
+
|
25
|
+
def scale_host(cloud_service_name, service_configuration, service_definition, env=nil)
|
26
|
+
env = env || EnvHelper.get_env("env")
|
27
|
+
|
28
|
+
# 1. Get cloud service's details
|
29
|
+
cloud_services = SettingsHelper.get_settings(File.join(Dir.pwd, "secrets/cloud_services.yml"), env)
|
30
|
+
cloud_service_details = cloud_services[cloud_service_name]
|
31
|
+
raise StandardError, "No details were found for cloud service #{cloud_service_name}" unless cloud_service_details
|
32
|
+
vmsize = cloud_service_details["vmsize"]
|
33
|
+
vmnbr = cloud_service_details["vmnbr"]
|
34
|
+
|
35
|
+
# 2. Load xml files
|
36
|
+
service_config_xml = XmlHelper.get_xml(service_configuration)
|
37
|
+
service_def_xml = XmlHelper.get_xml(service_definition)
|
38
|
+
|
39
|
+
service_config_xml.update_node_at_css_selector('ServiceConfiguration Role Instances',
|
40
|
+
{ :count => vmnbr })
|
41
|
+
service_def_xml.update_node_at_css_selector('ServiceDefinition WebRole',
|
42
|
+
{ :vmsize => vmsize })
|
43
|
+
|
44
|
+
XmlHelper.overide_xml(service_configuration, service_config_xml)
|
45
|
+
XmlHelper.overide_xml(service_definition, service_def_xml)
|
46
|
+
end
|
47
|
+
|
48
|
+
def configure_subscription(env=nil)
|
49
|
+
|
50
|
+
# 1. Load environment variables
|
51
|
+
env = env || EnvHelper.get_env("env")
|
52
|
+
pfx_path = EnvHelper.get_env("azure_management_certificate")
|
53
|
+
subscription_id = EnvHelper.get_env("azure_subscription_id")
|
54
|
+
|
55
|
+
# 2. Load secrets
|
56
|
+
storage = SettingsHelper.get_settings(File.join(Dir.pwd, "secrets/storage.yml"), env)
|
57
|
+
storage_details = storage["blob"]
|
58
|
+
raise StandardError, "No details were found for blob storage for the #{env} environment" unless storage_details
|
59
|
+
|
60
|
+
Azure.configure do |config|
|
61
|
+
config.storage_account_name = storage_details["name"]
|
62
|
+
config.storage_access_key = storage_details["key"]
|
63
|
+
config.management_certificate = pfx_path
|
64
|
+
config.subscription_id = subscription_id
|
65
|
+
config.management_endpoint = "https://management.core.windows.net"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def upload_cspkg_to_blob(pkg_name, pkg_dir, options={})
|
70
|
+
# 1. Configure the blob object, and load the package inside it
|
71
|
+
timeout = options[:timeout] || 20*60 # 20 minutes
|
72
|
+
blob_srv = Azure::Blob::BlobService.new
|
73
|
+
blob_name = Time.now.utc.strftime("%Y%m%d_%H%M%S_#{pkg_name}")
|
74
|
+
blob_container = "mydeployments"
|
75
|
+
blob_content = nil
|
76
|
+
File.open(File.join(pkg_dir, pkg_name), "rb") do |f|
|
77
|
+
blob_content = f.read
|
78
|
+
end
|
79
|
+
blob_options = {
|
80
|
+
:content_type => "application/octet-stream",
|
81
|
+
:timeout => timeout
|
82
|
+
}
|
83
|
+
|
84
|
+
# 2. Upload the blob object to the blob storage
|
85
|
+
start_time = Time.now
|
86
|
+
uploaded_package_name = nil
|
87
|
+
no_error = true
|
88
|
+
begin
|
89
|
+
puts "Start uploading package #{blob_name} to blob storage"
|
90
|
+
new_blob = blob_srv.create_block_blob(blob_container, blob_name, blob_content, blob_options)
|
91
|
+
uploaded_package_name = blob_name
|
92
|
+
rescue Exception => ex
|
93
|
+
no_error = false
|
94
|
+
raise ex
|
95
|
+
ensure
|
96
|
+
ellappsed_min = (Time.now - start_time)/60.to_f
|
97
|
+
puts "Upload of package #{blob_name} to blob storage succeeded in #{ellappsed_min} minutes".colorize(:green)
|
98
|
+
end
|
99
|
+
|
100
|
+
return [uploaded_package_name, no_error]
|
101
|
+
end
|
102
|
+
|
103
|
+
def deploy_blob_pkg_to_staging(cloud_service_name, blob_pkg_name, pkg_dir, labels, options={})
|
104
|
+
# 1. Load cloud service's details
|
105
|
+
env = options[:env] || EnvHelper.get_env("env")
|
106
|
+
timeout = options[:timeout] || 20*60 # 20 minutes
|
107
|
+
update_message_on = is_update_message_on
|
108
|
+
cloud_services = SettingsHelper.get_settings(File.join(Dir.pwd, "secrets/cloud_services.yml"), env)
|
109
|
+
cloud_service_details = cloud_services[cloud_service_name]
|
110
|
+
raise StandardError, "No details were found for cloud service #{cloud_service_name}" unless cloud_service_details
|
111
|
+
# 2. Load storage details
|
112
|
+
storage = SettingsHelper.get_settings(File.join(Dir.pwd, "secrets/storage.yml"), env)
|
113
|
+
storage_details = storage["blob"]
|
114
|
+
raise StandardError, "No details were found for blob storage for the #{env} environment" unless storage_details
|
115
|
+
|
116
|
+
# 3. Configure the deployment details
|
117
|
+
deployment_name = SecureRandom.uuid
|
118
|
+
cloud_srv_name = cloud_service_details["name"]
|
119
|
+
package_url = ENV["package_url"]
|
120
|
+
if package_url.nil?
|
121
|
+
if blob_pkg_name.nil? || blob_pkg_name.empty?
|
122
|
+
raise ArgumentError, "Missing argument. No 'blob_pkg_name' or 'package_url' defined."
|
123
|
+
else
|
124
|
+
package_url = "https://#{storage_details['name']}.blob.core.windows.net/mydeployments/#{blob_pkg_name}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
# This way of getting the service configuration file may seem weird(indeed, why not
|
128
|
+
# using the standard File.open method?), but for some reasons that I don't understand,
|
129
|
+
# File.open will result in a 'Bad Request : The specified configuration settings for Configuration
|
130
|
+
# are invalid.' error
|
131
|
+
service_configuration = XmlHelper.get_xml(File.join(pkg_dir, "ServiceConfiguration.#{env.capitalize}.cscfg")).to_xml
|
132
|
+
|
133
|
+
deployment_options = {
|
134
|
+
:slot => "staging",
|
135
|
+
:label => labels,
|
136
|
+
:start_deployment => true,
|
137
|
+
:fire_and_forget => true,
|
138
|
+
:upgrade_if_exists => true
|
139
|
+
}
|
140
|
+
|
141
|
+
# 4. Asynchronously deploy package to staging
|
142
|
+
start_time = Time.now
|
143
|
+
init_msg = nil
|
144
|
+
cloud_srv_mgmt = Azure::CloudServiceManagementService.new
|
145
|
+
no_error = true
|
146
|
+
begin
|
147
|
+
puts "Start deploying package from blob storage #{package_url} to cloud service"
|
148
|
+
resp = cloud_srv_mgmt.create_deployment(deployment_name, cloud_srv_name, package_url, service_configuration, deployment_options)
|
149
|
+
init_msg = "successfully initiated"
|
150
|
+
rescue Exception => ex
|
151
|
+
no_error = false
|
152
|
+
init_msg = "failed"
|
153
|
+
raise ex
|
154
|
+
ensure
|
155
|
+
ellapsed_time_min = (Time.now - start_time)/60.to_f
|
156
|
+
puts "Deployment #{deployment_name} #{init_msg} after #{ellapsed_time_min} minutes"
|
157
|
+
end
|
158
|
+
|
159
|
+
# 5. Wait until the deployment is done
|
160
|
+
deployment_pending = true
|
161
|
+
waiting_start_time = Time.now
|
162
|
+
timeout = timeout
|
163
|
+
counter = 1
|
164
|
+
waiting_symbols = ["=", "+"]
|
165
|
+
deployment_id = nil
|
166
|
+
while deployment_pending do
|
167
|
+
waiting_characters = Array.new(counter, waiting_symbols[0]).join
|
168
|
+
if update_message_on
|
169
|
+
print "\r"
|
170
|
+
print "Waiting for confirmation of running instances #{waiting_characters}"
|
171
|
+
end
|
172
|
+
deployment = cloud_srv_mgmt.get_deployment(cloud_srv_name, {:slot => "staging" })
|
173
|
+
raise StandardError, "#{timeout} seconds timeout. Client unable to confirm operation success" if (Time.now - waiting_start_time) > timeout
|
174
|
+
deployment_pending = !deployment.all_vms_running? || deployment.is_transitioning?
|
175
|
+
deployment_id = deployment.private_id
|
176
|
+
counter+=1
|
177
|
+
if counter > 40
|
178
|
+
counter = 1
|
179
|
+
waiting_symbols.reverse!
|
180
|
+
end
|
181
|
+
end
|
182
|
+
print "\n"
|
183
|
+
ellapsed_time_min = (Time.now - start_time)/60.to_f
|
184
|
+
puts "Deployment #{deployment_name} with id #{deployment_id} running successfully. Deployment took #{ellapsed_time_min} minutes to complete".colorize(:green)
|
185
|
+
return no_error
|
186
|
+
end
|
187
|
+
|
188
|
+
def swap(cloud_service_name, options={})
|
189
|
+
|
190
|
+
# 1. Load cloud service's details
|
191
|
+
env = options[:env] || EnvHelper.get_env("env")
|
192
|
+
timeout = options[:timeout] || 20*60 # 20 minutes
|
193
|
+
update_message_on = is_update_message_on
|
194
|
+
cloud_services = SettingsHelper.get_settings(File.join(Dir.pwd, "secrets/cloud_services.yml"), env)
|
195
|
+
cloud_service_details = cloud_services[cloud_service_name]
|
196
|
+
cloud_srv_name = cloud_service_details["name"]
|
197
|
+
|
198
|
+
# 2. Asynchronously swap deployments
|
199
|
+
start_time = Time.now
|
200
|
+
init_msg = nil
|
201
|
+
cloud_srv_mgmt = Azure::CloudServiceManagementService.new
|
202
|
+
no_error = true
|
203
|
+
begin
|
204
|
+
puts "Start swapping deployments for cloud service '#{cloud_srv_name}'"
|
205
|
+
resp = cloud_srv_mgmt.swap_deployment(cloud_srv_name, {:fire_and_forget => true})
|
206
|
+
init_msg = "successfully initiated"
|
207
|
+
rescue Exception => ex
|
208
|
+
no_error = false
|
209
|
+
init_msg = "failed"
|
210
|
+
raise ex
|
211
|
+
ensure
|
212
|
+
ellapsed_time_min = (Time.now - start_time)/60.to_f
|
213
|
+
puts "Swapping deployments for cloud service '#{cloud_srv_name}' #{init_msg} after #{ellapsed_time_min} minutes"
|
214
|
+
end
|
215
|
+
|
216
|
+
# 3. Wait until the swapping is done
|
217
|
+
deployment_pending = true
|
218
|
+
waiting_start_time = Time.now
|
219
|
+
counter = 1
|
220
|
+
waiting_symbols = ["=", "+"]
|
221
|
+
while deployment_pending do
|
222
|
+
waiting_characters = Array.new(counter, waiting_symbols[0]).join
|
223
|
+
if update_message_on
|
224
|
+
print "\r"
|
225
|
+
print "Waiting for confirmation of running instances #{waiting_characters}"
|
226
|
+
end
|
227
|
+
deployment = cloud_srv_mgmt.get_deployment(cloud_srv_name, {:slot => "production" })
|
228
|
+
raise StandardError, "#{timeout} seconds timeout. Client unable to confirm operation success" if (Time.now - waiting_start_time) > timeout
|
229
|
+
deployment_pending = !deployment.all_vms_running? || deployment.is_transitioning?
|
230
|
+
counter+=1
|
231
|
+
if counter > 40
|
232
|
+
counter = 1
|
233
|
+
waiting_symbols.reverse!
|
234
|
+
end
|
235
|
+
end
|
236
|
+
print "\n"
|
237
|
+
ellapsed_time_min = (Time.now - start_time)/60.to_f
|
238
|
+
puts "Swapping deployments for cloud service '#{cloud_srv_name}' done. Swapping took #{ellapsed_time_min} minutes to complete".colorize(:green)
|
239
|
+
return no_error
|
240
|
+
end
|
241
|
+
|
242
|
+
def delete_staging(cloud_service_name, env=nil)
|
243
|
+
|
244
|
+
# 1. Load cloud service's details
|
245
|
+
env = env || EnvHelper.get_env("env")
|
246
|
+
cloud_services = SettingsHelper.get_settings(File.join(Dir.pwd, "secrets/cloud_services.yml"), env)
|
247
|
+
cloud_service_details = cloud_services[cloud_service_name]
|
248
|
+
raise StandardError, "No details were found for cloud service #{cloud_service_name}" unless cloud_service_details
|
249
|
+
cloud_srv_name = cloud_service_details["name"]
|
250
|
+
|
251
|
+
# 2. Check if there is a Staging deployment for that Cloud Service
|
252
|
+
cloud_srv_mgmt = Azure::CloudServiceManagementService.new
|
253
|
+
deployment = cloud_srv_mgmt.get_deployment(cloud_srv_name, {:slot => "staging", :no_exit_on_failure => true})
|
254
|
+
|
255
|
+
# 3. Delete the Staging deployment if it exists
|
256
|
+
start_time = Time.now
|
257
|
+
if deployment.exists?
|
258
|
+
puts "Deleting staging deployment with id #{deployment.private_id} for cloud service #{cloud_srv_name}"
|
259
|
+
cloud_srv_mgmt.delete_cloud_service_deployment(cloud_srv_name, "staging")
|
260
|
+
ellapsed_time_min = (Time.now - start_time)/60.to_f
|
261
|
+
puts "Deleting staging deployment #{deployment.private_id} for cloud service #{cloud_srv_name} done. Operation took #{ellapsed_time_min} minutes to complete".colorize(:green)
|
262
|
+
else
|
263
|
+
puts "No staging deployment detected for cloud service '#{cloud_srv_name}'".colorize(:magenta)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module QuiversTaskrunner
|
3
|
+
module EnvHelper
|
4
|
+
def self.get_env(name)
|
5
|
+
begin
|
6
|
+
value = ENV[name]
|
7
|
+
if value.nil?
|
8
|
+
value = `#{name.upcase}`
|
9
|
+
end
|
10
|
+
return value
|
11
|
+
rescue Exception => ex
|
12
|
+
raise ArgumentError, "Environment variable '#{name}' not defined. Please pass\n" +
|
13
|
+
"a '#{name}' environment variable to your task, or create a '#{name}' \n" +
|
14
|
+
"environment variable on your machine"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
module QuiversTaskrunner
|
5
|
+
module RakeHelper
|
6
|
+
|
7
|
+
def self.safe_invoke(tasks, ensure_tasks={}, options={})
|
8
|
+
|
9
|
+
start_time = Time.now
|
10
|
+
task_group_name = options[:task_group_name] || "safe task invoke"
|
11
|
+
if options[:display_message] && !options[:global].nil? && options[:global].respond_to?("no_error")
|
12
|
+
puts "Start #{task_group_name}...".colorize(:cyan)
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
if tasks.is_a?(Array)
|
17
|
+
tasks.each { |t| Rake::Task[t].invoke }
|
18
|
+
else
|
19
|
+
Rake::Task[tasks].invoke
|
20
|
+
end
|
21
|
+
rescue Exception => ex
|
22
|
+
raise ex
|
23
|
+
ensure
|
24
|
+
if ensure_tasks.is_a?(Array) && ensure_tasks.any?
|
25
|
+
RakeHelper.safe_invoke(ensure_tasks[0], ensure_tasks.shift)
|
26
|
+
else
|
27
|
+
Rake::Task[ensure_tasks].invoke unless ensure_tasks.empty?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if options[:display_message] && !options[:global].nil? && options[:global].respond_to?("no_error")
|
32
|
+
ellapsed_time_min = (Time.now - start_time)/60.to_f
|
33
|
+
build_status = "successfully completed in"
|
34
|
+
color_theme = :green
|
35
|
+
unless options[:global].no_error
|
36
|
+
build_status = "failed after"
|
37
|
+
color_theme = :red
|
38
|
+
end
|
39
|
+
puts "#{task_group_name.capitalize} #{build_status} #{ellapsed_time_min} minutes".colorize(color_theme)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "erb"
|
3
|
+
|
4
|
+
module QuiversTaskrunner
|
5
|
+
module SettingsHelper
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def get_settings(filepath, env={})
|
9
|
+
environment = env.is_a?(Hash) ? "defaults" : env
|
10
|
+
file_contents = open(filepath).read
|
11
|
+
YAML.load(ERB.new(file_contents).result).to_hash
|
12
|
+
all_settings = YAML.load(ERB.new(file_contents).result).to_hash
|
13
|
+
all_settings[environment]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Document
|
6
|
+
def add_node_under_css_selector(css_selector, node)
|
7
|
+
nodes = node.is_a?(Array) ? node : [node]
|
8
|
+
self.css(css_selector).each { |n| nodes.each { |x| n.add_child(x) } }
|
9
|
+
end
|
10
|
+
|
11
|
+
def update_node_at_css_selector(css_selector, attributes={}, content={})
|
12
|
+
attribute_exists = !attributes.nil? && attributes.any?
|
13
|
+
content_exists = !content.nil? && content.any?
|
14
|
+
self.css(css_selector).each { |n|
|
15
|
+
if attribute_exists
|
16
|
+
attributes.each { |k,v| n[k.to_s] = v}
|
17
|
+
end
|
18
|
+
if content_exists
|
19
|
+
n.content = content
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module QuiversTaskrunner
|
28
|
+
module XmlHelper
|
29
|
+
|
30
|
+
def self.get_xml(filepath)
|
31
|
+
xml = nil
|
32
|
+
File.open(filepath, "rb") do |f|
|
33
|
+
xml = Nokogiri::XML(f)
|
34
|
+
end
|
35
|
+
return xml
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.overide_xml(filepath, xml)
|
39
|
+
File.open(filepath, "w") do |f|
|
40
|
+
f.write(xml.to_xml)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.create_xmlnode(name, original_document, attributes={}, content={})
|
45
|
+
node = Nokogiri::XML::Node.new name, original_document
|
46
|
+
unless attributes.nil? || attributes.empty?
|
47
|
+
attributes.each { |k,v|
|
48
|
+
node[k.to_s] = v
|
49
|
+
}
|
50
|
+
end
|
51
|
+
unless content.nil? || content.empty?
|
52
|
+
node.content = content
|
53
|
+
end
|
54
|
+
return node
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module QuiversTaskrunner
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def replace_tokens(files_with_missing_tokens, tokens)
|
5
|
+
files = files_with_missing_tokens.is_a?(Array) ? files_with_missing_tokens : [files_with_missing_tokens]
|
6
|
+
raise ArgumentError, "'tokens' must be a Hash" unless tokens.is_a?(Hash)
|
7
|
+
|
8
|
+
files.each { |f_path|
|
9
|
+
content = nil
|
10
|
+
File.open(f_path, "rb") do |f|
|
11
|
+
content = f.read
|
12
|
+
tokens.each { |k,v|
|
13
|
+
content = content.gsub("{{#{k}}}", v)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
File.open(f_path, "w") do |f|
|
18
|
+
f.write(content)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module QuiversTaskrunner
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def create_azure_files_restore_points(files_to_backup)
|
8
|
+
|
9
|
+
# convert single file into an array
|
10
|
+
files = files_to_backup.is_a?(Array) ? files_to_backup : (files_to_backup.nil? ? [] : [files_to_backup])
|
11
|
+
|
12
|
+
files.each do |f|
|
13
|
+
f_ext = File.extname(f)
|
14
|
+
f_backup_ext = ".backup#{f_ext}"
|
15
|
+
f_backup = f.gsub(f_ext, f_backup_ext)
|
16
|
+
# 1. Delete previous backup files if there are still present
|
17
|
+
FileUtils.rm_f(f_backup) if FileTest.exists? f_backup
|
18
|
+
# 2. Create backup files
|
19
|
+
FileUtils.cp f, f_backup
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def restore_and_clean_files(files_to_restore)
|
24
|
+
|
25
|
+
# convert single file into an array
|
26
|
+
files = files_to_restore.is_a?(Array) ? files_to_restore : (files_to_restore.nil? ? [] : [files_to_restore])
|
27
|
+
|
28
|
+
files.each do |f|
|
29
|
+
f_ext = File.extname(f)
|
30
|
+
f_backup_ext = ".backup#{f_ext}"
|
31
|
+
f_backup = f.gsub(f_ext, f_backup_ext)
|
32
|
+
# 1. Make sure there are restore files available
|
33
|
+
raise StandardError, "Missing restore file #{f_backup}" unless FileTest.exists? f_backup
|
34
|
+
# 2. Delete the modified files
|
35
|
+
FileUtils.rm_f(f)
|
36
|
+
# 3. Restore modified files
|
37
|
+
FileUtils.cp f_backup, f
|
38
|
+
# 4. Delete backup files
|
39
|
+
FileUtils.rm_f(f_backup)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module QuiversTaskrunner
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "quiverstaskrunner/version"
|
2
|
+
require "quiverstaskrunner/azuresetup"
|
3
|
+
require "quiverstaskrunner/replacetokens"
|
4
|
+
require "quiverstaskrunner/restorepoints"
|
5
|
+
require "quiverstaskrunner/helpers/envhelper"
|
6
|
+
require "quiverstaskrunner/helpers/rakehelper"
|
7
|
+
require "quiverstaskrunner/helpers/settingshelper"
|
8
|
+
require "quiverstaskrunner/helpers/xmlhelper"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
version = "0.1.%s" % ((Time.now.utc - Time.utc(2014, 7, 3))/60).round
|
6
|
+
version_file_path = File.join(lib, "quiverstaskrunner", "version.rb")
|
7
|
+
updated_content = nil
|
8
|
+
|
9
|
+
# update content
|
10
|
+
File.open(version_file_path, "rb") do |f|
|
11
|
+
content = f.read
|
12
|
+
updated_content = content.gsub(/(?<=").*?(?=")/, "%s" % version)
|
13
|
+
end
|
14
|
+
|
15
|
+
# overwrite version.rb with new content
|
16
|
+
File.open(version_file_path, "w") do |f|
|
17
|
+
f.write(updated_content)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
Gem::Specification.new do |spec|
|
22
|
+
spec.name = "quiverstaskrunner"
|
23
|
+
spec.version = version
|
24
|
+
spec.authors = ["ndao"]
|
25
|
+
spec.email = ["nicolas@quivers.com"]
|
26
|
+
spec.summary = %q{Set of modules which defines common tasks to build, deploy C# projects.}
|
27
|
+
spec.description = %q{Set of modules which defines common tasks to build, deploy C# projects. It also allows to query details about the project's hosting environment in Azure}
|
28
|
+
spec.homepage = ""
|
29
|
+
spec.license = "MIT"
|
30
|
+
|
31
|
+
spec.files = `git ls-files -z`.split("\x0")
|
32
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
33
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
37
|
+
spec.add_development_dependency "rake"
|
38
|
+
spec.add_runtime_dependency "nokogiri", "~> 1.6"
|
39
|
+
spec.add_runtime_dependency "azure", "~> 0.6"
|
40
|
+
spec.add_runtime_dependency "colorize", "~> 0.7"
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quiverstaskrunner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.40704
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ndao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: azure
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
description: Set of modules which defines common tasks to build, deploy C# projects.
|
84
|
+
It also allows to query details about the project's hosting environment in Azure
|
85
|
+
email:
|
86
|
+
- nicolas@quivers.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/quiverstaskrunner.rb
|
97
|
+
- lib/quiverstaskrunner/azuresetup.rb
|
98
|
+
- lib/quiverstaskrunner/helpers/envhelper.rb
|
99
|
+
- lib/quiverstaskrunner/helpers/rakehelper.rb
|
100
|
+
- lib/quiverstaskrunner/helpers/settingshelper.rb
|
101
|
+
- lib/quiverstaskrunner/helpers/xmlhelper.rb
|
102
|
+
- lib/quiverstaskrunner/replacetokens.rb
|
103
|
+
- lib/quiverstaskrunner/restorepoints.rb
|
104
|
+
- lib/quiverstaskrunner/version.rb
|
105
|
+
- quiverstaskrunner.gemspec
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.0.14
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Set of modules which defines common tasks to build, deploy C# projects.
|
130
|
+
test_files: []
|