indocker 0.1.11 → 0.1.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8625d37ada817f2f83c30f154bd2ed9a104a023e5b554f4c91f3708ed4aa2770
4
- data.tar.gz: 24950eb94bd956f7f10ad81da4330bffa78495a4852733a1bec5d0713cce4896
3
+ metadata.gz: 288383229ce87e66ab3869aa6fcd5180e0a54d09ca4046ed32a4ec34550a564f
4
+ data.tar.gz: 77eed21c9ad07145d0141c8450495fd74b6336cea91fc76a5dc37909f3983ee6
5
5
  SHA512:
6
- metadata.gz: e50ef7ed88a688bb1119e55b1d1662d6827e5667cc66c61dc85933687e9d4834c785c03c7fb917a2709adf04d909f7e611f8c844741b1532211dddad340dc149
7
- data.tar.gz: 1e52f25fff3bf09ddb7f1d097b46ad0e858555892d3b4721a628c8817a16e165694dbf3650e940eb83cb6ac05d8ded47c6359ada9d3cba39d3885ff95e9e88d0
6
+ metadata.gz: 6e91c51c6898841882c3543a31710b84db43e2fc20498174119b269eaa47f9caf260a0720d99645a03dd292d470be4adadaaec6d4cadebce1290998782a3156a
7
+ data.tar.gz: cbf4395ff9f1f21c56785fa926dbaf3af80f33cad68041fa4ee9c2e8cee85faa353f0efe9c34aa23707b47764e5a0c6b4359dacf1a50b17f4e02db003455689d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- indocker (0.1.11)
4
+ indocker (0.1.12)
5
5
  net-ssh
6
6
 
7
7
  GEM
@@ -85,6 +85,7 @@ module Indocker
85
85
  autoload :IndockerHelper, 'indocker_helper'
86
86
  autoload :ImagesCompiler, 'images_compiler'
87
87
  autoload :ContainerRunner, 'container_runner'
88
+ autoload :SshResultLogger, 'ssh_result_logger'
88
89
  autoload :DeploymentProgress, 'deployment_progress'
89
90
  autoload :DeploymentChecker, 'deployment_checker'
90
91
  autoload :DeploymentPolicy, 'deployment_policy'
@@ -3,11 +3,12 @@ require 'fileutils'
3
3
  class Indocker::BuildContext
4
4
  attr_reader :session, :server, :configuration, :helper, :logger
5
5
 
6
- def initialize(configuration:, build_server:, logger:)
6
+ def initialize(configuration:, build_server:, logger:, global_logger:)
7
7
  @configuration = configuration
8
8
  @logger = logger
9
9
  @helper = Indocker::BuildContextHelper.new(@configuration, @build_server)
10
10
  @server = build_server
11
+ @global_logger = global_logger
11
12
  @compiled_images = Hash.new(false)
12
13
  end
13
14
 
@@ -72,8 +73,8 @@ class Indocker::BuildContext
72
73
  res = Indocker::Docker.build(image.local_registry_url, build_args)
73
74
 
74
75
  if res.exit_status != 0
75
- puts "image compilation :#{image.name} failed"
76
- puts res.stdout
76
+ @global_logger.error("image compilation :#{image.name} failed")
77
+ @global_logger.error(res.stdout)
77
78
  exit 1
78
79
  end
79
80
 
@@ -1,13 +1,15 @@
1
1
  class Indocker::BuildContextPool
2
- def initialize(configuration:, logger:)
2
+ def initialize(configuration:, logger:, global_logger:)
3
3
  @logger = logger
4
4
  @configuration = configuration
5
+ @global_logger = global_logger
5
6
 
6
7
  @contexts = configuration.build_servers.map do |build_server|
7
8
  Indocker::BuildContext.new(
8
9
  logger: @logger,
9
10
  configuration: configuration,
10
- build_server: build_server
11
+ build_server: build_server,
12
+ global_logger: @global_logger,
11
13
  )
12
14
  end
13
15
  end
@@ -46,7 +46,7 @@ class Indocker::ConfigurationDeployer
46
46
  containers = find_containers_to_deploy(configuration, deployment_policy)
47
47
 
48
48
  clonner = Indocker::Repositories::Clonner.new(configuration, @logger)
49
- build_context_pool = Indocker::BuildContextPool.new(configuration: configuration, logger: @logger)
49
+ build_context_pool = Indocker::BuildContextPool.new(configuration: configuration, logger: @logger, global_logger: @global_logger)
50
50
  deployer = Indocker::ContainerDeployer.new(configuration: configuration, logger: @logger)
51
51
 
52
52
  @global_logger.info("Establishing ssh sessions to all servers...")
@@ -290,21 +290,15 @@ class Indocker::ConfigurationDeployer
290
290
  result = build_context
291
291
  .session
292
292
  .exec!(
293
- "cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/compile -C #{Indocker.configuration_name} -i #{image.name} -s #{@logger.debug? ? '-d' : ''}",
294
- on_stdout: proc { |data|
295
- @logger.info("[compile] #{data}")
296
- },
297
- on_stderr: proc { |data|
298
- @logger.error("[compile] #{data}")
299
- }
293
+ "cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/compile -C #{Indocker.configuration_name} -i #{image.name} -s #{@logger.debug? ? '-d' : ''}"
300
294
  )
301
295
  end
302
296
 
303
- if result.exit_code != 0
304
- @global_logger.error("[compile] #{image.name.to_s.green} image compilation failed")
305
- puts result.stdout_data
306
- exit 1
307
- end
297
+ Indocker::SshResultLogger
298
+ .new(@logger)
299
+ .log(result, "#{image.name.to_s.green} image compilation failed")
300
+
301
+ exit 1 if result.exit_code != 0
308
302
 
309
303
  @logger.info("Image compilation completed #{image.name.to_s.green}. Time taken: #{time}")
310
304
 
@@ -50,21 +50,14 @@ class Indocker::ContainerDeployer
50
50
  result = deploy_context
51
51
  .session
52
52
  .exec!(
53
- "cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/run -C #{Indocker.configuration_name} -c #{container.name} #{debug_options} #{command_output} #{force_restart_options}",
54
- on_stdout: proc { |data|
55
- @logger.info("[deploy] #{data}")
56
- },
57
- on_stderr: proc { |data|
58
- @logger.error("[deploy] #{data}")
59
- }
53
+ "cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/run -C #{Indocker.configuration_name} -c #{container.name} #{debug_options} #{command_output} #{force_restart_options}"
60
54
  )
61
-
62
- if result.exit_code != 0
63
- @global_logger.error("[deploy] #{container.name.to_s.green} deployment for server #{server.name} failed")
64
- puts result.stdout_data
65
- exit 1
66
- end
67
55
 
56
+ Indocker::SshResultLogger
57
+ .new(@logger)
58
+ .log(result, "#{container.name.to_s.green} deployment for server #{server.name} failed")
59
+
60
+ exit 1 if result.exit_code != 0
68
61
  @logger.info("Container deployment to #{server.user}@#{server.host} finished: #{container.name.to_s.green}")
69
62
 
70
63
  deploy_context.close_session
@@ -9,7 +9,8 @@ class Indocker::ImagesCompiler
9
9
  build_context = Indocker::BuildContext.new(
10
10
  configuration: configuration,
11
11
  build_server: nil,
12
- logger: @logger
12
+ logger: @logger,
13
+ global_logger: Indocker.global_logger
13
14
  )
14
15
 
15
16
  image_compiler = Indocker::Images::ImageCompiler.new
@@ -0,0 +1,18 @@
1
+ class Indocker::SshResultLogger
2
+ def initialize(logger)
3
+ @logger = logger
4
+ end
5
+
6
+ def log(result, error_message)
7
+ if result.exit_code == 0
8
+ puts result.stdout_data
9
+ else
10
+ @logger.error(error_message)
11
+ puts result.stdout_data
12
+
13
+ result.stderr_data.to_s.split("\n").each do |line|
14
+ @logger.error(line)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -37,11 +37,11 @@ class Indocker::SshSession
37
37
  !@ssh
38
38
  end
39
39
 
40
- def exec!(command, on_stdout: nil, on_stderr: nil)
40
+ def exec!(command)
41
41
  if local?
42
42
  exec_locally!(command)
43
43
  else
44
- exec_remotely!(command, on_stdout: on_stdout, on_stderr: on_stderr)
44
+ exec_remotely!(command)
45
45
  end
46
46
  end
47
47
 
@@ -57,7 +57,7 @@ class Indocker::SshSession
57
57
  ExecResult.new(res.stdout, '', res.exit_status, nil)
58
58
  end
59
59
 
60
- def exec_remotely!(command, on_stdout:, on_stderr:)
60
+ def exec_remotely!(command)
61
61
  if Indocker.export_command
62
62
  command = "#{Indocker.export_command} && #{command}"
63
63
  end
@@ -78,12 +78,10 @@ class Indocker::SshSession
78
78
 
79
79
  channel.on_data do |ch,data|
80
80
  stdout_data += data
81
- on_stdout.call(data) if on_stdout
82
81
  end
83
82
 
84
83
  channel.on_extended_data do |ch,type,data|
85
84
  stderr_data += data
86
- on_stderr.call(data) if on_stderr
87
85
  end
88
86
 
89
87
  channel.on_request('exit-status') do |ch,data|
@@ -1,3 +1,3 @@
1
1
  module Indocker
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
@@ -163,6 +163,7 @@ files:
163
163
  - lib/indocker/server.rb
164
164
  - lib/indocker/server_pool.rb
165
165
  - lib/indocker/shell.rb
166
+ - lib/indocker/ssh_result_logger.rb
166
167
  - lib/indocker/ssh_session.rb
167
168
  - lib/indocker/version.rb
168
169
  - lib/indocker/volume_helper.rb