mr-shipper 0.0.1
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/bin/ship +6 -0
- data/lib/shipper/config.rb +16 -0
- data/lib/shipper/deploy.rb +42 -0
- data/lib/shipper/executor.rb +47 -0
- data/lib/shipper/host.rb +36 -0
- data/lib/shipper/logger.rb +31 -0
- data/lib/shipper/service.rb +31 -0
- data/lib/shipper.rb +10 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 20ee8ca7212836d14568ba6c775d97481407e88583e0bec19ffcd8dc57541e9b
|
4
|
+
data.tar.gz: c38afecf60d8ce258972239a8b884bbae66fca9abe75f64c1f7c93d8633ffc5c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe1b457d4eda6aca061641919eb53b66a0a70f765f852107ed2a2efd6bf5673ac73e46625e0e92087288cd72d48fcdd65adaeebcb00508002978573f94fe8f5c
|
7
|
+
data.tar.gz: e02b32a75d76674280579fbd4a65516ae0555eabe7fd2c8ebebab7f41593bf706f326b20713e561fc80ac9900d5cc436a4be8e49911456e8f60a16ae9155fc99
|
data/bin/ship
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'singleton'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module Shipper
|
8
|
+
class Config < ::OpenStruct
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
config = ::YAML::load_file("#{Dir.pwd}/shipper.yml")
|
13
|
+
super(config)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shipper
|
4
|
+
class Deploy
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@config = Shipper::Config.instance
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
ship_services!
|
13
|
+
update_host!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def ship_services!
|
19
|
+
logger.headline('Shipping services..')
|
20
|
+
services = load_services
|
21
|
+
services.each(&:ship!)
|
22
|
+
logger.headline('Services shipped!')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_host!
|
26
|
+
logger.headline('Updating host..')
|
27
|
+
host = ::Shipper::Host.new(config.host)
|
28
|
+
host.update!
|
29
|
+
logger.headline('Host updated!')
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_services
|
33
|
+
config.services.map do |name, config|
|
34
|
+
::Shipper::Service.new(name, config)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def logger
|
39
|
+
::Shipper::Logger.instance
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/ssh'
|
4
|
+
require 'open3'
|
5
|
+
|
6
|
+
module Shipper
|
7
|
+
class Executor
|
8
|
+
attr_accessor :host_bash, :path
|
9
|
+
|
10
|
+
def initialize(host_bash = nil, path = nil)
|
11
|
+
@host_bash = host_bash
|
12
|
+
@path = path || Dir.pwd
|
13
|
+
end
|
14
|
+
|
15
|
+
def exec(cmd)
|
16
|
+
host_bash ? exec_host(cmd) : exec_local(cmd)
|
17
|
+
end
|
18
|
+
|
19
|
+
def cd(new_location)
|
20
|
+
@path = new_location
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def exec_host(cmd)
|
26
|
+
logger.bold("Exec host '#{cmd}'")
|
27
|
+
|
28
|
+
host_bash.exec!("cd #{path}; #{cmd}") do |channel, stream, data|
|
29
|
+
logger.puts(data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def exec_local(cmd)
|
34
|
+
logger.bold("Exec local '#{cmd}'")
|
35
|
+
|
36
|
+
Dir.chdir(path) do
|
37
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr|
|
38
|
+
logger.puts(stdout.gets)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def logger
|
44
|
+
::Shipper::Logger.instance
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/shipper/host.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shipper
|
4
|
+
class Host
|
5
|
+
attr_accessor :ssh_entry, :location, :executor
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@ssh_entry = options['ssh_entry']
|
9
|
+
@location = options['location']
|
10
|
+
@executor = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def update!
|
14
|
+
user, host = ssh_entry.split('@')
|
15
|
+
|
16
|
+
::Net::SSH.start(host, user) do |ssh|
|
17
|
+
load_executor(ssh)
|
18
|
+
|
19
|
+
executor.cd location
|
20
|
+
exec 'docker-compose pull'
|
21
|
+
exec 'docker-compose down'
|
22
|
+
exec 'docker-compose up -d'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def exec(cmd)
|
29
|
+
executor.exec(cmd)
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_executor(ssh)
|
33
|
+
@executor = ::Shipper::Executor.new(ssh, location)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
module Shipper
|
6
|
+
class Logger
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_reader :io_splitter
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@io_splitter = '#' * 5
|
13
|
+
end
|
14
|
+
|
15
|
+
def headline(phrase)
|
16
|
+
puts "##### #{phrase}".bold.green
|
17
|
+
end
|
18
|
+
|
19
|
+
def bold(phrase)
|
20
|
+
puts "# #{phrase}".bold.yellow
|
21
|
+
end
|
22
|
+
|
23
|
+
def puts(phrase)
|
24
|
+
super(phrase)
|
25
|
+
end
|
26
|
+
|
27
|
+
def success!
|
28
|
+
puts '# Success!'.green
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shipper
|
4
|
+
class Service
|
5
|
+
attr_reader :name, :path, :before_build, :repo
|
6
|
+
|
7
|
+
def initialize(name, options)
|
8
|
+
@name = name
|
9
|
+
@path = "#{Dir.pwd}/#{options['path']}"
|
10
|
+
@before_build = options['before_build']
|
11
|
+
@repo = options['repo']
|
12
|
+
end
|
13
|
+
|
14
|
+
def ship!
|
15
|
+
executor.cd(path)
|
16
|
+
before_build.each { |cmd| exec(cmd) } if before_build
|
17
|
+
exec "docker build . -t #{repo}"
|
18
|
+
exec "docker push #{repo}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def exec(cmd)
|
24
|
+
executor.exec(cmd)
|
25
|
+
end
|
26
|
+
|
27
|
+
def executor
|
28
|
+
@executor ||= ::Shipper::Executor.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/shipper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mr-shipper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rostyslav Safonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-ssh
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.1
|
41
|
+
description: The simple way to deploy docker-compose based apps
|
42
|
+
email: elhowm@gmail.com
|
43
|
+
executables:
|
44
|
+
- ship
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/ship
|
49
|
+
- lib/shipper.rb
|
50
|
+
- lib/shipper/config.rb
|
51
|
+
- lib/shipper/deploy.rb
|
52
|
+
- lib/shipper/executor.rb
|
53
|
+
- lib/shipper/host.rb
|
54
|
+
- lib/shipper/logger.rb
|
55
|
+
- lib/shipper/service.rb
|
56
|
+
homepage: https://rubygemspecs.org/gems/mr-shipper
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Docker shipping
|
79
|
+
test_files: []
|