osp-deploy 1.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/osp-rails-deploy.rb +74 -0
- data/lib/osp_deploy/logger_redirect.rb +27 -0
- data/lib/osp_deploy/rails_deployer.rb +350 -0
- data/lib/osp_deploy/thread_info_logger.rb +46 -0
- data/lib/osp_deploy/version.rb +3 -0
- data/lib/osp_deploy.rb +16 -0
- data/osp-deploy.gemspec +22 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71dac36de7734d9a2503d9c6f653c10710dc994d
|
4
|
+
data.tar.gz: 86f5c8919687fc71c1749fe6f35fa2a0b8e459df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a3c44baeaed4703041310c29a6fc0798e0054844150a6c5fa01af2ccac5f9bb89f5ee98607f8d38028da8da6a209db96f12e24daf86f662629776ff4b2aaab1
|
7
|
+
data.tar.gz: a56ecd8541989b95f8bb3c3d1186b3ec85f38a1063be627ef5e4a0c94b132b245bba3474adda71b1f241e3963a6bc3dc0c794e75e3596e508feaff8a4e644844
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bernd Ledig
|
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
|
+
# Osp::Deploy
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'osp-deploy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install osp-deploy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
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 new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: UTF-8
|
3
|
+
|
4
|
+
# Deployment-Tools to deploy the rails-app to a server
|
5
|
+
# with git-branch / -tag evaluation
|
6
|
+
# and generator for version-intializer
|
7
|
+
#
|
8
|
+
# Author: Bernd Ledig <bernd@ledig.info>
|
9
|
+
|
10
|
+
require 'getoptlong'
|
11
|
+
require 'fileutils'
|
12
|
+
require 'osp_deploy'
|
13
|
+
|
14
|
+
#############################
|
15
|
+
# Main-Part #
|
16
|
+
#############################
|
17
|
+
|
18
|
+
parser = GetoptLong.new(
|
19
|
+
['-h', '--help', GetoptLong::NO_ARGUMENT],
|
20
|
+
['-n', '--no-git-check', GetoptLong::NO_ARGUMENT],
|
21
|
+
['-v', '--verbose', GetoptLong::NO_ARGUMENT],
|
22
|
+
)
|
23
|
+
|
24
|
+
def print_usage err_code, msg=nil
|
25
|
+
puts ''
|
26
|
+
puts msg+"\n\n" if msg
|
27
|
+
puts <<EOT
|
28
|
+
Usage: #{File.basename(__FILE__)} <options> command
|
29
|
+
Options:
|
30
|
+
-n --no-git-check disable GIT commit check
|
31
|
+
-v --verbose verbose mode
|
32
|
+
Commands:
|
33
|
+
check-config
|
34
|
+
gen-version-initializer
|
35
|
+
make-last-changes
|
36
|
+
deploy (default) - Make all deployment steps
|
37
|
+
EOT
|
38
|
+
exit err_code
|
39
|
+
end
|
40
|
+
|
41
|
+
options = {}
|
42
|
+
begin
|
43
|
+
parser.each do |opt, arg|
|
44
|
+
case opt
|
45
|
+
when '-h'
|
46
|
+
print_usage 0
|
47
|
+
when '-n'
|
48
|
+
options[:no_git_check] = true
|
49
|
+
when '-v'
|
50
|
+
options[:verbose] = true
|
51
|
+
else
|
52
|
+
print_usage 2, "Option '#{opt}' not yet implemented!"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
rescue => e
|
56
|
+
print_usage 1
|
57
|
+
end
|
58
|
+
|
59
|
+
command = ARGV.first || 'deploy'
|
60
|
+
|
61
|
+
deployer = OspDeploy::RailsDeployer.new options
|
62
|
+
puts "Execute OspDeploy with command: #{command}"
|
63
|
+
case command
|
64
|
+
when 'check-config'
|
65
|
+
deployer.validate_config
|
66
|
+
when 'gen-version-initializer'
|
67
|
+
deployer.gen_version_initializer
|
68
|
+
when 'make-last-changes'
|
69
|
+
deployer.make_last_changelog
|
70
|
+
when 'deploy'
|
71
|
+
deployer.deploy_and_bundle
|
72
|
+
else
|
73
|
+
print_usage 2, "Unknown command: #{command}"
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class OspDeploy::LoggerRedirect
|
2
|
+
|
3
|
+
attr_accessor :logger, :severity
|
4
|
+
|
5
|
+
# Redirect $stdout to logger wit severity "DEBUG"
|
6
|
+
# and $stderr to logger wit severity "WARN"
|
7
|
+
def self.redirect_std_io logger
|
8
|
+
$stdout = self.new logger, Logger::DEBUG
|
9
|
+
$stderr = self.new logger, Logger::WARN
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.restore_std_io
|
13
|
+
$stdout = STDOUT
|
14
|
+
$stderr = STDERR
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize logger, severity
|
18
|
+
@logger = logger
|
19
|
+
@severity = severity
|
20
|
+
end
|
21
|
+
|
22
|
+
# Duke-Typing der relavanten IO-Methoden
|
23
|
+
def write s; @logger.add(@severity, s); end
|
24
|
+
def puts s; @logger.add(@severity, s); end
|
25
|
+
def print s; @logger.add(@severity, s); end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,350 @@
|
|
1
|
+
require 'osp_deploy/thread_info_logger'
|
2
|
+
require 'yaml'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
class OspDeploy::RailsDeployer
|
7
|
+
|
8
|
+
DEPLOY_CONFIG_FILE = "config/osp-deploy.yml"
|
9
|
+
|
10
|
+
REQUIRED_OPTIONS = { :always => [:jobs, :server_uris, :tag_prefix],
|
11
|
+
:torquebox => [:appl_name, :torquebox_home, :remote_dest_file_dir],
|
12
|
+
:file => [:remote_dest_file_dir],
|
13
|
+
:precompile_assets => [:environment],
|
14
|
+
}
|
15
|
+
|
16
|
+
DEFAULT_EXCLUDES = ['coverage', 'nbproject', '.idea', 'tmp', 'log', '.git', '*~']
|
17
|
+
BUNDLER_DEFAULT_CMD = "bundle install --deployment --without=test"
|
18
|
+
|
19
|
+
|
20
|
+
def initialize options
|
21
|
+
@options = options
|
22
|
+
@deployment_config = nil
|
23
|
+
@thread_logger = nil
|
24
|
+
@valid = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
def logger
|
30
|
+
@thread_logger ||= begin
|
31
|
+
#puts "Create ThreadInfoLogger."
|
32
|
+
logger = OspDeploy::ThreadInfoLogger.new(STDOUT)
|
33
|
+
logger.level = @options[:verbose] ? Logger::DEBUG : Logger::INFO
|
34
|
+
# im HUDSON/JENKINS keine farbige Ausgabe
|
35
|
+
logger.disable_ansi_colors=true if ( ENV['JENKINS_URL'] || ENV['HUDSON_URL'] )
|
36
|
+
logger
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def validate_config
|
42
|
+
dconfig_file_path = DEPLOY_CONFIG_FILE
|
43
|
+
cur_branch = parse_git_branch
|
44
|
+
logger.info "Read and validate deployment config file '#{dconfig_file_path}' for branch '#{cur_branch}'"
|
45
|
+
config = YAML.load_file(dconfig_file_path)
|
46
|
+
@deployment_config = config[cur_branch]
|
47
|
+
unless @deployment_config
|
48
|
+
raise "No config params for branch #{cur_branch} found in #{dconfig_file_path}!"
|
49
|
+
end
|
50
|
+
required_options = REQUIRED_OPTIONS[:always]
|
51
|
+
jobs = @deployment_config['jobs']
|
52
|
+
jobs = jobs.split(',').map(&:strip).map(&:to_sym) if jobs
|
53
|
+
@deployment_config['jobs'] = jobs
|
54
|
+
jobs && jobs.each do |job|
|
55
|
+
required_options |= REQUIRED_OPTIONS[job]
|
56
|
+
end
|
57
|
+
required_options.compact!
|
58
|
+
required_options.uniq!
|
59
|
+
validation_errors = required_options.select{|param_name| !@deployment_config.has_key?(param_name.to_s)}
|
60
|
+
unless validation_errors.empty?
|
61
|
+
logger.debug "Used deployment config: #{@deployment_config.inspect}"
|
62
|
+
raise "Error in deployment config! Missing options: #{validation_errors.join(', ')}"
|
63
|
+
end
|
64
|
+
git_check
|
65
|
+
@deployment_config[:branch] = cur_branch
|
66
|
+
@deployment_config["server_uris"].freeze
|
67
|
+
|
68
|
+
# some defaults
|
69
|
+
@deployment_config['environment'] ||= production
|
70
|
+
@valid = true
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
def gen_version_initializer
|
76
|
+
validate_config unless @valid
|
77
|
+
ini_file = 'version_from_git.rb'
|
78
|
+
fname = File.join("config", "initializers", ini_file)
|
79
|
+
|
80
|
+
# Ermittel Datum und ID des Commits vom HEAD
|
81
|
+
glog = `git log --pretty=format:"%ci %h" -n 1 HEAD`
|
82
|
+
cdate,refid = glog.scan(/(\d{4}-\d\d-\d\d \d\d:\d\d):\d\d [^ ]+ (\w+)/).flatten
|
83
|
+
|
84
|
+
# Ermitteln letzten Tag als Version
|
85
|
+
ver_nr = `git tag -l '#{@deployment_config['tag_prefix']}*' | tail -n 1`
|
86
|
+
ver_nr.chomp!
|
87
|
+
|
88
|
+
logger.info "Generate initializer '#{fname}' with: " +
|
89
|
+
"APP_VERSION(:nr => '#{ver_nr}', :commit_date => '#{cdate}', :git_id => '#{refid}', :branch => #{@deployment_config[:branch]})"
|
90
|
+
|
91
|
+
version_src = <<-EOT
|
92
|
+
# Version-Initializer
|
93
|
+
# Autogenerate from osp-git-deploy-tools
|
94
|
+
# DO NOT EDIT THIS !
|
95
|
+
|
96
|
+
app_structur = Struct.new :nr, :commit_date, :git_id, :branch
|
97
|
+
APP_VERSION = app_structur.new '#{ver_nr}', '#{cdate}', '#{refid}', '#{@deployment_config[:branch]}'
|
98
|
+
EOT
|
99
|
+
File.open(fname, 'w'){|f| f.write(version_src) }
|
100
|
+
make_last_changelog
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
# Deploy project files to remote server
|
106
|
+
def deploy_files
|
107
|
+
gen_version_initializer
|
108
|
+
threads = server_iterator(:threads => true) do |server_uri|
|
109
|
+
sync_files_to_remote_server(server_uri)
|
110
|
+
end
|
111
|
+
threads.each{|t| t.join }
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
# Deploy this project to the remote-servers
|
120
|
+
def deploy
|
121
|
+
gen_version_initializer
|
122
|
+
threads = nil
|
123
|
+
if @deployment_config['jobs'].include?(:file) || @deployment_config['jobs'].include?(:torquebox)
|
124
|
+
threads = server_iterator(:threads => true) do |server_uri|
|
125
|
+
precompile_assets if @deployment_config['jobs'].include?(:precompile_assets)
|
126
|
+
sync_files_to_remote_server(server_uri)
|
127
|
+
torquebox_deploy(server_uri) if @deployment_config['jobs'].include?(:torquebox)
|
128
|
+
precompile_assets_housekeeping if @deployment_config['jobs'].include?(:precompile_assets)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
threads.each{|t| t.join }
|
132
|
+
server_iterator do |server_uri|
|
133
|
+
execute_post_commands(server_uri)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# Deploy this project and execute bundler
|
139
|
+
def deploy_and_bundle
|
140
|
+
gen_version_initializer
|
141
|
+
threads = nil
|
142
|
+
if @deployment_config['jobs'].include?(:file) || @deployment_config['jobs'].include?(:torquebox)
|
143
|
+
threads = server_iterator(:threads => true) do |server_uri|
|
144
|
+
precompile_assets if @deployment_config['jobs'].include?(:precompile_assets)
|
145
|
+
sync_files_to_remote_server(server_uri)
|
146
|
+
bundler_actions_on_remote_server(server_uri)
|
147
|
+
torquebox_deploy(server_uri) if @deployment_config['jobs'].include?(:torquebox)
|
148
|
+
precompile_assets_housekeeping if @deployment_config['jobs'].include?(:precompile_assets)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
threads.each{|t| t.join }
|
152
|
+
server_iterator do |server_uri|
|
153
|
+
execute_post_commands(server_uri)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
# make git-log for last 20 commits in medium format into file last-changelog.txt
|
160
|
+
def make_last_changelog
|
161
|
+
logger.info "make_last_changelog"
|
162
|
+
system("git log --abbrev-commit --pretty=medium HEAD~20..HEAD > public/last-changelog.txt")
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
def server_iterator options={}
|
173
|
+
raise "No block given!" unless block_given?
|
174
|
+
server_ix = ENV['SERVER_NR']
|
175
|
+
threads = []
|
176
|
+
if @deployment_config['server_nr_required'] && server_ix.nil?
|
177
|
+
puts "Please set the in SERVER_NR environment! Sample: "
|
178
|
+
puts " SERVER_NR=1 rake osp:deploy"
|
179
|
+
puts ""
|
180
|
+
puts "Possible values:"
|
181
|
+
@deployment_config["server_uris"].each_with_index do |server, ix|
|
182
|
+
puts " [#{ix+1}] #{server}"
|
183
|
+
end
|
184
|
+
puts ""
|
185
|
+
raise "Server-Nr required but not set!"
|
186
|
+
end
|
187
|
+
if server_ix
|
188
|
+
server_uri = @deployment_config["server_uris"][server_ix.to_i-1]
|
189
|
+
raise "No Server with Nr=#{server_ix} configured!" if server_uri.nil?
|
190
|
+
server_uris = [server_uri]
|
191
|
+
else
|
192
|
+
server_uris = @deployment_config["server_uris"]
|
193
|
+
end
|
194
|
+
server_uris.each do |server_uri|
|
195
|
+
if options[:threads]
|
196
|
+
uri = server_uri.clone # Nowendig wegen Thread-Safe
|
197
|
+
threads << Thread.new do
|
198
|
+
Thread.current[:log_prefix] = "[#{uri}]"
|
199
|
+
yield(uri)
|
200
|
+
Thread.current[:log_prefix] = nil
|
201
|
+
end
|
202
|
+
else
|
203
|
+
Thread.current[:log_prefix] = "[#{server_uri}]"
|
204
|
+
yield(server_uri)
|
205
|
+
Thread.current[:log_prefix] = nil
|
206
|
+
end
|
207
|
+
end
|
208
|
+
threads
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
def execute_post_commands server_uri
|
214
|
+
post_commands = @deployment_config['post_commands']
|
215
|
+
return if post_commands.nil?
|
216
|
+
raise "Option 'post_commands' expected an Array!" unless post_commands.is_a?(Array)
|
217
|
+
logger.info "Execute post-commands."
|
218
|
+
|
219
|
+
file_dir = @deployment_config['remote_dest_file_dir']
|
220
|
+
post_commands = ["cd #{file_dir}"] + post_commands if file_dir
|
221
|
+
|
222
|
+
cmd = "ssh #{server_uri} \"#{post_commands.join(' && ')}\""
|
223
|
+
execute_cmd(cmd)
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
# Rsync Project-Dir mit Remote-Server inkl. Rename der Config-Files
|
229
|
+
def sync_files_to_remote_server server_uri
|
230
|
+
file_dir = @deployment_config['remote_dest_file_dir']
|
231
|
+
renames = @deployment_config['config_renames'] || {}
|
232
|
+
|
233
|
+
excludes = DEFAULT_EXCLUDES
|
234
|
+
excludes |= @deployment_config['excludes'] if @deployment_config['excludes']
|
235
|
+
excludes |= renames.values
|
236
|
+
exclude_file = Tempfile.new('osp-deploy-exludes')
|
237
|
+
exclude_file.write excludes.join("\n")
|
238
|
+
exclude_file.close
|
239
|
+
|
240
|
+
logger.info "FILE deployment to #{server_uri}:#{file_dir} started"
|
241
|
+
logger.debug "FILE deployment: excludes = #{excludes.join(', ')}"
|
242
|
+
runtime = Benchmark.realtime do
|
243
|
+
verbose = logger.debug? ? 'v' : nil
|
244
|
+
cmd = "rsync -ac#{verbose} --delete --exclude-from=#{exclude_file.path} . #{server_uri}:#{file_dir}"
|
245
|
+
execute_cmd cmd
|
246
|
+
|
247
|
+
# Umbenennen/Kopieren einiger config files
|
248
|
+
rename_cmds = []
|
249
|
+
renames.each do |src_name, dst_name|
|
250
|
+
rename_cmds << "cp #{src_name} #{dst_name}"
|
251
|
+
end
|
252
|
+
unless rename_cmds.empty?
|
253
|
+
cmd = "ssh #{server_uri} \"cd #{file_dir}/config && #{rename_cmds.join(' && ')} \""
|
254
|
+
execute_cmd cmd
|
255
|
+
end
|
256
|
+
end
|
257
|
+
exclude_file.delete
|
258
|
+
logger.info "FILE deployment finished in #{runtime.round}s"
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
# Aufruf des Bundlers auf dem Zielsystem
|
263
|
+
def bundler_actions_on_remote_server server_uri
|
264
|
+
file_dir = @deployment_config['remote_dest_file_dir']
|
265
|
+
bundler_cmd = @deployment_config['bundler_cmd'] || BUNDLER_DEFAULT_CMD
|
266
|
+
logger.info "Execute '#{bundler_cmd}' on #{server_uri}:#{file_dir}"
|
267
|
+
runtime = Benchmark.realtime do
|
268
|
+
bout = @options[:verbose] ? nil : '> /dev/null'
|
269
|
+
cmd = "ssh #{server_uri} \"cd #{file_dir} && #{bundler_cmd}\" #{bout}"
|
270
|
+
execute_cmd cmd
|
271
|
+
end
|
272
|
+
logger.info "Execute bundler finished in #{runtime.round}s"
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
def torquebox_deploy server_uri
|
279
|
+
appl_name = @deployment_config['appl_name']
|
280
|
+
tb_home = @deployment_config['torquebox_home']
|
281
|
+
web_config = <<EOS
|
282
|
+
---
|
283
|
+
application:
|
284
|
+
root: #{@deployment_config['remote_dest_file_dir']}
|
285
|
+
environment:
|
286
|
+
RACK_ENV: #{@deployment_config['environment']}
|
287
|
+
web:
|
288
|
+
context: #{appl_name}
|
289
|
+
EOS
|
290
|
+
conf_file = Tempfile.new('osp-deploy-tb-conf')
|
291
|
+
conf_file.write web_config
|
292
|
+
conf_file.close
|
293
|
+
deployment_file = "#{tb_home}/jboss/standalone/deployments/#{appl_name}-knob.yml"
|
294
|
+
deployment_file_marker = "#{deployment_file}.deployed"
|
295
|
+
logger.info "Torquebox deploy #{deployment_file}"
|
296
|
+
logger.debug "Torquebox deploy conf-file: #{File.read(conf_file.path)}"
|
297
|
+
execute_cmd "scp #{conf_file.path} #{server_uri}:#{deployment_file}"
|
298
|
+
execute_cmd "ssh #{server_uri} \"touch #{deployment_file_marker}\" "
|
299
|
+
conf_file.delete
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
# read current branch
|
306
|
+
def parse_git_branch
|
307
|
+
ref = `git symbolic-ref HEAD 2> /dev/null`
|
308
|
+
ref ||= ''
|
309
|
+
ref[/[^\/]+$/].chomp
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
# Überprüfen ob es Änderungen im Fiel-System gibt, die noch nicht in GIT eingecheckt wurden
|
314
|
+
def git_check
|
315
|
+
if @options[:no_git_check]
|
316
|
+
logger.warn "Skip GIT check !!! "
|
317
|
+
return
|
318
|
+
end
|
319
|
+
s = `git status`
|
320
|
+
unless s =~ /working directory clean/
|
321
|
+
logger.info "File-Changes not in GIT-Repository:\n#{s}\n"
|
322
|
+
raise "Currently exist changes! Please commit this before or set NO_GIT_CHECK environment to true."
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
def precompile_assets
|
328
|
+
logger.info "Precompile assets..."
|
329
|
+
execute_cmd "bundle exec rake assets:precompile RAILS_ENV=#{@deployment_config['environment']}"
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
def precompile_assets_housekeeping
|
334
|
+
asset_dir = 'public/assets'
|
335
|
+
if File.exist?(asset_dir)
|
336
|
+
logger.info "Precompile assets housekeeping: remove '#{asset_dir}'"
|
337
|
+
FileUtils.rm_rf asset_dir
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
def execute_cmd cmd
|
343
|
+
logger.debug "Execute: #{cmd[/\w+/]}\n\t#{cmd}"
|
344
|
+
rc = system(cmd)
|
345
|
+
raise("Command '#{cmd}' failed.") unless rc
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Colorful logger with additional infos from thread
|
2
|
+
# The additional info is read from Thread.current[:log_prefix]
|
3
|
+
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
class OspDeploy::ThreadInfoLogger < ::Logger
|
7
|
+
|
8
|
+
SERVERITY_COLORS = {
|
9
|
+
'DEBUG' => "\033[37m", # Light Gray
|
10
|
+
'INFO' => "\033[32m", # Green
|
11
|
+
'WARN' => "\033[33m", # Yellow
|
12
|
+
'ERROR' => "\033[31m" # Red
|
13
|
+
}
|
14
|
+
|
15
|
+
attr_accessor :disable_ansi_colors
|
16
|
+
|
17
|
+
def format_message(severity, timestamp, progname, msg)
|
18
|
+
thread_info = Thread.current[:log_prefix]
|
19
|
+
prefix = "%s %-5s %s - " % [timestamp.strftime('%H:%M:%S'), severity, thread_info]
|
20
|
+
# Einfügen Zeilenumbruch bei langen Messages
|
21
|
+
width = 120
|
22
|
+
log_msg = insert_line_feeds(msg, width, prefix)
|
23
|
+
log_msg = colorize(log_msg, SERVERITY_COLORS[severity]) unless @disable_ansi_colors
|
24
|
+
"#{log_msg}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def insert_line_feeds msg, max_length, prefix
|
31
|
+
return if msg.nil?
|
32
|
+
return "#{prefix}#{msg}" if msg.length < max_length
|
33
|
+
ix = msg.rindex(' ', max_length-prefix.length-5)
|
34
|
+
if ix && ix > 0
|
35
|
+
log_msg = "#{prefix}#{msg[0,ix]}\n"
|
36
|
+
log_msg << insert_line_feeds(msg[ix..-1], max_length, "\t")
|
37
|
+
else
|
38
|
+
log_msg = "#{prefix}#{msg}"
|
39
|
+
end
|
40
|
+
log_msg
|
41
|
+
end
|
42
|
+
|
43
|
+
def colorize(text, color_code)
|
44
|
+
"#{color_code}#{text}\033[0m"
|
45
|
+
end
|
46
|
+
end
|
data/lib/osp_deploy.rb
ADDED
data/osp-deploy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'osp_deploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "osp-deploy"
|
8
|
+
gem.version = OspDeploy::VERSION
|
9
|
+
gem.authors = ["Bernd Ledig"]
|
10
|
+
gem.email = ["bernd.ledig@ottogroup.com"]
|
11
|
+
gem.description = "Rails-Deploy-Tool"
|
12
|
+
gem.summary = "Deploay a Rails-App as JRuby-Webapp into Java-App-Server like Torquebox"
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec", '>2.7', '<3.0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osp-deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bernd Ledig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>'
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.7'
|
34
|
+
- - <
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.0'
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>'
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.7'
|
42
|
+
- - <
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.0'
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
|
+
description: Rails-Deploy-Tool
|
48
|
+
email:
|
49
|
+
- bernd.ledig@ottogroup.com
|
50
|
+
executables:
|
51
|
+
- osp-rails-deploy.rb
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/osp-rails-deploy.rb
|
61
|
+
- lib/osp_deploy.rb
|
62
|
+
- lib/osp_deploy/logger_redirect.rb
|
63
|
+
- lib/osp_deploy/rails_deployer.rb
|
64
|
+
- lib/osp_deploy/thread_info_logger.rb
|
65
|
+
- lib/osp_deploy/version.rb
|
66
|
+
- osp-deploy.gemspec
|
67
|
+
homepage: ''
|
68
|
+
licenses: []
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Deploay a Rails-App as JRuby-Webapp into Java-App-Server like Torquebox
|
90
|
+
test_files: []
|