indocker 0.1.12 → 0.1.17

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +8 -2
  5. data/example/indocker/bin/deploy +3 -6
  6. data/example/indocker/bin/remote/compile +2 -6
  7. data/example/indocker/bin/remote/run +2 -6
  8. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/Dockerfile +0 -0
  9. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/container.rb +2 -1
  10. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/image.rb +0 -0
  11. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/Dockerfile +0 -0
  12. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/build_context/bin/run +0 -0
  13. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/container.rb +2 -1
  14. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/image.rb +0 -0
  15. data/example/indocker/bounded_contexts/good_containers/daemon_container/Dockerfile +1 -0
  16. data/example/indocker/bounded_contexts/good_containers/daemon_container/container.rb +6 -0
  17. data/example/indocker/bounded_contexts/good_containers/daemon_container/image.rb +4 -0
  18. data/example/indocker/bounded_contexts/good_containers/dependency_container/Dockerfile +1 -0
  19. data/example/indocker/bounded_contexts/good_containers/dependency_container/container.rb +6 -0
  20. data/example/indocker/bounded_contexts/good_containers/dependency_container/image.rb +4 -0
  21. data/example/indocker/bounded_contexts/good_containers/good_container/Dockerfile +3 -0
  22. data/example/indocker/bounded_contexts/good_containers/good_container/build_context/example_file.txt +2 -0
  23. data/example/indocker/bounded_contexts/good_containers/good_container/container.rb +10 -0
  24. data/example/indocker/bounded_contexts/good_containers/good_container/image.rb +4 -0
  25. data/example/indocker/bounded_contexts/shared/{good_container → parent_image}/Dockerfile +1 -1
  26. data/example/indocker/bounded_contexts/shared/parent_image/image.rb +3 -0
  27. data/example/indocker/bounded_contexts/shared/ruby/container.rb +2 -1
  28. data/example/indocker/configurations/external.rb +11 -1
  29. data/example/indocker/env_files/development_env.env +1 -0
  30. data/example/indocker/infrastructure/artifacts.rb +26 -0
  31. data/example/indocker/infrastructure/env_files.rb +6 -0
  32. data/example/indocker/setup.rb +3 -1
  33. data/indocker.gemspec +1 -0
  34. data/lib/indocker.rb +42 -20
  35. data/lib/indocker/artifacts/base.rb +26 -0
  36. data/lib/indocker/artifacts/dto/file_dto.rb +8 -0
  37. data/lib/indocker/artifacts/git.rb +17 -5
  38. data/lib/indocker/artifacts/remote.rb +17 -0
  39. data/lib/indocker/artifacts/services/synchronizer.rb +59 -0
  40. data/lib/indocker/build_context.rb +6 -41
  41. data/lib/indocker/build_context_helper.rb +1 -1
  42. data/lib/indocker/container_deployer.rb +12 -23
  43. data/lib/indocker/crontab_redeploy_rules_builder.rb +6 -6
  44. data/lib/indocker/deploy_context.rb +4 -32
  45. data/lib/indocker/deployment_checker.rb +4 -2
  46. data/lib/indocker/docker_run_args.rb +2 -2
  47. data/lib/indocker/images/image_compiler.rb +0 -1
  48. data/lib/indocker/{configuration_deployer.rb → launchers/configuration_deployer.rb} +66 -113
  49. data/lib/indocker/{container_runner.rb → launchers/container_runner.rb} +2 -3
  50. data/lib/indocker/launchers/dto/remote_operation_dto.rb +10 -0
  51. data/lib/indocker/{images_compiler.rb → launchers/images_compiler.rb} +1 -2
  52. data/lib/indocker/{network.rb → networks/network.rb} +1 -1
  53. data/lib/indocker/{network_helper.rb → networks/network_helper.rb} +1 -1
  54. data/lib/indocker/repositories/cloner.rb +73 -0
  55. data/lib/indocker/server_pools/build_server_connection.rb +15 -0
  56. data/lib/indocker/server_pools/build_server_pool.rb +40 -0
  57. data/lib/indocker/server_pools/deploy_server_connection.rb +17 -0
  58. data/lib/indocker/server_pools/deploy_server_pool.rb +41 -0
  59. data/lib/indocker/server_pools/server_connection.rb +37 -0
  60. data/lib/indocker/version.rb +1 -1
  61. data/lib/indocker/{volume_helper.rb → volumes/volume_helper.rb} +1 -1
  62. metadata +56 -24
  63. data/example/indocker/bounded_contexts/shared/good_container/container.rb +0 -5
  64. data/example/indocker/bounded_contexts/shared/good_container/image.rb +0 -3
  65. data/example/spec/indocker_spec.rb +0 -39
  66. data/example/spec/spec_helper.rb +0 -39
  67. data/lib/indocker/build_context_pool.rb +0 -42
  68. data/lib/indocker/configurations/formatters/stdout.rb +0 -36
  69. data/lib/indocker/repositories/clonner.rb +0 -17
  70. data/lib/indocker/server_pool.rb +0 -38
@@ -1,4 +1,4 @@
1
- class Indocker::ContainerRunner
1
+ class Indocker::Launchers::ContainerRunner
2
2
  def initialize(logger)
3
3
  @logger = logger
4
4
  end
@@ -13,8 +13,7 @@ class Indocker::ContainerRunner
13
13
 
14
14
  deploy_context = Indocker::DeployContext.new(
15
15
  logger: @logger,
16
- configuration: configuration,
17
- server: nil
16
+ configuration: configuration
18
17
  )
19
18
 
20
19
  container = configuration.containers.detect { |c| c.name == container_name }
@@ -0,0 +1,10 @@
1
+ class Indocker::Launchers::DTO::RemoteOperationDTO
2
+ attr_reader :thread, :server, :operation, :message
3
+
4
+ def initialize(thread, server, operation, message = nil)
5
+ @thread = thread
6
+ @server = server
7
+ @operation = operation
8
+ @message = message
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
- class Indocker::ImagesCompiler
1
+ class Indocker::Launchers::ImagesCompiler
2
2
  def initialize(logger)
3
3
  @logger = logger
4
4
  end
@@ -8,7 +8,6 @@ class Indocker::ImagesCompiler
8
8
 
9
9
  build_context = Indocker::BuildContext.new(
10
10
  configuration: configuration,
11
- build_server: nil,
12
11
  logger: @logger,
13
12
  global_logger: Indocker.global_logger
14
13
  )
@@ -1,4 +1,4 @@
1
- class Indocker::Network
1
+ class Indocker::Networks::Network
2
2
  attr_reader :name, :containers
3
3
 
4
4
  def initialize(name)
@@ -1,4 +1,4 @@
1
- class Indocker::NetworkHelper
1
+ class Indocker::Networks::NetworkHelper
2
2
  class << self
3
3
  def name(configuration_name, network)
4
4
  "#{configuration_name}_#{network.name}"
@@ -0,0 +1,73 @@
1
+ require 'net/ssh'
2
+
3
+ class Indocker::Repositories::Cloner
4
+ def initialize(configuration, logger)
5
+ @configuration = configuration
6
+ @logger = logger
7
+ end
8
+
9
+ def clone(session, repository)
10
+ raise ArgumenError.new("only git repositories should be cloned") if !repository.is_git?
11
+
12
+ already_cloned = repository_already_cloned?(
13
+ session: session,
14
+ target_path: repository.clone_path,
15
+ remote_url: repository.remote_url,
16
+ )
17
+
18
+ git_command = if already_cloned
19
+ build_force_pull_command(
20
+ target_path: repository.clone_path,
21
+ branch_name: repository.branch,
22
+ )
23
+ else
24
+ build_clone_command(
25
+ target_path: repository.clone_path,
26
+ branch_name: repository.branch,
27
+ remote_url: repository.remote_url,
28
+ )
29
+ end
30
+
31
+ session.exec!("ssh-agent bash -c 'ssh-add ~/.ssh/#{repository.ssh_key}; #{git_command}'")
32
+ end
33
+
34
+ private
35
+
36
+ def repository_already_cloned?(session:, target_path:, remote_url:)
37
+ target_remote_url = session.exec!(
38
+ build_git_remote_url_command(
39
+ path: target_path
40
+ )
41
+ ).stdout_data.chomp
42
+
43
+ @logger.debug("target remote_url: #{target_remote_url.inspect}, checked remote_url: #{remote_url.inspect}")
44
+
45
+ target_remote_url == remote_url
46
+ end
47
+
48
+ def build_git_remote_url_command(path:)
49
+ [
50
+ "mkdir -p #{path}",
51
+ "cd #{path}",
52
+ "git config --get remote.origin.url",
53
+ ].join(" && ")
54
+ end
55
+
56
+ def build_clone_command(target_path:, branch_name:, remote_url:)
57
+ [
58
+ "rm -rf #{target_path}",
59
+ "mkdir -p #{target_path}",
60
+ "git clone -b #{branch_name} --depth 1 #{remote_url} #{target_path}",
61
+ ].join(" && ")
62
+ end
63
+
64
+ def build_force_pull_command(target_path:, branch_name:)
65
+ [
66
+ "cd #{target_path}",
67
+ "git add .",
68
+ "git reset HEAD --hard",
69
+ "git checkout #{branch_name}",
70
+ "git pull --force",
71
+ ].join(" && ")
72
+ end
73
+ end
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+
3
+ class Indocker::ServerPools::BuildServerConnection < Indocker::ServerPools::ServerConnection
4
+ def compile_image_remotely(configuration_name:, image_name:)
5
+ result = exec!(
6
+ "cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/compile -C #{configuration_name} -i #{image_name} -s #{@logger.debug? ? '-d' : ''}"
7
+ )
8
+
9
+ Indocker::SshResultLogger
10
+ .new(@logger)
11
+ .log(result, "#{image_name.to_s.green} image compilation failed")
12
+
13
+ result
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ class Indocker::ServerPools::BuildServerPool
2
+ def initialize(configuration:, logger:)
3
+ @logger = logger
4
+ @configuration = configuration
5
+
6
+ @connections = configuration.build_servers.map do |build_server|
7
+ Indocker::ServerPools::BuildServerConnection.new(
8
+ logger: @logger,
9
+ configuration: configuration,
10
+ server: build_server,
11
+ )
12
+ end
13
+ end
14
+
15
+ def create_sessions!
16
+ @connections.each(&:create_session!)
17
+ end
18
+
19
+ def get
20
+ context = nil
21
+
22
+ loop do
23
+ context = @connections.detect {|c| !c.busy?}
24
+ sleep(0.1)
25
+ break if context
26
+ end
27
+
28
+ context
29
+ end
30
+
31
+ def each(&proc)
32
+ @connections.each(&proc)
33
+ end
34
+
35
+ def close_sessions
36
+ @connections.each(&:close_session)
37
+ rescue => e
38
+ @logger.error("error during session close: #{e.inspect}")
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ class Indocker::ServerPools::DeployServerConnection < Indocker::ServerPools::ServerConnection
2
+ def run_container_remotely(configuration_name:, container_name:, force_restart:)
3
+ command_output = @logger.debug? ? "" : " > /dev/null"
4
+ debug_options = @logger.debug? ? "-d" : ""
5
+ force_restart_options = force_restart ? "-f" : ""
6
+
7
+ result = exec!(
8
+ "cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/run -C #{configuration_name} -c #{container_name} #{debug_options} #{command_output} #{force_restart_options}"
9
+ )
10
+
11
+ Indocker::SshResultLogger
12
+ .new(@logger)
13
+ .log(result, "#{container_name.to_s.green} deployment for server #{server.name} failed")
14
+
15
+ result
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ class Indocker::ServerPools::DeployServerPool
2
+ def initialize(configuration:, logger:)
3
+ @logger = logger
4
+ @configuration = configuration
5
+ @connections = []
6
+ @semaphore = Mutex.new
7
+ end
8
+
9
+ def create_connection!(server)
10
+ connection = Indocker::ServerPools::DeployServerConnection.new(
11
+ logger: @logger,
12
+ configuration: @configuration,
13
+ server: server,
14
+ )
15
+ connection.create_session!
16
+ connection
17
+ end
18
+
19
+ def find_or_create_connection!(server)
20
+ @semaphore.synchronize do
21
+ connection = @connections.detect do |connection|
22
+ connection.server.host == server.host &&
23
+ connection.server.port == server.port &&
24
+ connection.server.user == server.user
25
+ end
26
+ if connection.nil?
27
+ connection = create_connection!(server)
28
+ @connections.push(connection)
29
+ end
30
+ connection
31
+ end
32
+ end
33
+
34
+ def each(&proc)
35
+ @connections.each(&proc)
36
+ end
37
+
38
+ def close_sessions
39
+ @connections.each(&:close_session)
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ class Indocker::ServerPools::ServerConnection
2
+ attr_reader :server, :session
3
+
4
+ def initialize(logger:, configuration:, server:)
5
+ @logger = logger
6
+ @configuration = configuration
7
+ @server = server
8
+ end
9
+
10
+ def create_session!
11
+ return unless @server
12
+
13
+ @session = Indocker::SshSession.new(
14
+ host: @server.host,
15
+ user: @server.user,
16
+ port: @server.port,
17
+ logger: @logger
18
+ )
19
+ end
20
+
21
+ def exec!(command)
22
+ @session.exec!(command)
23
+ end
24
+
25
+ def close_session
26
+ @session.close if @session
27
+ @session = nil
28
+ end
29
+
30
+ def set_busy(flag)
31
+ @busy = !!flag
32
+ end
33
+
34
+ def busy?
35
+ !!@busy
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Indocker
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.17"
3
3
  end
@@ -1,4 +1,4 @@
1
- class Indocker::VolumeHelper
1
+ class Indocker::Volumes::VolumeHelper
2
2
  class << self
3
3
  def name(configuration_name, volume)
4
4
  "#{configuration_name}_#{volume.name}"
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.12
4
+ version: 0.1.17
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-08-13 00:00:00.000000000 Z
12
+ date: 2020-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.18.5
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.18.5
70
84
  description: Docker Containers Deployment
71
85
  email:
72
86
  - gvalmon@gmail.com
@@ -76,6 +90,7 @@ extra_rdoc_files: []
76
90
  files:
77
91
  - ".gitignore"
78
92
  - ".rspec"
93
+ - ".ruby-version"
79
94
  - ".travis.yml"
80
95
  - Gemfile
81
96
  - Gemfile.lock
@@ -88,44 +103,54 @@ files:
88
103
  - example/indocker/bin/remote/compile
89
104
  - example/indocker/bin/remote/run
90
105
  - 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
106
+ - example/indocker/bounded_contexts/bad_containers/bad_container_build/Dockerfile
107
+ - example/indocker/bounded_contexts/bad_containers/bad_container_build/container.rb
108
+ - example/indocker/bounded_contexts/bad_containers/bad_container_build/image.rb
109
+ - example/indocker/bounded_contexts/bad_containers/bad_container_start/Dockerfile
110
+ - example/indocker/bounded_contexts/bad_containers/bad_container_start/build_context/bin/run
111
+ - example/indocker/bounded_contexts/bad_containers/bad_container_start/container.rb
112
+ - example/indocker/bounded_contexts/bad_containers/bad_container_start/image.rb
113
+ - example/indocker/bounded_contexts/good_containers/daemon_container/Dockerfile
114
+ - example/indocker/bounded_contexts/good_containers/daemon_container/container.rb
115
+ - example/indocker/bounded_contexts/good_containers/daemon_container/image.rb
116
+ - example/indocker/bounded_contexts/good_containers/dependency_container/Dockerfile
117
+ - example/indocker/bounded_contexts/good_containers/dependency_container/container.rb
118
+ - example/indocker/bounded_contexts/good_containers/dependency_container/image.rb
119
+ - example/indocker/bounded_contexts/good_containers/good_container/Dockerfile
120
+ - example/indocker/bounded_contexts/good_containers/good_container/build_context/example_file.txt
121
+ - example/indocker/bounded_contexts/good_containers/good_container/container.rb
122
+ - example/indocker/bounded_contexts/good_containers/good_container/image.rb
123
+ - example/indocker/bounded_contexts/shared/parent_image/Dockerfile
124
+ - example/indocker/bounded_contexts/shared/parent_image/image.rb
101
125
  - example/indocker/bounded_contexts/shared/ruby/Dockerfile
102
126
  - example/indocker/bounded_contexts/shared/ruby/container.rb
103
127
  - example/indocker/bounded_contexts/shared/ruby/image.rb
104
128
  - example/indocker/configurations/dev.rb
105
129
  - example/indocker/configurations/external.rb
130
+ - example/indocker/env_files/development_env.env
131
+ - example/indocker/infrastructure/artifacts.rb
106
132
  - example/indocker/infrastructure/build_servers.rb
133
+ - example/indocker/infrastructure/env_files.rb
107
134
  - example/indocker/infrastructure/networks.rb
108
135
  - example/indocker/infrastructure/registries.rb
109
136
  - example/indocker/infrastructure/servers.rb
110
137
  - example/indocker/setup.rb
111
- - example/spec/indocker_spec.rb
112
- - example/spec/spec_helper.rb
113
138
  - indocker.gemspec
114
139
  - lib/indocker.rb
140
+ - lib/indocker/artifacts/base.rb
141
+ - lib/indocker/artifacts/dto/file_dto.rb
115
142
  - lib/indocker/artifacts/git.rb
143
+ - lib/indocker/artifacts/remote.rb
144
+ - lib/indocker/artifacts/services/synchronizer.rb
116
145
  - lib/indocker/build_context.rb
117
146
  - lib/indocker/build_context_helper.rb
118
- - lib/indocker/build_context_pool.rb
119
147
  - lib/indocker/build_server.rb
120
148
  - lib/indocker/colored_string.rb
121
149
  - lib/indocker/concerns/inspectable.rb
122
- - lib/indocker/configuration_deployer.rb
123
150
  - lib/indocker/configurations/configuration.rb
124
151
  - lib/indocker/configurations/configuration_builder.rb
125
- - lib/indocker/configurations/formatters/stdout.rb
126
152
  - lib/indocker/container_deployer.rb
127
153
  - lib/indocker/container_helper.rb
128
- - lib/indocker/container_runner.rb
129
154
  - lib/indocker/containers/container.rb
130
155
  - lib/indocker/containers/container_builder.rb
131
156
  - lib/indocker/containers/restart_policy.rb
@@ -146,30 +171,37 @@ files:
146
171
  - lib/indocker/images/image_compiler.rb
147
172
  - lib/indocker/images/template_compiler.rb
148
173
  - lib/indocker/images/templates_compiler.rb
149
- - lib/indocker/images_compiler.rb
150
174
  - lib/indocker/indocker_helper.rb
175
+ - lib/indocker/launchers/configuration_deployer.rb
176
+ - lib/indocker/launchers/container_runner.rb
177
+ - lib/indocker/launchers/dto/remote_operation_dto.rb
178
+ - lib/indocker/launchers/images_compiler.rb
151
179
  - lib/indocker/logger_factory.rb
152
- - lib/indocker/network.rb
153
- - lib/indocker/network_helper.rb
180
+ - lib/indocker/networks/network.rb
181
+ - lib/indocker/networks/network_helper.rb
154
182
  - lib/indocker/registries/abstract.rb
155
183
  - lib/indocker/registries/local.rb
156
184
  - lib/indocker/registries/remote.rb
157
185
  - lib/indocker/repositories/abstract.rb
158
- - lib/indocker/repositories/clonner.rb
186
+ - lib/indocker/repositories/cloner.rb
159
187
  - lib/indocker/repositories/git.rb
160
188
  - lib/indocker/repositories/local.rb
161
189
  - lib/indocker/repositories/no_sync.rb
162
190
  - lib/indocker/rsync.rb
163
191
  - lib/indocker/server.rb
164
- - lib/indocker/server_pool.rb
192
+ - lib/indocker/server_pools/build_server_connection.rb
193
+ - lib/indocker/server_pools/build_server_pool.rb
194
+ - lib/indocker/server_pools/deploy_server_connection.rb
195
+ - lib/indocker/server_pools/deploy_server_pool.rb
196
+ - lib/indocker/server_pools/server_connection.rb
165
197
  - lib/indocker/shell.rb
166
198
  - lib/indocker/ssh_result_logger.rb
167
199
  - lib/indocker/ssh_session.rb
168
200
  - lib/indocker/version.rb
169
- - lib/indocker/volume_helper.rb
170
201
  - lib/indocker/volumes/external.rb
171
202
  - lib/indocker/volumes/local.rb
172
203
  - lib/indocker/volumes/repository.rb
204
+ - lib/indocker/volumes/volume_helper.rb
173
205
  homepage: https://github.com/ArtStation/indocker
174
206
  licenses:
175
207
  - MIT