indocker 0.1.6 → 0.1.11
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 +4 -4
- data/Gemfile +5 -0
- data/Gemfile.lock +10 -4
- data/README.md +13 -2
- data/example/indocker/bin/deploy +19 -13
- data/example/indocker/bounded_contexts/shared/bad_container_build/Dockerfile +3 -0
- data/example/indocker/bounded_contexts/shared/bad_container_build/container.rb +5 -0
- data/example/indocker/bounded_contexts/shared/bad_container_build/image.rb +3 -0
- data/example/indocker/bounded_contexts/shared/bad_container_start/Dockerfile +8 -0
- data/example/indocker/bounded_contexts/shared/bad_container_start/build_context/bin/run +3 -0
- data/example/indocker/bounded_contexts/shared/bad_container_start/container.rb +5 -0
- data/example/indocker/bounded_contexts/shared/bad_container_start/image.rb +3 -0
- data/example/indocker/bounded_contexts/shared/good_container/Dockerfile +4 -0
- data/example/indocker/bounded_contexts/shared/good_container/container.rb +5 -0
- data/example/indocker/bounded_contexts/shared/good_container/image.rb +3 -0
- data/example/indocker/configurations/external.rb +18 -0
- data/example/indocker/infrastructure/build_servers.rb +11 -0
- data/example/indocker/infrastructure/servers.rb +11 -0
- data/example/indocker/setup.rb +1 -1
- data/example/spec/indocker_spec.rb +39 -0
- data/example/spec/spec_helper.rb +39 -0
- data/indocker.gemspec +1 -1
- data/lib/indocker.rb +37 -57
- data/lib/indocker/build_context.rb +13 -12
- data/lib/indocker/build_context_pool.rb +5 -1
- data/lib/indocker/configuration_deployer.rb +125 -93
- data/lib/indocker/container_deployer.rb +17 -7
- data/lib/indocker/context_args.rb +2 -0
- data/lib/indocker/deploy_context.rb +10 -8
- data/lib/indocker/deployment_policy.rb +22 -0
- data/lib/indocker/deployment_progress.rb +7 -2
- data/lib/indocker/images_compiler.rb +1 -1
- data/lib/indocker/logger_factory.rb +37 -0
- data/lib/indocker/server_pool.rb +9 -1
- data/lib/indocker/ssh_session.rb +21 -10
- data/lib/indocker/version.rb +1 -1
- metadata +19 -5
- data/lib/indocker/ssh_result_logger.rb +0 -18
@@ -16,6 +16,8 @@ class Indocker::ContextArgs
|
|
16
16
|
value = @context_args.fetch(name) do
|
17
17
|
Indocker.logger.warn("build arg '#{format_arg(name)}' is not defined#{@container ? " for container :#{@container.name}" : ""}")
|
18
18
|
Indocker.logger.warn("available args: #{@context_args.inspect}")
|
19
|
+
|
20
|
+
nil
|
19
21
|
end
|
20
22
|
|
21
23
|
if value.is_a?(Hash)
|
@@ -9,15 +9,17 @@ class Indocker::DeployContext
|
|
9
9
|
@configuration = configuration
|
10
10
|
@server = server
|
11
11
|
@restart_policy = Indocker::Containers::RestartPolicy.new(configuration, logger)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def create_session!
|
15
|
+
return unless @server
|
16
|
+
|
17
|
+
@session = Indocker::SshSession.new(
|
18
|
+
host: @server.host,
|
19
|
+
user: @server.user,
|
20
|
+
port: @server.port,
|
21
|
+
logger: @logger
|
22
|
+
)
|
21
23
|
end
|
22
24
|
|
23
25
|
def exec!(command)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Indocker::DeploymentPolicy
|
2
|
+
attr_reader :deploy_containers, :deploy_tags, :servers,
|
3
|
+
:skip_dependent, :skip_tags, :skip_containers, :skip_build, :skip_deploy,
|
4
|
+
:force_restart, :skip_force_restart, :auto_confirm, :require_confirmation
|
5
|
+
|
6
|
+
def initialize(deploy_containers:, deploy_tags:, servers:,
|
7
|
+
skip_dependent:, skip_tags:, skip_containers:, skip_build:, skip_deploy:,
|
8
|
+
force_restart:, skip_force_restart:, auto_confirm:, require_confirmation:)
|
9
|
+
@deploy_containers = deploy_containers
|
10
|
+
@deploy_tags = deploy_tags
|
11
|
+
@servers = servers
|
12
|
+
@skip_dependent = skip_dependent
|
13
|
+
@skip_tags = skip_tags
|
14
|
+
@skip_containers = skip_containers
|
15
|
+
@skip_build = skip_build
|
16
|
+
@skip_deploy = skip_deploy
|
17
|
+
@force_restart = force_restart
|
18
|
+
@skip_force_restart = skip_force_restart
|
19
|
+
@auto_confirm = auto_confirm
|
20
|
+
@require_confirmation = require_confirmation
|
21
|
+
end
|
22
|
+
end
|
@@ -70,9 +70,10 @@ class Indocker::DeploymentProgress
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def setup(binaries_servers:, build_servers:, deploy_servers:, env_files:, artifact_servers:,
|
73
|
-
repositories:, force_restart:, skip_build:, containers:)
|
73
|
+
repositories:, force_restart:, skip_build:, skip_deploy:, containers:)
|
74
74
|
@force_restart = force_restart
|
75
|
-
@skip_build
|
75
|
+
@skip_build = skip_build
|
76
|
+
@skip_deploy = skip_deploy
|
76
77
|
|
77
78
|
binaries_servers.each do |server|
|
78
79
|
@synced_binaries[server] = {
|
@@ -250,6 +251,10 @@ class Indocker::DeploymentProgress
|
|
250
251
|
@logger.info("Warning: Image build is skipped for all containers".purple)
|
251
252
|
end
|
252
253
|
|
254
|
+
if @skip_deploy
|
255
|
+
@logger.info("Warning: All container deployment is skipped".purple)
|
256
|
+
end
|
257
|
+
|
253
258
|
if @force_restart
|
254
259
|
@logger.info("Warning: All containers will be force restarted".purple)
|
255
260
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Indocker::LoggerFactory
|
2
|
+
class << self
|
3
|
+
def create(stdout, level = nil)
|
4
|
+
logger = Logger.new(stdout)
|
5
|
+
|
6
|
+
logger.level = level || Logger::INFO
|
7
|
+
|
8
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
9
|
+
level = Logger::SEV_LABEL.index(severity)
|
10
|
+
|
11
|
+
severity = case level
|
12
|
+
when Logger::INFO
|
13
|
+
severity.green
|
14
|
+
when Logger::WARN
|
15
|
+
severity.purple
|
16
|
+
when Logger::DEBUG
|
17
|
+
severity.yellow
|
18
|
+
when Logger::ERROR
|
19
|
+
severity.red
|
20
|
+
when Logger::FATAL
|
21
|
+
severity.red
|
22
|
+
else
|
23
|
+
severity
|
24
|
+
end
|
25
|
+
|
26
|
+
severity = severity.downcase
|
27
|
+
if logger.debug?
|
28
|
+
"#{datetime.strftime("%Y/%m/%d %H:%M:%S")} #{severity}: #{msg}\n"
|
29
|
+
else
|
30
|
+
" #{severity}: #{msg}\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
logger
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/indocker/server_pool.rb
CHANGED
@@ -12,12 +12,20 @@ class Indocker::ServerPool
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def create_sessions!
|
16
|
+
@contexts.each(&:create_session!)
|
17
|
+
end
|
18
|
+
|
19
|
+
# NOTE: get is a bad name here, because we create a new connection.
|
20
|
+
# TODO: why we create a new connection here?
|
15
21
|
def get(server)
|
16
|
-
Indocker::DeployContext.new(
|
22
|
+
context = Indocker::DeployContext.new(
|
17
23
|
logger: @logger,
|
18
24
|
configuration: @configuration,
|
19
25
|
server: server,
|
20
26
|
)
|
27
|
+
context.create_session!
|
28
|
+
context
|
21
29
|
end
|
22
30
|
|
23
31
|
def each(&proc)
|
data/lib/indocker/ssh_session.rb
CHANGED
@@ -37,11 +37,27 @@ class Indocker::SshSession
|
|
37
37
|
!@ssh
|
38
38
|
end
|
39
39
|
|
40
|
-
def exec!(command)
|
41
|
-
if
|
40
|
+
def exec!(command, on_stdout: nil, on_stderr: nil)
|
41
|
+
if local?
|
42
|
+
exec_locally!(command)
|
43
|
+
else
|
44
|
+
exec_remotely!(command, on_stdout: on_stdout, on_stderr: on_stderr)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def close
|
49
|
+
if @ssh
|
50
|
+
@ssh.close
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def exec_locally!(command)
|
42
56
|
res = Indocker::Shell.command_with_result(command, @logger, skip_logging: false)
|
43
57
|
ExecResult.new(res.stdout, '', res.exit_status, nil)
|
44
|
-
|
58
|
+
end
|
59
|
+
|
60
|
+
def exec_remotely!(command, on_stdout:, on_stderr:)
|
45
61
|
if Indocker.export_command
|
46
62
|
command = "#{Indocker.export_command} && #{command}"
|
47
63
|
end
|
@@ -62,10 +78,12 @@ class Indocker::SshSession
|
|
62
78
|
|
63
79
|
channel.on_data do |ch,data|
|
64
80
|
stdout_data += data
|
81
|
+
on_stdout.call(data) if on_stdout
|
65
82
|
end
|
66
83
|
|
67
84
|
channel.on_extended_data do |ch,type,data|
|
68
85
|
stderr_data += data
|
86
|
+
on_stderr.call(data) if on_stderr
|
69
87
|
end
|
70
88
|
|
71
89
|
channel.on_request('exit-status') do |ch,data|
|
@@ -82,11 +100,4 @@ class Indocker::SshSession
|
|
82
100
|
|
83
101
|
ExecResult.new(stdout_data, stderr_data, exit_code, exit_signal)
|
84
102
|
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def close
|
88
|
-
if @ssh
|
89
|
-
@ssh.close
|
90
|
-
end
|
91
|
-
end
|
92
103
|
end
|
data/lib/indocker/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 12.3.3
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 12.3.3
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,15 +88,28 @@ files:
|
|
88
88
|
- example/indocker/bin/remote/compile
|
89
89
|
- example/indocker/bin/remote/run
|
90
90
|
- example/indocker/bin/utils/configurations.rb
|
91
|
+
- example/indocker/bounded_contexts/shared/bad_container_build/Dockerfile
|
92
|
+
- example/indocker/bounded_contexts/shared/bad_container_build/container.rb
|
93
|
+
- example/indocker/bounded_contexts/shared/bad_container_build/image.rb
|
94
|
+
- example/indocker/bounded_contexts/shared/bad_container_start/Dockerfile
|
95
|
+
- example/indocker/bounded_contexts/shared/bad_container_start/build_context/bin/run
|
96
|
+
- example/indocker/bounded_contexts/shared/bad_container_start/container.rb
|
97
|
+
- example/indocker/bounded_contexts/shared/bad_container_start/image.rb
|
98
|
+
- example/indocker/bounded_contexts/shared/good_container/Dockerfile
|
99
|
+
- example/indocker/bounded_contexts/shared/good_container/container.rb
|
100
|
+
- example/indocker/bounded_contexts/shared/good_container/image.rb
|
91
101
|
- example/indocker/bounded_contexts/shared/ruby/Dockerfile
|
92
102
|
- example/indocker/bounded_contexts/shared/ruby/container.rb
|
93
103
|
- example/indocker/bounded_contexts/shared/ruby/image.rb
|
94
104
|
- example/indocker/configurations/dev.rb
|
105
|
+
- example/indocker/configurations/external.rb
|
95
106
|
- example/indocker/infrastructure/build_servers.rb
|
96
107
|
- example/indocker/infrastructure/networks.rb
|
97
108
|
- example/indocker/infrastructure/registries.rb
|
98
109
|
- example/indocker/infrastructure/servers.rb
|
99
110
|
- example/indocker/setup.rb
|
111
|
+
- example/spec/indocker_spec.rb
|
112
|
+
- example/spec/spec_helper.rb
|
100
113
|
- indocker.gemspec
|
101
114
|
- lib/indocker.rb
|
102
115
|
- lib/indocker/artifacts/git.rb
|
@@ -120,6 +133,7 @@ files:
|
|
120
133
|
- lib/indocker/crontab_redeploy_rules_builder.rb
|
121
134
|
- lib/indocker/deploy_context.rb
|
122
135
|
- lib/indocker/deployment_checker.rb
|
136
|
+
- lib/indocker/deployment_policy.rb
|
123
137
|
- lib/indocker/deployment_progress.rb
|
124
138
|
- lib/indocker/docker.rb
|
125
139
|
- lib/indocker/docker_run_args.rb
|
@@ -134,6 +148,7 @@ files:
|
|
134
148
|
- lib/indocker/images/templates_compiler.rb
|
135
149
|
- lib/indocker/images_compiler.rb
|
136
150
|
- lib/indocker/indocker_helper.rb
|
151
|
+
- lib/indocker/logger_factory.rb
|
137
152
|
- lib/indocker/network.rb
|
138
153
|
- lib/indocker/network_helper.rb
|
139
154
|
- lib/indocker/registries/abstract.rb
|
@@ -148,7 +163,6 @@ files:
|
|
148
163
|
- lib/indocker/server.rb
|
149
164
|
- lib/indocker/server_pool.rb
|
150
165
|
- lib/indocker/shell.rb
|
151
|
-
- lib/indocker/ssh_result_logger.rb
|
152
166
|
- lib/indocker/ssh_session.rb
|
153
167
|
- lib/indocker/version.rb
|
154
168
|
- lib/indocker/volume_helper.rb
|
@@ -1,18 +0,0 @@
|
|
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
|