mina-multideploy 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/mina/multideploy/create_scripts.rb +2 -22
- data/lib/mina/multideploy/init.rb +2 -0
- data/lib/mina/multideploy/templates/servers_deploy.rb +48 -0
- data/lib/mina/multideploy/version.rb +1 -1
- data/lib/mina/tasks/multideploy_tasks.rake +2 -2
- data/mina-multideploy.gemspec +2 -0
- metadata +31 -3
- data/lib/mina/multideploy/templates/server_deploy.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aca7ad4690b9550048d60ca01c629d187bd788722558ec41a528b3518e662087
|
4
|
+
data.tar.gz: 52671874308ad8cd188ecdc2f086107b09eb7fe31483ced6b91b1fa44fcb2418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a45f632fec2ac0689d50d3cc76e592966412892e8658b3feffda14a46a321f182719318a0b7e7a0c88c0f063b5b94a2ddcbe3672c75dd271365fa84462c7bc36
|
7
|
+
data.tar.gz: ed2f1996a3032daa0f915416f4a2c31b3dff15781ee8c2a365230071fe5ebb9d1ab0c3fb9d307fa45cf9260a5263687527465cc241014b87372b72d37292e477
|
data/README.md
CHANGED
@@ -33,6 +33,8 @@ config/initializers/multideploy.rb
|
|
33
33
|
```
|
34
34
|
It should look something like this:
|
35
35
|
```ruby
|
36
|
+
return unless defined? Mina::Multideploy
|
37
|
+
|
36
38
|
Mina::Multideploy.configure do |config|
|
37
39
|
config.servers = {}
|
38
40
|
# Default velues
|
@@ -46,7 +48,7 @@ end
|
|
46
48
|
*`servers`* - hash at format `domain` => `array of application_name's`.
|
47
49
|
|
48
50
|
Example:
|
49
|
-
```
|
51
|
+
```ruby
|
50
52
|
config.servers = {
|
51
53
|
'84.155.207.209' => %w[carghana caryange cartanzania]
|
52
54
|
'105.87.69.69' => %w[poster]
|
@@ -67,7 +69,7 @@ Run this command:
|
|
67
69
|
```ruby
|
68
70
|
bundle exec rails multideploy:prepare
|
69
71
|
```
|
70
|
-
You will get
|
72
|
+
You will get file `servers_deploy.rb` at working directory (tmp/deploy by default). Check it and run `ruby ./tmp/deploy/server_deploy.rb`.
|
71
73
|
|
72
74
|
### Automatic deploy
|
73
75
|
Run this command:
|
@@ -77,7 +79,7 @@ bundle exec rails multideploy:start
|
|
77
79
|
It will make the same as `multideploy:prepare`, but the deployment will start automatically.
|
78
80
|
|
79
81
|
## Additional information
|
80
|
-
* all scripts are updated before launch `multideploy:prepare` and `multideploy:start`
|
82
|
+
* all scripts are updated according config file before launch `multideploy:prepare` and `multideploy:start`
|
81
83
|
* add public SSH key, so you can login to server without password. Run `ssh-copy-id user@$host`
|
82
84
|
|
83
85
|
## License
|
@@ -10,7 +10,6 @@ module Multideploy
|
|
10
10
|
|
11
11
|
def call
|
12
12
|
create_dir
|
13
|
-
write_bash_script
|
14
13
|
write_ruby_script
|
15
14
|
end
|
16
15
|
|
@@ -25,26 +24,7 @@ module Multideploy
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def deploy_file
|
28
|
-
'
|
29
|
-
end
|
30
|
-
|
31
|
-
def bash_script
|
32
|
-
script = '#!/bin/bash'
|
33
|
-
script << "\n\n"
|
34
|
-
script << "echo 'Deploy started!'"
|
35
|
-
script << "\n\n"
|
36
|
-
script << c.servers.keys.map { |ip| "ruby \"$PWD/#{working_dir}/#{deploy_file}\" --ip #{ip} &\n" }.join('')
|
37
|
-
script << "\n"
|
38
|
-
script << 'wait'
|
39
|
-
script << "\n"
|
40
|
-
script << "echo 'Deploy finished!'"
|
41
|
-
end
|
42
|
-
|
43
|
-
def write_bash_script
|
44
|
-
File.open("#{working_dir}/multideploy", 'w+') do |f|
|
45
|
-
f.write(bash_script)
|
46
|
-
end
|
47
|
-
FileUtils.chmod 0755, "#{working_dir}/multideploy"
|
27
|
+
'servers_deploy.rb'
|
48
28
|
end
|
49
29
|
|
50
30
|
def ruby_script
|
@@ -59,7 +39,7 @@ module Multideploy
|
|
59
39
|
File.open("#{working_dir}/#{deploy_file}", 'w+') do |f|
|
60
40
|
f.write(ruby_script)
|
61
41
|
end
|
62
|
-
FileUtils.chmod
|
42
|
+
FileUtils.chmod 0o755, "#{working_dir}/#{deploy_file}"
|
63
43
|
end
|
64
44
|
end
|
65
45
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'logger'
|
3
|
+
require 'parallel'
|
4
|
+
require 'tty-progressbar'
|
5
|
+
# require 'byebug'
|
6
|
+
|
7
|
+
# Servers list
|
8
|
+
SERVERS = SERVERS_TO_REPLACE
|
9
|
+
|
10
|
+
w_dir = Dir.pwd
|
11
|
+
c_dir = "#{w_dir}/CUSTOM_W_DIR_TO_REPLACE/config"
|
12
|
+
l_dir = "#{w_dir}/CUSTOM_W_DIR_TO_REPLACE/log"
|
13
|
+
|
14
|
+
original_deploy_config = File.read("#{w_dir}/ORIGINAL_DEPLOY_FILE_TO_REPLACE")
|
15
|
+
max_ip_length = SERVERS.keys.map(&:length).max + 1
|
16
|
+
multibar = TTY::ProgressBar::Multi.new
|
17
|
+
|
18
|
+
FileUtils.mkdir_p c_dir unless File.exist?(c_dir)
|
19
|
+
FileUtils.mkdir_p l_dir unless File.exist?(l_dir)
|
20
|
+
|
21
|
+
# Deploy script
|
22
|
+
Parallel.each(SERVERS, in_threads: SERVERS.length) do |ip, names|
|
23
|
+
bar = multibar.register("#{ip.ljust(max_ip_length)} [:current/:total] :report", total: names.size)
|
24
|
+
bar.start
|
25
|
+
|
26
|
+
report = ''
|
27
|
+
bar.advance(0, report: report)
|
28
|
+
|
29
|
+
names.each do |site|
|
30
|
+
c_file_name = "#{ip}-#{site}.rb"
|
31
|
+
l_file_name = "#{ip}-#{site}.log"
|
32
|
+
|
33
|
+
custom_deploy_config = original_deploy_config.gsub(/^set :application_name(.*)/, "set :application_name, :#{site}")
|
34
|
+
custom_deploy_config = custom_deploy_config.gsub(/^set :domain(.*)/, "set :domain, '#{ip}'")
|
35
|
+
|
36
|
+
FileUtils.rm "#{l_dir}/#{l_file_name}" if File.exist?("#{l_dir}/#{l_file_name}")
|
37
|
+
File.write("#{c_dir}/#{c_file_name}", custom_deploy_config)
|
38
|
+
|
39
|
+
cmd = "mina deploy -f #{c_dir}/#{c_file_name}"
|
40
|
+
cmd = `#{cmd}`
|
41
|
+
|
42
|
+
logger = Logger.new("#{l_dir}/#{l_file_name}")
|
43
|
+
logger.info(cmd)
|
44
|
+
|
45
|
+
report += "#{site} ✗ " if cmd.include?('ERROR: Deploy failed.')
|
46
|
+
bar.advance(report: report)
|
47
|
+
end
|
48
|
+
end
|
@@ -11,13 +11,13 @@ namespace :multideploy do
|
|
11
11
|
task prepare: :environment do
|
12
12
|
c = Mina::Multideploy.configuration
|
13
13
|
Multideploy::CreateScripts.call
|
14
|
-
puts "Run './#{c.w_dir}/
|
14
|
+
puts "Run 'ruby ./#{c.w_dir}/servers_deploy.rb' to start deploy"
|
15
15
|
end
|
16
16
|
|
17
17
|
desc 'Prepare deploy scripts and start deploying'
|
18
18
|
task start: :environment do
|
19
19
|
c = Mina::Multideploy.configuration
|
20
20
|
Multideploy::CreateScripts.call
|
21
|
-
exec "./#{c.w_dir}/
|
21
|
+
exec "ruby ./#{c.w_dir}/servers_deploy.rb"
|
22
22
|
end
|
23
23
|
end
|
data/mina-multideploy.gemspec
CHANGED
@@ -25,4 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_runtime_dependency 'parallel'
|
29
|
+
spec.add_runtime_dependency 'tty-progressbar'
|
28
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-multideploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Volkov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: parallel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-progressbar
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: This gem will help you deploy the application on multiple servers in
|
56
84
|
parallel. It takes original mina deploy.rb file, changes application_name, domain
|
57
85
|
and starts deploying process.
|
@@ -75,7 +103,7 @@ files:
|
|
75
103
|
- lib/mina/multideploy/create_scripts.rb
|
76
104
|
- lib/mina/multideploy/init.rb
|
77
105
|
- lib/mina/multideploy/railtie.rb
|
78
|
-
- lib/mina/multideploy/templates/
|
106
|
+
- lib/mina/multideploy/templates/servers_deploy.rb
|
79
107
|
- lib/mina/multideploy/version.rb
|
80
108
|
- lib/mina/tasks/multideploy_tasks.rake
|
81
109
|
- mina-multideploy.gemspec
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'logger'
|
3
|
-
require 'optparse'
|
4
|
-
# require 'byebug'
|
5
|
-
|
6
|
-
# Servers list
|
7
|
-
SERVERS = SERVERS_TO_REPLACE
|
8
|
-
|
9
|
-
# Read entered options
|
10
|
-
options = {}
|
11
|
-
OptionParser.new do |parser|
|
12
|
-
parser.banner = 'Usage: hello.rb [options]'
|
13
|
-
|
14
|
-
parser.on('-h', '--help', 'Show this help message') do
|
15
|
-
puts parser
|
16
|
-
end
|
17
|
-
|
18
|
-
parser.on('--ip IP', 'The ip address server to deploy.') do |v|
|
19
|
-
options[:ip] = v
|
20
|
-
end
|
21
|
-
end.parse!
|
22
|
-
|
23
|
-
ip = options[:ip]
|
24
|
-
w_dir = Dir.pwd
|
25
|
-
c_dir = "#{w_dir}/CUSTOM_W_DIR_TO_REPLACE/config"
|
26
|
-
l_dir = "#{w_dir}/CUSTOM_W_DIR_TO_REPLACE/log"
|
27
|
-
original_deploy_config = File.read("#{w_dir}/ORIGINAL_DEPLOY_FILE_TO_REPLACE")
|
28
|
-
|
29
|
-
FileUtils.mkdir_p c_dir unless File.exist?(c_dir)
|
30
|
-
FileUtils.mkdir_p l_dir unless File.exist?(l_dir)
|
31
|
-
|
32
|
-
# Deploy report to console
|
33
|
-
class SiteDeployReport
|
34
|
-
|
35
|
-
attr_reader :ip, :site, :status
|
36
|
-
|
37
|
-
def initialize(ipaddress, site, status)
|
38
|
-
@ip = ipaddress
|
39
|
-
@site = site
|
40
|
-
@status = status
|
41
|
-
end
|
42
|
-
|
43
|
-
def call
|
44
|
-
puts "#{ip} - #{site} - #{status}"
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
# Deploy script
|
50
|
-
SERVERS[ip].each do |site|
|
51
|
-
c_file_name = "#{ip}-#{site}.rb"
|
52
|
-
l_file_name = "#{ip}-#{site}.log"
|
53
|
-
|
54
|
-
FileUtils.rm "#{l_dir}/#{l_file_name}" if File.exist?("#{l_dir}/#{l_file_name}")
|
55
|
-
logger = Logger.new("#{l_dir}/#{l_file_name}")
|
56
|
-
|
57
|
-
custom_deploy_config = original_deploy_config.gsub(/^set :application_name(.*)/, "set :application_name, :#{site}")
|
58
|
-
custom_deploy_config = custom_deploy_config.gsub(/^set :domain(.*)/, "set :domain, '#{ip}'")
|
59
|
-
|
60
|
-
File.write("#{c_dir}/#{c_file_name}", custom_deploy_config)
|
61
|
-
|
62
|
-
cmd = "mina deploy -f #{c_dir}/#{c_file_name}"
|
63
|
-
cmd = `#{cmd}`
|
64
|
-
|
65
|
-
logger.info(cmd)
|
66
|
-
|
67
|
-
raise 'ERROR: Deploy failed.' if cmd.include?('ERROR: Deploy failed.')
|
68
|
-
|
69
|
-
rescue StandardError => e
|
70
|
-
SiteDeployReport.new(ip, site, '✗').call
|
71
|
-
logger.error(e)
|
72
|
-
else
|
73
|
-
SiteDeployReport.new(ip, site, '✓').call
|
74
|
-
end
|