indocker 0.1.16 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile.lock +17 -17
  4. data/example/indocker/bin/deploy +3 -6
  5. data/example/indocker/bin/remote/compile +2 -6
  6. data/example/indocker/bin/remote/run +2 -6
  7. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/Dockerfile +0 -0
  8. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/container.rb +0 -0
  9. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/image.rb +0 -0
  10. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/Dockerfile +0 -0
  11. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/build_context/bin/run +0 -0
  12. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/container.rb +0 -0
  13. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/image.rb +0 -0
  14. data/example/indocker/bounded_contexts/good_containers/daemon_container/Dockerfile +1 -0
  15. data/example/indocker/bounded_contexts/{shared → good_containers}/daemon_container/container.rb +0 -0
  16. data/example/indocker/bounded_contexts/good_containers/daemon_container/image.rb +4 -0
  17. data/example/indocker/bounded_contexts/good_containers/dependency_container/Dockerfile +1 -0
  18. data/example/indocker/bounded_contexts/good_containers/dependency_container/container.rb +6 -0
  19. data/example/indocker/bounded_contexts/good_containers/dependency_container/image.rb +4 -0
  20. data/example/indocker/bounded_contexts/good_containers/good_container/Dockerfile +3 -0
  21. data/example/indocker/bounded_contexts/good_containers/good_container/build_context/example_file.txt +2 -0
  22. data/example/indocker/bounded_contexts/{shared → good_containers}/good_container/container.rb +5 -1
  23. data/example/indocker/bounded_contexts/good_containers/good_container/image.rb +4 -0
  24. data/example/indocker/bounded_contexts/shared/{good_container → parent_image}/Dockerfile +1 -1
  25. data/example/indocker/bounded_contexts/shared/parent_image/image.rb +3 -0
  26. data/example/indocker/configurations/external.rb +5 -0
  27. data/example/indocker/env_files/development_env.env +1 -0
  28. data/example/indocker/infrastructure/artifacts.rb +18 -2
  29. data/example/indocker/infrastructure/env_files.rb +6 -0
  30. data/example/indocker/setup.rb +2 -1
  31. data/lib/indocker/artifacts/base.rb +26 -0
  32. data/lib/indocker/artifacts/dto/file_dto.rb +8 -0
  33. data/lib/indocker/artifacts/git.rb +17 -5
  34. data/lib/indocker/artifacts/remote.rb +17 -0
  35. data/lib/indocker/artifacts/services/synchronizer.rb +59 -0
  36. data/lib/indocker/build_context_helper.rb +1 -1
  37. data/lib/indocker/crontab_redeploy_rules_builder.rb +4 -5
  38. data/lib/indocker/launchers/configuration_deployer.rb +38 -82
  39. data/lib/indocker/launchers/dto/remote_operation_dto.rb +10 -0
  40. data/lib/indocker/repositories/cloner.rb +73 -0
  41. data/lib/indocker/version.rb +1 -1
  42. data/lib/indocker.rb +17 -7
  43. metadata +33 -21
  44. data/example/indocker/bounded_contexts/shared/daemon_container/Dockerfile +0 -4
  45. data/example/indocker/bounded_contexts/shared/daemon_container/image.rb +0 -3
  46. data/example/indocker/bounded_contexts/shared/good_container/image.rb +0 -3
  47. data/lib/indocker/configurations/formatters/stdout.rb +0 -36
  48. data/lib/indocker/repositories/clonner.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e93eba781605cba8bdb795ed40a03b16d3602508ca427639b42ead50c25b7ec6
4
- data.tar.gz: 3e5dc1f5582c8ee45fa4e3583cfea13abf3121e52341eecdc98b8660db700d94
3
+ metadata.gz: 8e526bf660134a83bdfca0bde3f3c55eabdd65048aaa9b5010f49e63c00bac36
4
+ data.tar.gz: 7ee83fa4d8784114390bc9abab7d29f5e9dbe24bde4573274f1dd6f95d627bf9
5
5
  SHA512:
6
- metadata.gz: 4da7e1049911e4d0c12d89d977cfb568687f61568866ec82f737694c1023984ad97d205d25eaa35e19ebc46843d0743d1df07c833c48d293a5c10ca5de0fd792
7
- data.tar.gz: 1a8205455ebf5da34c8039a87c45772807920e362e8814bee275ef578647a15edf9970a9c53196b5805aeba8d4b3b047e30e329b0637d393a390c9d32c68353f
6
+ metadata.gz: 5b3f95e27d372a330e370dd8bae0740e7ec3e04f354128c13189b8a4494fc6fdb06bebf5222f6ac95f79e30d08e3c37f69a54e1ee0000287f111366762ab68ac
7
+ data.tar.gz: c556959cdf2eca0ce5a2ce95dec99a0498c052eb64af113b50d14705562a3aa860e3d87755e56f473e3a60c70191f87f8c6a5870af9b126e921e8d871b754c03
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 3.1.2
data/Gemfile.lock CHANGED
@@ -1,38 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- indocker (0.1.16)
4
+ indocker (0.3.0)
5
5
  net-ssh
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  coderay (1.1.3)
11
- diff-lcs (1.3)
12
- docile (1.3.2)
11
+ diff-lcs (1.5.0)
12
+ docile (1.4.0)
13
13
  method_source (1.0.0)
14
- net-ssh (6.1.0)
15
- pry (0.13.1)
14
+ net-ssh (7.0.1)
15
+ pry (0.14.1)
16
16
  coderay (~> 1.1)
17
17
  method_source (~> 1.0)
18
18
  rake (12.3.3)
19
- rspec (3.9.0)
20
- rspec-core (~> 3.9.0)
21
- rspec-expectations (~> 3.9.0)
22
- rspec-mocks (~> 3.9.0)
23
- rspec-core (3.9.1)
24
- rspec-support (~> 3.9.1)
25
- rspec-expectations (3.9.0)
19
+ rspec (3.12.0)
20
+ rspec-core (~> 3.12.0)
21
+ rspec-expectations (~> 3.12.0)
22
+ rspec-mocks (~> 3.12.0)
23
+ rspec-core (3.12.0)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-expectations (3.12.0)
26
26
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.9.0)
28
- rspec-mocks (3.9.1)
27
+ rspec-support (~> 3.12.0)
28
+ rspec-mocks (3.12.0)
29
29
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.9.0)
31
- rspec-support (3.9.2)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-support (3.12.0)
32
32
  simplecov (0.18.5)
33
33
  docile (~> 1.1)
34
34
  simplecov-html (~> 0.11)
35
- simplecov-html (0.12.2)
35
+ simplecov-html (0.12.3)
36
36
 
37
37
  PLATFORMS
38
38
  ruby
@@ -94,12 +94,9 @@ if !configurations.include?(options[:configuration])
94
94
  exit 1
95
95
  end
96
96
 
97
- begin
98
- require 'indocker'
99
- rescue LoadError
100
- puts "InDocker has been moved into a separate gem. Please install using `gem install indocker`"
101
- exit
102
- end
97
+ require 'rubygems'
98
+ require 'bundler/setup'
99
+ require 'indocker'
103
100
 
104
101
  if options[:debug]
105
102
  Indocker.set_log_level(Logger::DEBUG)
@@ -49,12 +49,8 @@ if !options.has_key?(:images)
49
49
  puts "At least one image should be provided"
50
50
  end
51
51
 
52
- begin
53
- require 'indocker'
54
- rescue LoadError
55
- puts "InDocker has been moved into a separate gem. Please install using `gem install indocker`"
56
- exit 1
57
- end
52
+ require 'rubygems'
53
+ require 'indocker'
58
54
 
59
55
  if options[:debug]
60
56
  Indocker.set_log_level(Logger::DEBUG)
@@ -46,12 +46,8 @@ if !configurations.include?(options[:configuration])
46
46
  exit 1
47
47
  end
48
48
 
49
- begin
50
- require 'indocker'
51
- rescue LoadError
52
- puts "InDocker has been moved into a separate gem. Please install using `gem install indocker`"
53
- exit 1
54
- end
49
+ require 'rubygems'
50
+ require 'indocker'
55
51
 
56
52
  if options[:debug]
57
53
  Indocker.set_log_level(Logger::DEBUG)
@@ -0,0 +1 @@
1
+ FROM <%= image_url(:parent_image) %>
@@ -0,0 +1,4 @@
1
+ Indocker
2
+ .define_image(:daemon_container)
3
+ .depends_on(:parent_image)
4
+ .registry(:default)
@@ -0,0 +1 @@
1
+ FROM <%= image_url(:parent_image) %>
@@ -0,0 +1,6 @@
1
+ Indocker
2
+ .define_container(:dependency_container)
3
+ .tags('dependency_container', 'console=true')
4
+ .image(:dependency_container)
5
+ .networks(:app_net)
6
+ .daemonize(false)
@@ -0,0 +1,4 @@
1
+ Indocker
2
+ .define_image(:dependency_container)
3
+ .depends_on(:parent_image)
4
+ .registry(:default)
@@ -0,0 +1,3 @@
1
+ FROM <%= image_url(:parent_image) %>
2
+
3
+ COPY example_file.txt example_file.txt
@@ -0,0 +1,2 @@
1
+ domain: <%= global_build_args.domain %>
2
+ hostname: <%= containers.good_container.hostname %>
@@ -1,6 +1,10 @@
1
1
  Indocker
2
2
  .define_container(:good_container)
3
+ .depends_on(:dependency_container)
3
4
  .tags('good_container', 'console=true')
4
5
  .image(:good_container)
5
6
  .networks(:app_net)
6
- .daemonize(false)
7
+ .daemonize(false)
8
+ # .start({
9
+ # env_files: [:default_env],
10
+ # })
@@ -0,0 +1,4 @@
1
+ Indocker
2
+ .define_image(:good_container)
3
+ .depends_on(:parent_image)
4
+ .registry(:default)
@@ -1,4 +1,4 @@
1
1
  FROM ruby:2.5.0
2
2
 
3
3
  RUN mkdir /app
4
- WORKDIR /app
4
+ WORKDIR /app
@@ -0,0 +1,3 @@
1
+ Indocker
2
+ .define_image(:parent_image)
3
+ .registry(:default)
@@ -2,6 +2,10 @@ Indocker
2
2
  .build_configuration(:external)
3
3
  .use_registry(:dev, as: :default)
4
4
  .use_build_server(:external_bs)
5
+ .global_build_args({
6
+ domain: 'indocker.me',
7
+ })
8
+ .use_env_file(:development_env, as: :default_env)
5
9
  .enabled_containers(
6
10
  ruby: {
7
11
  servers: [:external],
@@ -20,4 +24,5 @@ Indocker
20
24
  }
21
25
  ).artifacts(
22
26
  indocker_readme: [:external],
27
+ hosts_file: [:external],
23
28
  )
@@ -0,0 +1 @@
1
+ PROJECT_NAME=indocker
@@ -4,7 +4,23 @@ Indocker.add_artifact(
4
4
  remote_name: 'origin',
5
5
  remote_url: 'https://github.com/ArtStation/indocker.git',
6
6
  branch: :master,
7
- source_path: './README.md',
8
- target_path: File.join(Indocker.deploy_dir, 'README.md'),
7
+ files: [
8
+ Indocker::Artifacts::DTO::FileDTO.new(
9
+ source_path: './README.md',
10
+ target_path: Indocker.deploy_dir,
11
+ )
12
+ ]
13
+ )
14
+ )
15
+
16
+ Indocker.add_artifact(
17
+ Indocker::Artifacts::Remote.new(
18
+ name: :hosts_file,
19
+ files: [
20
+ Indocker::Artifacts::DTO::FileDTO.new(
21
+ source_path: '/etc/hosts',
22
+ target_path: Indocker.deploy_dir,
23
+ )
24
+ ]
9
25
  )
10
26
  )
@@ -0,0 +1,6 @@
1
+ Indocker.define_env_file(
2
+ Indocker::EnvFiles::Local.new(
3
+ :development_env,
4
+ File.expand_path(File.join(__dir__, '../env_files/development_env.env'))
5
+ )
6
+ )
@@ -3,7 +3,7 @@ require 'indocker'
3
3
  root_dir = File.join(__dir__, '..', '..')
4
4
 
5
5
  Indocker.set_root_dir(__dir__)
6
- Indocker.set_deploy_dir('~/deployment')
6
+ Indocker.set_deploy_dir('~/.indocker-deployment')
7
7
 
8
8
  Indocker.set_dockerignore [
9
9
  'Dockerfile',
@@ -19,6 +19,7 @@ require_relative 'infrastructure/servers'
19
19
  require_relative 'infrastructure/build_servers'
20
20
  require_relative 'infrastructure/networks'
21
21
  require_relative 'infrastructure/artifacts'
22
+ require_relative 'infrastructure/env_files'
22
23
 
23
24
  Indocker.set_bounded_contexts_dir(File.join(__dir__, 'bounded_contexts'))
24
25
 
@@ -0,0 +1,26 @@
1
+ class Indocker::Artifacts::Base
2
+ def build_source_path(*args)
3
+ raise StandardError.new('not implemented')
4
+ end
5
+
6
+ def is_git?
7
+ false
8
+ end
9
+
10
+ private
11
+
12
+ def build_all_files(files: [], source_path: nil, target_path: nil)
13
+ all_files = files
14
+
15
+ if source_path && target_path
16
+ all_files.push(
17
+ Indocker::Artifacts::DTO::FileDTO.new(
18
+ source_path: source_path,
19
+ target_path: target_path,
20
+ )
21
+ )
22
+ end
23
+
24
+ all_files
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ class Indocker::Artifacts::DTO::FileDTO
2
+ attr_reader :source_path, :target_path
3
+
4
+ def initialize(source_path:, target_path:)
5
+ @source_path = source_path
6
+ @target_path = target_path
7
+ end
8
+ end
@@ -1,13 +1,17 @@
1
- class Indocker::Artifacts::Git
2
- attr_reader :name, :remote_name, :remote_url, :branch, :source_path, :target_path
1
+ class Indocker::Artifacts::Git < Indocker::Artifacts::Base
2
+ attr_reader :name, :remote_name, :remote_url, :branch, :files
3
3
 
4
- def initialize(name:, remote_name:, remote_url:, branch:, source_path:, target_path:)
4
+ def initialize(name:, remote_name:, remote_url:, branch:, files: [], source_path: nil, target_path: nil)
5
5
  @name = name
6
6
  @remote_name = remote_name
7
7
  @remote_url = remote_url
8
8
  @branch = branch
9
- @source_path = source_path
10
- @target_path = target_path
9
+
10
+ @files = build_all_files(
11
+ files: files,
12
+ source_path: source_path,
13
+ target_path: target_path,
14
+ )
11
15
  end
12
16
 
13
17
  def repository
@@ -22,4 +26,12 @@ class Indocker::Artifacts::Git
22
26
  def project_name(url)
23
27
  url.split('/').last.gsub('.git', '')
24
28
  end
29
+
30
+ def is_git?
31
+ true
32
+ end
33
+
34
+ def build_source_path(path)
35
+ File.join(self.repository.clone_path, path)
36
+ end
25
37
  end
@@ -0,0 +1,17 @@
1
+ class Indocker::Artifacts::Remote < Indocker::Artifacts::Base
2
+ attr_reader :name, :files
3
+
4
+ def initialize(name:, files: [], source_path: nil, target_path: nil)
5
+ @name = name
6
+
7
+ @files = build_all_files(
8
+ files: files,
9
+ source_path: source_path,
10
+ target_path: target_path,
11
+ )
12
+ end
13
+
14
+ def build_source_path(path)
15
+ path
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ class Indocker::Artifacts::Services::Synchronizer
2
+ def initialize(logger:, progress:)
3
+ @logger = logger
4
+ @progress = progress
5
+ end
6
+
7
+ def call(clonner, artifact_servers)
8
+ @logger.info("Syncing git artifacts")
9
+
10
+ remote_operations = []
11
+
12
+ artifact_servers.each do |artifact, servers|
13
+ remote_operations += servers.map do |server|
14
+ @progress.start_syncing_artifact(server, artifact)
15
+
16
+ thread = Thread.new do
17
+ server.synchronize do
18
+ session = Indocker::SshSession.new(
19
+ host: server.host,
20
+ user: server.user,
21
+ port: server.port,
22
+ logger: @logger
23
+ )
24
+
25
+ if artifact.is_git?
26
+ @logger.info("Pulling git artifact #{artifact.name.to_s.green} for #{server.user}@#{server.host}")
27
+ result = clonner.clone(session, artifact.repository)
28
+
29
+ if result.exit_code != 0
30
+ @logger.error("Artifact repository :#{artifact.repository.name} was not clonned")
31
+ @logger.error(result.stderr_data)
32
+ exit 1
33
+ end
34
+ end
35
+
36
+ artifact.files.each do |artifact_item|
37
+ source_path = artifact.build_source_path(artifact_item.source_path)
38
+
39
+ result = session.exec!("mkdir -p #{artifact_item.target_path}")
40
+ result = session.exec!("cp #{source_path} #{artifact_item.target_path}")
41
+
42
+ if !result.success?
43
+ @logger.error(result.stdout_data)
44
+ @logger.error(result.stderr_data)
45
+ exit 1
46
+ end
47
+ end
48
+
49
+ @progress.finish_syncing_artifact(server, artifact)
50
+ end
51
+ end
52
+
53
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :artifact_sync)
54
+ end
55
+ end
56
+
57
+ remote_operations
58
+ end
59
+ end
@@ -4,7 +4,7 @@ class Indocker::BuildContextHelper
4
4
  def initialize(configuration, build_server)
5
5
  @configuration = configuration
6
6
  @build_server = build_server
7
- @clonned_repositories = Hash.new(false)
7
+ @cloned_repositories = Hash.new(false)
8
8
  end
9
9
 
10
10
  def image_url(image_sym)
@@ -1,10 +1,9 @@
1
1
  class Indocker::CrontabRedeployRulesBuilder
2
- CRONTAB = <<-CRONTAB
3
- SHELL=/bin/bash
4
- PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
5
-
6
- %{rules}
2
+ CRONTAB = <<~CRONTAB
3
+ SHELL=/bin/bash
4
+ PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
7
5
 
6
+ %{rules}
8
7
  CRONTAB
9
8
 
10
9
  LOG_FILE = "/var/log/indocker-redeploy-%{env}.log"
@@ -43,10 +43,10 @@ class Indocker::Launchers::ConfigurationDeployer
43
43
  def run!(configuration:, deployment_policy:)
44
44
  containers = find_containers_to_deploy(configuration, deployment_policy)
45
45
 
46
- clonner = Indocker::Repositories::Clonner.new(configuration, @logger)
46
+ cloner = Indocker::Repositories::Cloner.new(configuration, @logger)
47
47
  build_server_pool = Indocker::ServerPools::BuildServerPool.new(configuration: configuration, logger: @logger)
48
48
  deployer = Indocker::ContainerDeployer.new(configuration: configuration, logger: @logger)
49
-
49
+
50
50
  @global_logger.info("Establishing ssh sessions to all servers...")
51
51
  build_server_pool.create_sessions!
52
52
 
@@ -80,31 +80,35 @@ class Indocker::Launchers::ConfigurationDeployer
80
80
  remote_operations = sync_env_files(deploy_servers, configuration.env_files)
81
81
  wait_remote_operations(remote_operations)
82
82
 
83
- remote_operations = pull_repositories(clonner, build_servers, configuration.repositories)
83
+ remote_operations = pull_repositories(cloner, build_servers, configuration.repositories)
84
84
  wait_remote_operations(remote_operations)
85
85
 
86
- remote_operations = sync_artifacts(clonner, configuration.artifact_servers)
86
+ remote_operations = sync_artifacts(cloner, configuration.artifact_servers)
87
87
  wait_remote_operations(remote_operations)
88
88
 
89
89
  update_crontab_redeploy_rules(configuration, build_servers.first)
90
90
 
91
91
  containers.uniq.each do |container|
92
92
  recursively_deploy_container(
93
- configuration,
94
- deployer,
95
- build_server_pool,
96
- container,
97
- containers,
98
- deployment_policy.skip_build,
99
- deployment_policy.skip_deploy,
100
- deployment_policy.force_restart,
93
+ configuration,
94
+ deployer,
95
+ build_server_pool,
96
+ container,
97
+ containers,
98
+ deployment_policy.skip_build,
99
+ deployment_policy.skip_deploy,
100
+ deployment_policy.force_restart,
101
101
  deployment_policy.skip_force_restart
102
102
  )
103
103
  end
104
104
 
105
105
  Thread
106
106
  .list
107
- .each { |t| t.join if t != Thread.current }
107
+ .each { |t|
108
+ if t != Thread.current
109
+ t.join if !t.stop?
110
+ end
111
+ }
108
112
  ensure
109
113
  build_server_pool.close_sessions if build_server_pool
110
114
  deployer.close_sessions if deployer
@@ -127,7 +131,7 @@ class Indocker::Launchers::ConfigurationDeployer
127
131
 
128
132
  def find_containers_to_deploy(configuration, deployment_policy)
129
133
  load_enabled_containers(configuration)
130
-
134
+
131
135
  containers = []
132
136
 
133
137
  deployment_policy.deploy_tags.each do |tag|
@@ -302,19 +306,19 @@ class Indocker::Launchers::ConfigurationDeployer
302
306
  @compiled_images[image] = true
303
307
  end
304
308
 
305
- def recursively_deploy_container(configuration, deployer, build_server_pool, container,
309
+ def recursively_deploy_container(configuration, deployer, build_server_pool, container,
306
310
  containers, skip_build, skip_deploy, force_restart, skip_force_restart)
307
311
 
308
312
  container.dependent_containers.each do |container|
309
313
  recursively_deploy_container(
310
- configuration,
311
- deployer,
312
- build_server_pool,
313
- container,
314
- containers,
315
- skip_build,
314
+ configuration,
315
+ deployer,
316
+ build_server_pool,
317
+ container,
318
+ containers,
319
+ skip_build,
316
320
  skip_deploy,
317
- force_restart,
321
+ force_restart,
318
322
  skip_force_restart
319
323
  )
320
324
  end
@@ -342,18 +346,7 @@ class Indocker::Launchers::ConfigurationDeployer
342
346
  deployer.deploy(container, force_restart, skip_force_restart, @progress)
343
347
  end
344
348
 
345
- class RemoteOperation
346
- attr_reader :thread, :server, :operation, :message
347
-
348
- def initialize(thread, server, operation, message = nil)
349
- @thread = thread
350
- @server = server
351
- @operation = operation
352
- @message = message
353
- end
354
- end
355
-
356
- def pull_repositories(clonner, servers, repositories)
349
+ def pull_repositories(cloner, servers, repositories)
357
350
  @logger.info("Clonning/pulling repositories")
358
351
 
359
352
  remote_operations = []
@@ -382,10 +375,10 @@ class Indocker::Launchers::ConfigurationDeployer
382
375
  )
383
376
  elsif repository.is_git?
384
377
  @logger.info("Pulling repository #{alias_name.to_s.green} for #{server.user}@#{server.host}")
385
- result = clonner.clone(session, repository)
378
+ result = cloner.clone(session, repository)
386
379
 
387
380
  if result.exit_code != 0
388
- @logger.error("Repository :#{repository.name} was not clonned")
381
+ @logger.error("Repository :#{repository.name} was not cloned")
389
382
  @logger.error(result.stderr_data)
390
383
  exit 1
391
384
  end
@@ -398,57 +391,20 @@ class Indocker::Launchers::ConfigurationDeployer
398
391
  @progress.finish_syncing_repository(server, alias_name)
399
392
  end
400
393
 
401
- RemoteOperation.new(thread, server, :repository_pull)
394
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :repository_pull)
402
395
  end
403
396
  end
404
397
 
405
398
  remote_operations
406
399
  end
407
400
 
408
- def sync_artifacts(clonner, artifact_servers)
409
- @logger.info("Syncing git artifacts")
410
-
411
- remote_operations = []
412
-
413
- artifact_servers.each do |artifact, servers|
414
- remote_operations += servers.map do |server|
415
- @progress.start_syncing_artifact(server, artifact)
416
-
417
- thread = Thread.new do
418
- server.synchronize do
419
- session = Indocker::SshSession.new(
420
- host: server.host,
421
- user: server.user,
422
- port: server.port,
423
- logger: @logger
424
- )
425
-
426
- @logger.info("Pulling git artifact #{artifact.name.to_s.green} for #{server.user}@#{server.host}")
427
- result = clonner.clone(session, artifact.repository)
428
-
429
- if result.exit_code != 0
430
- @logger.error("Artifact repository :#{artifact.repository.name} was not clonned")
431
- @logger.error(result.stderr_data)
432
- exit 1
433
- end
434
-
435
- source_path = File.join(artifact.repository.clone_path, artifact.source_path)
436
- result = session.exec!("mkdir -p #{artifact.target_path}")
437
- result = session.exec!("cp -r #{source_path} #{artifact.target_path}")
438
-
439
- if !result.success?
440
- @logger.error(result.stdout_data)
441
- @logger.error(result.stderr_data)
442
- exit 1
443
- end
444
-
445
- @progress.finish_syncing_artifact(server, artifact)
446
- end
447
- end
401
+ def sync_artifacts(cloner, artifact_servers)
402
+ artifacts_synchronizer = Indocker::Artifacts::Services::Synchronizer.new(
403
+ logger: @logger,
404
+ progress: @progress,
405
+ )
448
406
 
449
- RemoteOperation.new(thread, server, :artifact_sync)
450
- end
451
- end
407
+ remote_operations = artifacts_synchronizer.call(cloner, artifact_servers)
452
408
 
453
409
  remote_operations
454
410
  end
@@ -506,7 +462,7 @@ class Indocker::Launchers::ConfigurationDeployer
506
462
  @progress.finish_syncing_binaries(server)
507
463
  end
508
464
 
509
- RemoteOperation.new(thread, server, :indocker_sync)
465
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :indocker_sync)
510
466
  end
511
467
  end
512
468
 
@@ -547,7 +503,7 @@ class Indocker::Launchers::ConfigurationDeployer
547
503
  @progress.finish_syncing_env_file(server, alias_name)
548
504
  end
549
505
 
550
- RemoteOperation.new(thread, server, :env_file_sync)
506
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :env_file_sync)
551
507
  end
552
508
  end
553
509
 
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Indocker
2
- VERSION = "0.1.16"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/indocker.rb CHANGED
@@ -10,16 +10,12 @@ module Indocker
10
10
  autoload :Git, 'repositories/git'
11
11
  autoload :Local, 'repositories/local'
12
12
  autoload :NoSync, 'repositories/no_sync'
13
- autoload :Clonner, 'repositories/clonner'
13
+ autoload :Cloner, 'repositories/cloner'
14
14
  end
15
15
 
16
16
  module Configurations
17
17
  autoload :Configuration, 'configurations/configuration'
18
18
  autoload :ConfigurationBuilder, 'configurations/configuration_builder'
19
-
20
- module Formatters
21
- autoload :Stdout, 'configurations/formatters/stdout'
22
- end
23
19
  end
24
20
 
25
21
  module Registries
@@ -59,7 +55,17 @@ module Indocker
59
55
  end
60
56
 
61
57
  module Artifacts
58
+ autoload :Base, 'artifacts/base'
62
59
  autoload :Git, 'artifacts/git'
60
+ autoload :Remote, 'artifacts/remote'
61
+
62
+ module DTO
63
+ autoload :FileDTO, 'artifacts/dto/file_dto'
64
+ end
65
+
66
+ module Services
67
+ autoload :Synchronizer, 'artifacts/services/synchronizer'
68
+ end
63
69
  end
64
70
 
65
71
  module Networks
@@ -71,6 +77,10 @@ module Indocker
71
77
  autoload :ConfigurationDeployer, 'launchers/configuration_deployer'
72
78
  autoload :ImagesCompiler, 'launchers/images_compiler'
73
79
  autoload :ContainerRunner, 'launchers/container_runner'
80
+
81
+ module DTO
82
+ autoload :RemoteOperationDTO, 'launchers/dto/remote_operation_dto'
83
+ end
74
84
  end
75
85
 
76
86
  module ServerPools
@@ -332,9 +342,9 @@ module Indocker
332
342
  builder
333
343
  end
334
344
 
335
- def deploy(containers: [], skip_tags: [], tags: [], skip_dependent: false,
345
+ def deploy(containers: [], skip_tags: [], tags: [], skip_dependent: false,
336
346
  skip_containers: [], servers: [], skip_build: false, skip_deploy: false,
337
- force_restart: false, skip_force_restart: [], auto_confirm: false,
347
+ force_restart: false, skip_force_restart: [], auto_confirm: false,
338
348
  require_confirmation: false)
339
349
 
340
350
  deployment_policy = Indocker::DeploymentPolicy.new(
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  - Iskander Khaziev
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-08-14 00:00:00.000000000 Z
12
+ date: 2022-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -103,33 +103,45 @@ files:
103
103
  - example/indocker/bin/remote/compile
104
104
  - example/indocker/bin/remote/run
105
105
  - example/indocker/bin/utils/configurations.rb
106
- - example/indocker/bounded_contexts/shared/bad_container_build/Dockerfile
107
- - example/indocker/bounded_contexts/shared/bad_container_build/container.rb
108
- - example/indocker/bounded_contexts/shared/bad_container_build/image.rb
109
- - example/indocker/bounded_contexts/shared/bad_container_start/Dockerfile
110
- - example/indocker/bounded_contexts/shared/bad_container_start/build_context/bin/run
111
- - example/indocker/bounded_contexts/shared/bad_container_start/container.rb
112
- - example/indocker/bounded_contexts/shared/bad_container_start/image.rb
113
- - example/indocker/bounded_contexts/shared/daemon_container/Dockerfile
114
- - example/indocker/bounded_contexts/shared/daemon_container/container.rb
115
- - example/indocker/bounded_contexts/shared/daemon_container/image.rb
116
- - example/indocker/bounded_contexts/shared/good_container/Dockerfile
117
- - example/indocker/bounded_contexts/shared/good_container/container.rb
118
- - 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
119
125
  - example/indocker/bounded_contexts/shared/ruby/Dockerfile
120
126
  - example/indocker/bounded_contexts/shared/ruby/container.rb
121
127
  - example/indocker/bounded_contexts/shared/ruby/image.rb
122
128
  - example/indocker/configurations/dev.rb
123
129
  - example/indocker/configurations/external.rb
130
+ - example/indocker/env_files/development_env.env
124
131
  - example/indocker/infrastructure/artifacts.rb
125
132
  - example/indocker/infrastructure/build_servers.rb
133
+ - example/indocker/infrastructure/env_files.rb
126
134
  - example/indocker/infrastructure/networks.rb
127
135
  - example/indocker/infrastructure/registries.rb
128
136
  - example/indocker/infrastructure/servers.rb
129
137
  - example/indocker/setup.rb
130
138
  - indocker.gemspec
131
139
  - lib/indocker.rb
140
+ - lib/indocker/artifacts/base.rb
141
+ - lib/indocker/artifacts/dto/file_dto.rb
132
142
  - lib/indocker/artifacts/git.rb
143
+ - lib/indocker/artifacts/remote.rb
144
+ - lib/indocker/artifacts/services/synchronizer.rb
133
145
  - lib/indocker/build_context.rb
134
146
  - lib/indocker/build_context_helper.rb
135
147
  - lib/indocker/build_server.rb
@@ -137,7 +149,6 @@ files:
137
149
  - lib/indocker/concerns/inspectable.rb
138
150
  - lib/indocker/configurations/configuration.rb
139
151
  - lib/indocker/configurations/configuration_builder.rb
140
- - lib/indocker/configurations/formatters/stdout.rb
141
152
  - lib/indocker/container_deployer.rb
142
153
  - lib/indocker/container_helper.rb
143
154
  - lib/indocker/containers/container.rb
@@ -163,6 +174,7 @@ files:
163
174
  - lib/indocker/indocker_helper.rb
164
175
  - lib/indocker/launchers/configuration_deployer.rb
165
176
  - lib/indocker/launchers/container_runner.rb
177
+ - lib/indocker/launchers/dto/remote_operation_dto.rb
166
178
  - lib/indocker/launchers/images_compiler.rb
167
179
  - lib/indocker/logger_factory.rb
168
180
  - lib/indocker/networks/network.rb
@@ -171,7 +183,7 @@ files:
171
183
  - lib/indocker/registries/local.rb
172
184
  - lib/indocker/registries/remote.rb
173
185
  - lib/indocker/repositories/abstract.rb
174
- - lib/indocker/repositories/clonner.rb
186
+ - lib/indocker/repositories/cloner.rb
175
187
  - lib/indocker/repositories/git.rb
176
188
  - lib/indocker/repositories/local.rb
177
189
  - lib/indocker/repositories/no_sync.rb
@@ -194,7 +206,7 @@ homepage: https://github.com/ArtStation/indocker
194
206
  licenses:
195
207
  - MIT
196
208
  metadata: {}
197
- post_install_message:
209
+ post_install_message:
198
210
  rdoc_options: []
199
211
  require_paths:
200
212
  - lib
@@ -209,8 +221,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
221
  - !ruby/object:Gem::Version
210
222
  version: '0'
211
223
  requirements: []
212
- rubygems_version: 3.0.8
213
- signing_key:
224
+ rubygems_version: 3.3.7
225
+ signing_key:
214
226
  specification_version: 4
215
227
  summary: Docker Containers Deployment
216
228
  test_files: []
@@ -1,4 +0,0 @@
1
- FROM ruby:2.5.0
2
-
3
- RUN mkdir /app
4
- WORKDIR /app
@@ -1,3 +0,0 @@
1
- Indocker
2
- .define_image(:daemon_container)
3
- .registry(:default)
@@ -1,3 +0,0 @@
1
- Indocker
2
- .define_image(:good_container)
3
- .registry(:default)
@@ -1,36 +0,0 @@
1
- class Indocker::Configurations::Formatters::Stdout
2
- def print(configuration)
3
- c = configuration
4
- <<~EOS
5
- Name: #{c.name}
6
-
7
- Repositories: {
8
- #{c.repositories.map do |alias_name, repository|
9
- " #{alias_name}: #{repository.inspect}"
10
- end.join("\n")}
11
- }
12
-
13
- Registries: {
14
- #{c.registries.map do |alias_name, registry|
15
- " #{alias_name}: #{registry.inspect}"
16
- end.join("\n")}
17
- }
18
-
19
- Servers: {
20
- #{c.servers.map do |alias_name, server|
21
- " #{alias_name}: #{server.inspect}"
22
- end.join("\n")}
23
- }
24
-
25
- Build Servers: [
26
- #{c.build_servers.map do |build_server|
27
- " #{build_server.inspect}"
28
- end.join("\n")}
29
- ]
30
-
31
- Tags: #{c.tags.inspect}
32
-
33
- Global build args: #{c.global_build_args.inspect}
34
- EOS
35
- end
36
- end
@@ -1,17 +0,0 @@
1
- require 'net/ssh'
2
-
3
- class Indocker::Repositories::Clonner
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 clonned") if !repository.is_git?
11
-
12
- session.exec!("rm -rf #{repository.clone_path} && mkdir -p #{repository.clone_path}")
13
-
14
- git_command = "git clone -b #{repository.branch} --depth 1 #{repository.remote_url} #{repository.clone_path}"
15
- session.exec!("ssh-agent bash -c 'ssh-add ~/.ssh/#{repository.ssh_key}; #{git_command}'")
16
- end
17
- end