indocker 0.1.16 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/example/indocker/bin/deploy +3 -6
  4. data/example/indocker/bin/remote/compile +2 -6
  5. data/example/indocker/bin/remote/run +2 -6
  6. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/Dockerfile +0 -0
  7. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/container.rb +0 -0
  8. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/image.rb +0 -0
  9. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/Dockerfile +0 -0
  10. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/build_context/bin/run +0 -0
  11. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/container.rb +0 -0
  12. data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/image.rb +0 -0
  13. data/example/indocker/bounded_contexts/good_containers/daemon_container/Dockerfile +1 -0
  14. data/example/indocker/bounded_contexts/{shared → good_containers}/daemon_container/container.rb +0 -0
  15. data/example/indocker/bounded_contexts/good_containers/daemon_container/image.rb +4 -0
  16. data/example/indocker/bounded_contexts/good_containers/dependency_container/Dockerfile +1 -0
  17. data/example/indocker/bounded_contexts/good_containers/dependency_container/container.rb +6 -0
  18. data/example/indocker/bounded_contexts/good_containers/dependency_container/image.rb +4 -0
  19. data/example/indocker/bounded_contexts/good_containers/good_container/Dockerfile +3 -0
  20. data/example/indocker/bounded_contexts/good_containers/good_container/build_context/example_file.txt +2 -0
  21. data/example/indocker/bounded_contexts/{shared → good_containers}/good_container/container.rb +5 -1
  22. data/example/indocker/bounded_contexts/good_containers/good_container/image.rb +4 -0
  23. data/example/indocker/bounded_contexts/shared/{good_container → parent_image}/Dockerfile +1 -1
  24. data/example/indocker/bounded_contexts/shared/parent_image/image.rb +3 -0
  25. data/example/indocker/configurations/external.rb +5 -0
  26. data/example/indocker/env_files/development_env.env +1 -0
  27. data/example/indocker/infrastructure/artifacts.rb +18 -2
  28. data/example/indocker/infrastructure/env_files.rb +6 -0
  29. data/example/indocker/setup.rb +2 -1
  30. data/lib/indocker/artifacts/base.rb +26 -0
  31. data/lib/indocker/artifacts/dto/file_dto.rb +8 -0
  32. data/lib/indocker/artifacts/git.rb +20 -6
  33. data/lib/indocker/artifacts/remote.rb +17 -0
  34. data/lib/indocker/artifacts/services/synchronizer.rb +59 -0
  35. data/lib/indocker/build_context_helper.rb +1 -1
  36. data/lib/indocker/crontab_redeploy_rules_builder.rb +4 -5
  37. data/lib/indocker/launchers/configuration_deployer.rb +33 -81
  38. data/lib/indocker/launchers/dto/remote_operation_dto.rb +10 -0
  39. data/lib/indocker/repositories/cloner.rb +73 -0
  40. data/lib/indocker/version.rb +1 -1
  41. data/lib/indocker.rb +17 -7
  42. metadata +30 -18
  43. data/example/indocker/bounded_contexts/shared/daemon_container/Dockerfile +0 -4
  44. data/example/indocker/bounded_contexts/shared/daemon_container/image.rb +0 -3
  45. data/example/indocker/bounded_contexts/shared/good_container/image.rb +0 -3
  46. data/lib/indocker/configurations/formatters/stdout.rb +0 -36
  47. 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: 2a5d202d36a852928093c1692e9a10d54bacff1d27868d7226ee1cfae15693e4
4
+ data.tar.gz: 54b624c582b12e08ddf638244b8c6fa0535f0a9594fb9f9ffbef0db1165a1b62
5
5
  SHA512:
6
- metadata.gz: 4da7e1049911e4d0c12d89d977cfb568687f61568866ec82f737694c1023984ad97d205d25eaa35e19ebc46843d0743d1df07c833c48d293a5c10ca5de0fd792
7
- data.tar.gz: 1a8205455ebf5da34c8039a87c45772807920e362e8814bee275ef578647a15edf9970a9c53196b5805aeba8d4b3b047e30e329b0637d393a390c9d32c68353f
6
+ metadata.gz: 2da5112e2278a5b9b21fb339abc894620cd687ebcf3c08053754e268335814cd088c799a4c243db3a91595ee22c455f34d8c8fcd57fffb96c629d5018fa6089e
7
+ data.tar.gz: 44feb6b875f8b5d6fad1523f37c226a3029518f72e89b1cdd0a3ab1ee8ac625c7cc98054f56948cae5933f2c370364c5d6b943cf529b031ed50ea4316f672265
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- indocker (0.1.16)
4
+ indocker (0.1.18)
5
5
  net-ssh
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ GEM
11
11
  diff-lcs (1.3)
12
12
  docile (1.3.2)
13
13
  method_source (1.0.0)
14
- net-ssh (6.1.0)
14
+ net-ssh (7.0.1)
15
15
  pry (0.13.1)
16
16
  coderay (~> 1.1)
17
17
  method_source (~> 1.0)
@@ -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,18 @@
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, :ssh_key
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, ssh_key: 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
+ @ssh_key = ssh_key
10
+
11
+ @files = build_all_files(
12
+ files: files,
13
+ source_path: source_path,
14
+ target_path: target_path,
15
+ )
11
16
  end
12
17
 
13
18
  def repository
@@ -15,6 +20,7 @@ class Indocker::Artifacts::Git
15
20
  remote_name: remote_name,
16
21
  remote_url: remote_url,
17
22
  branch: branch,
23
+ ssh_key: ssh_key,
18
24
  clone_path: "/tmp/#{Indocker.configuration.name}/artifacts/git/#{project_name(remote_url)}/#{branch}"
19
25
  )
20
26
  end
@@ -22,4 +28,12 @@ class Indocker::Artifacts::Git
22
28
  def project_name(url)
23
29
  url.split('/').last.gsub('.git', '')
24
30
  end
25
- end
31
+
32
+ def is_git?
33
+ true
34
+ end
35
+
36
+ def build_source_path(path)
37
+ File.join(self.repository.clone_path, path)
38
+ end
39
+ 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,24 +80,24 @@ 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
@@ -127,7 +127,7 @@ class Indocker::Launchers::ConfigurationDeployer
127
127
 
128
128
  def find_containers_to_deploy(configuration, deployment_policy)
129
129
  load_enabled_containers(configuration)
130
-
130
+
131
131
  containers = []
132
132
 
133
133
  deployment_policy.deploy_tags.each do |tag|
@@ -302,19 +302,19 @@ class Indocker::Launchers::ConfigurationDeployer
302
302
  @compiled_images[image] = true
303
303
  end
304
304
 
305
- def recursively_deploy_container(configuration, deployer, build_server_pool, container,
305
+ def recursively_deploy_container(configuration, deployer, build_server_pool, container,
306
306
  containers, skip_build, skip_deploy, force_restart, skip_force_restart)
307
307
 
308
308
  container.dependent_containers.each do |container|
309
309
  recursively_deploy_container(
310
- configuration,
311
- deployer,
312
- build_server_pool,
313
- container,
314
- containers,
315
- skip_build,
310
+ configuration,
311
+ deployer,
312
+ build_server_pool,
313
+ container,
314
+ containers,
315
+ skip_build,
316
316
  skip_deploy,
317
- force_restart,
317
+ force_restart,
318
318
  skip_force_restart
319
319
  )
320
320
  end
@@ -342,18 +342,7 @@ class Indocker::Launchers::ConfigurationDeployer
342
342
  deployer.deploy(container, force_restart, skip_force_restart, @progress)
343
343
  end
344
344
 
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)
345
+ def pull_repositories(cloner, servers, repositories)
357
346
  @logger.info("Clonning/pulling repositories")
358
347
 
359
348
  remote_operations = []
@@ -382,10 +371,10 @@ class Indocker::Launchers::ConfigurationDeployer
382
371
  )
383
372
  elsif repository.is_git?
384
373
  @logger.info("Pulling repository #{alias_name.to_s.green} for #{server.user}@#{server.host}")
385
- result = clonner.clone(session, repository)
374
+ result = cloner.clone(session, repository)
386
375
 
387
376
  if result.exit_code != 0
388
- @logger.error("Repository :#{repository.name} was not clonned")
377
+ @logger.error("Repository :#{repository.name} was not cloned")
389
378
  @logger.error(result.stderr_data)
390
379
  exit 1
391
380
  end
@@ -398,57 +387,20 @@ class Indocker::Launchers::ConfigurationDeployer
398
387
  @progress.finish_syncing_repository(server, alias_name)
399
388
  end
400
389
 
401
- RemoteOperation.new(thread, server, :repository_pull)
390
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :repository_pull)
402
391
  end
403
392
  end
404
393
 
405
394
  remote_operations
406
395
  end
407
396
 
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
397
+ def sync_artifacts(cloner, artifact_servers)
398
+ artifacts_synchronizer = Indocker::Artifacts::Services::Synchronizer.new(
399
+ logger: @logger,
400
+ progress: @progress,
401
+ )
448
402
 
449
- RemoteOperation.new(thread, server, :artifact_sync)
450
- end
451
- end
403
+ remote_operations = artifacts_synchronizer.call(cloner, artifact_servers)
452
404
 
453
405
  remote_operations
454
406
  end
@@ -506,7 +458,7 @@ class Indocker::Launchers::ConfigurationDeployer
506
458
  @progress.finish_syncing_binaries(server)
507
459
  end
508
460
 
509
- RemoteOperation.new(thread, server, :indocker_sync)
461
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :indocker_sync)
510
462
  end
511
463
  end
512
464
 
@@ -547,7 +499,7 @@ class Indocker::Launchers::ConfigurationDeployer
547
499
  @progress.finish_syncing_env_file(server, alias_name)
548
500
  end
549
501
 
550
- RemoteOperation.new(thread, server, :env_file_sync)
502
+ Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :env_file_sync)
551
503
  end
552
504
  end
553
505
 
@@ -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.1.18"
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,7 +1,7 @@
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.1.18
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-14 00:00:00.000000000 Z
12
+ date: 2023-02-16 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
@@ -209,7 +221,7 @@ 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
224
+ rubygems_version: 3.0.9
213
225
  signing_key:
214
226
  specification_version: 4
215
227
  summary: Docker Containers Deployment
@@ -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