mina-multideploy 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 969d4c8fccca59952aab56ffbce0dbd41c8ec0ab14d81ba3fa8258b3705e82bc
4
+ data.tar.gz: 8fc2f58ce2e9715f04c45cd1a17c53fd57bd3b72305b3726fcf17757ed852171
5
+ SHA512:
6
+ metadata.gz: 9ddeb3a89e0bfbf602574d8fc01a7a5239fa4fa56fc03c37887b6f2ec1a42aedb6b209cf63ba9ac954a699c4fcb00c9f3b7dd248bf166952ad2d2defd5739bab
7
+ data.tar.gz: 6f08a685ce34814fcd65acc1a7977a8b07df883092a6fde7242f86cc3213a50b8182e38ed922ba3aa3ed9e9f1c4de5645f74c3f185899d95beb63c00d3b92efa
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mina-multideploy.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sergey Volkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,89 @@
1
+ # Mina multideploy
2
+
3
+ Useful tool for parallel deploying on multiple servers with [mina](https://github.com/mina-deploy/mina).
4
+
5
+ ## How it works
6
+ This gem will help you deploy the application on multiple servers in parallel. It takes original mina `deploy.rb` file, changes `application_name`, `domain` and starts deploying process.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mina-multideploy'
13
+ ```
14
+
15
+ And then execute:
16
+ ```
17
+ bundle install
18
+ ```
19
+
20
+ Or install it yourself as:
21
+ ```bash
22
+ gem install mina-multideploy
23
+ ```
24
+
25
+ ## Getting Started
26
+ Start off by generating a configuration file:
27
+ ```
28
+ bundle exec rails multideploy:init
29
+ ```
30
+ It should give you a file in:
31
+ ```
32
+ config/initializers/multideploy.rb
33
+ ```
34
+ It should look something like this:
35
+ ```ruby
36
+ Mina::Multideploy.configure do |config|
37
+ config.servers = {}
38
+ # Default velues
39
+ # config.original = 'config/deploy.rb'
40
+ # config.w_dir = 'tmp/deploy'
41
+ end
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ *`servers`* - hash at format `domain` => `array of application_name's`.
47
+
48
+ Example:
49
+ ```
50
+ config.servers = {
51
+ '84.155.207.209' => %w[carghana caryange cartanzania]
52
+ '105.87.69.69' => %w[poster]
53
+ '48.84.207.183' => %w[codica timebot]
54
+ }
55
+ ```
56
+ It means that your code will be deployed to 3 servers, and there can be several applications on one server.
57
+
58
+ *`original`* - path to the original mina `deploy.rb` file which will be taken as a basic.
59
+
60
+ *`w_dir`* - path to directory where temoporary files and logs will be created.
61
+
62
+ ## Available features
63
+ After you have configured servers at `config/initializers/multideploy.rb` you can start deploying in two ways.
64
+
65
+ ### Semi-automatic deploy (recomended for first deploy)
66
+ Run this command:
67
+ ```ruby
68
+ bundle exec rails multideploy:prepare
69
+ ```
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`.
71
+
72
+ ### Automatic deploy
73
+ Run this command:
74
+ ```ruby
75
+ bundle exec rails multideploy:start
76
+ ```
77
+ It will make the same as `multideploy:prepare`, but the deployment will start automatically.
78
+
79
+ ## Additional information
80
+ * all scripts are updated before launch `multideploy:prepare` and `multideploy:start`
81
+ * add public SSH key, so you can login to server without password. Run `ssh-copy-id user@$host`
82
+
83
+ ## License
84
+
85
+ Mina multideploy is released under the [MIT License](https://opensource.org/licenses/MIT)
86
+
87
+ ## About Codica
88
+
89
+ [![Codica logo](https://www.codica.com/assets/images/logo/logo.svg)](https://www.codica.com)
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mina/multideploy'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require 'mina/multideploy/railtie'
2
+ require 'mina/multideploy/base_service'
3
+ require 'mina/multideploy/version'
4
+
5
+ module Mina
6
+ module Multideploy
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+ yield(configuration)
14
+ end
15
+
16
+ class Configuration
17
+ attr_accessor :servers, :original, :w_dir
18
+
19
+ def initialize
20
+ @servers = {}
21
+ @original = 'config/deploy.rb'
22
+ @w_dir = 'tmp/deploy'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Multideploy
2
+ class BaseService
3
+ def self.call(*args)
4
+ new(*args).call
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,65 @@
1
+ require 'fileutils'
2
+
3
+ module Multideploy
4
+ class CreateScripts < BaseService
5
+ attr_reader :c
6
+
7
+ def initialize
8
+ @c = Mina::Multideploy.configuration
9
+ end
10
+
11
+ def call
12
+ create_dir
13
+ write_bash_script
14
+ write_ruby_script
15
+ end
16
+
17
+ private
18
+
19
+ def working_dir
20
+ c.w_dir
21
+ end
22
+
23
+ def create_dir
24
+ FileUtils.mkdir_p(working_dir)
25
+ end
26
+
27
+ 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"
48
+ end
49
+
50
+ def ruby_script
51
+ template_path = File.join(File.dirname(__FILE__), "./templates/#{deploy_file}")
52
+ script = File.read(template_path)
53
+ script = script.gsub('SERVERS_TO_REPLACE', c.servers.inspect)
54
+ script = script.gsub('ORIGINAL_DEPLOY_FILE_TO_REPLACE', c.original)
55
+ script = script.gsub('CUSTOM_W_DIR_TO_REPLACE', c.w_dir)
56
+ end
57
+
58
+ def write_ruby_script
59
+ File.open("#{working_dir}/#{deploy_file}", 'w+') do |f|
60
+ f.write(ruby_script)
61
+ end
62
+ FileUtils.chmod 0755, "#{working_dir}/#{deploy_file}"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,35 @@
1
+ module Multideploy
2
+ class Init < BaseService
3
+ def call
4
+ create
5
+ end
6
+
7
+ private
8
+
9
+ def path
10
+ 'config/initializers/multideploy.rb'
11
+ end
12
+
13
+ def content
14
+ <<-EOS
15
+ Mina::Multideploy.configure do |config|
16
+ config.servers = {}
17
+ # Default velues
18
+ # config.original = 'config/deploy.rb'
19
+ # config.w_dir = 'tmp/deploy'
20
+ end
21
+ EOS
22
+ end
23
+
24
+ def create
25
+ if File.exist?(path)
26
+ puts "#{path} already exist."
27
+ else
28
+ File.open(path, 'w+') do |f|
29
+ f.write(content)
30
+ end
31
+ puts "#{path} created. Feel free to chenge it!"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module Multideploy
2
+ class Railtie < ::Rails::Railtie
3
+ rake_tasks do
4
+ load 'mina/tasks/multideploy_tasks.rake'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,5 @@
1
+ module Mina
2
+ module Multideploy
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require 'mina/multideploy/init'
2
+ require 'mina/multideploy/create_scripts'
3
+
4
+ namespace :multideploy do
5
+ desc 'Create initializer file'
6
+ task init: :environment do
7
+ Multideploy::Init.call
8
+ end
9
+
10
+ desc 'Prepare deploy scripts'
11
+ task prepare: :environment do
12
+ c = Mina::Multideploy.configuration
13
+ Multideploy::CreateScripts.call
14
+ puts "Run './#{c.w_dir}/multideploy' to start deploy"
15
+ end
16
+
17
+ desc 'Prepare deploy scripts and start deploying'
18
+ task start: :environment do
19
+ c = Mina::Multideploy.configuration
20
+ Multideploy::CreateScripts.call
21
+ exec "./#{c.w_dir}/multideploy"
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mina/multideploy/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mina-multideploy'
7
+ spec.version = Mina::Multideploy::VERSION
8
+ spec.authors = ['Sergey Volkov']
9
+ spec.email = ['sergvolkov.codica@gmail.com']
10
+
11
+ spec.summary = 'Parallel deploying on multiple servers with mina.'
12
+ spec.description = 'This gem will help you deploy the application on multiple servers in parallel. It takes original mina deploy.rb file, changes application_name, domain and starts deploying process.'
13
+ spec.homepage = 'https://github.com/codica2/mina-multideploy'
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-multideploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Volkov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-09 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem will help you deploy the application on multiple servers in
56
+ parallel. It takes original mina deploy.rb file, changes application_name, domain
57
+ and starts deploying process.
58
+ email:
59
+ - sergvolkov.codica@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/mina/multideploy.rb
74
+ - lib/mina/multideploy/base_service.rb
75
+ - lib/mina/multideploy/create_scripts.rb
76
+ - lib/mina/multideploy/init.rb
77
+ - lib/mina/multideploy/railtie.rb
78
+ - lib/mina/multideploy/templates/server_deploy.rb
79
+ - lib/mina/multideploy/version.rb
80
+ - lib/mina/tasks/multideploy_tasks.rake
81
+ - mina-multideploy.gemspec
82
+ homepage: https://github.com/codica2/mina-multideploy
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.7.7
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Parallel deploying on multiple servers with mina.
106
+ test_files: []