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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 969d4c8fccca59952aab56ffbce0dbd41c8ec0ab14d81ba3fa8258b3705e82bc
4
- data.tar.gz: 8fc2f58ce2e9715f04c45cd1a17c53fd57bd3b72305b3726fcf17757ed852171
3
+ metadata.gz: aca7ad4690b9550048d60ca01c629d187bd788722558ec41a528b3518e662087
4
+ data.tar.gz: 52671874308ad8cd188ecdc2f086107b09eb7fe31483ced6b91b1fa44fcb2418
5
5
  SHA512:
6
- metadata.gz: 9ddeb3a89e0bfbf602574d8fc01a7a5239fa4fa56fc03c37887b6f2ec1a42aedb6b209cf63ba9ac954a699c4fcb00c9f3b7dd248bf166952ad2d2defd5739bab
7
- data.tar.gz: 6f08a685ce34814fcd65acc1a7977a8b07df883092a6fde7242f86cc3213a50b8182e38ed922ba3aa3ed9e9f1c4de5645f74c3f185899d95beb63c00d3b92efa
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 two files `multideploy` and `server_deploy.rb` at working directory (tmp/deploy by default). Check them and run `./tmp/deploy/multideploy`.
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
- 'server_deploy.rb'
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 0755, "#{working_dir}/#{deploy_file}"
42
+ FileUtils.chmod 0o755, "#{working_dir}/#{deploy_file}"
63
43
  end
64
44
  end
65
45
  end
@@ -12,6 +12,8 @@ module Multideploy
12
12
 
13
13
  def content
14
14
  <<-EOS
15
+ return unless defined? Mina::Multideploy
16
+
15
17
  Mina::Multideploy.configure do |config|
16
18
  config.servers = {}
17
19
  # Default velues
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Multideploy
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  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}/multideploy' to start deploy"
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}/multideploy"
21
+ exec "ruby ./#{c.w_dir}/servers_deploy.rb"
22
22
  end
23
23
  end
@@ -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.0.0
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-09 00:00:00.000000000 Z
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/server_deploy.rb
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