indocker 0.1.16 → 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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/example/indocker/bin/deploy +3 -6
- data/example/indocker/bin/remote/compile +2 -6
- data/example/indocker/bin/remote/run +2 -6
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/Dockerfile +0 -0
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/container.rb +0 -0
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/image.rb +0 -0
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/Dockerfile +0 -0
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/build_context/bin/run +0 -0
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/container.rb +0 -0
- data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/image.rb +0 -0
- data/example/indocker/bounded_contexts/good_containers/daemon_container/Dockerfile +1 -0
- data/example/indocker/bounded_contexts/{shared → good_containers}/daemon_container/container.rb +0 -0
- data/example/indocker/bounded_contexts/good_containers/daemon_container/image.rb +4 -0
- data/example/indocker/bounded_contexts/good_containers/dependency_container/Dockerfile +1 -0
- data/example/indocker/bounded_contexts/good_containers/dependency_container/container.rb +6 -0
- data/example/indocker/bounded_contexts/good_containers/dependency_container/image.rb +4 -0
- data/example/indocker/bounded_contexts/good_containers/good_container/Dockerfile +3 -0
- data/example/indocker/bounded_contexts/good_containers/good_container/build_context/example_file.txt +2 -0
- data/example/indocker/bounded_contexts/{shared → good_containers}/good_container/container.rb +5 -1
- data/example/indocker/bounded_contexts/good_containers/good_container/image.rb +4 -0
- data/example/indocker/bounded_contexts/shared/{good_container → parent_image}/Dockerfile +1 -1
- data/example/indocker/bounded_contexts/shared/parent_image/image.rb +3 -0
- data/example/indocker/configurations/external.rb +5 -0
- data/example/indocker/env_files/development_env.env +1 -0
- data/example/indocker/infrastructure/artifacts.rb +18 -2
- data/example/indocker/infrastructure/env_files.rb +6 -0
- data/example/indocker/setup.rb +2 -1
- data/lib/indocker.rb +17 -7
- data/lib/indocker/artifacts/base.rb +26 -0
- data/lib/indocker/artifacts/dto/file_dto.rb +8 -0
- data/lib/indocker/artifacts/git.rb +17 -5
- data/lib/indocker/artifacts/remote.rb +17 -0
- data/lib/indocker/artifacts/services/synchronizer.rb +59 -0
- data/lib/indocker/build_context_helper.rb +1 -1
- data/lib/indocker/crontab_redeploy_rules_builder.rb +4 -5
- data/lib/indocker/launchers/configuration_deployer.rb +33 -81
- data/lib/indocker/launchers/dto/remote_operation_dto.rb +10 -0
- data/lib/indocker/repositories/cloner.rb +73 -0
- data/lib/indocker/version.rb +1 -1
- metadata +29 -17
- data/example/indocker/bounded_contexts/shared/daemon_container/Dockerfile +0 -4
- data/example/indocker/bounded_contexts/shared/daemon_container/image.rb +0 -3
- data/example/indocker/bounded_contexts/shared/good_container/image.rb +0 -3
- data/lib/indocker/configurations/formatters/stdout.rb +0 -36
- data/lib/indocker/repositories/clonner.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87f0d247cd6a4aa8f3958d6b9d9aef1dfd879c15651c9e4c01c9e15e7bffe0a0
|
|
4
|
+
data.tar.gz: e0391bebb9cd04117a68e904caef9ccd72b586fd10a8e2ba02b3673b389de8de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: baad11d2671bb96f35cfed12ca80ac713d135ee19a4b8e7222ab91685a9f5efd65a84d539425cc68e7f786eca689e451b46ea2e503569037b080aee422f01fe2
|
|
7
|
+
data.tar.gz: 876a4b96e5a96f7a1f9ffff7138597e413739a84c4bc1dbe8b0adb18073e431ecef0da966b7c7bf861d3f6792de8ec21e43f5970aae6ccb3b5813b095700a787
|
data/Gemfile.lock
CHANGED
data/example/indocker/bin/deploy
CHANGED
|
@@ -94,12 +94,9 @@ if !configurations.include?(options[:configuration])
|
|
|
94
94
|
exit 1
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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)
|
data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/Dockerfile
RENAMED
|
File without changes
|
data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/container.rb
RENAMED
|
File without changes
|
data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_build/image.rb
RENAMED
|
File without changes
|
data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/Dockerfile
RENAMED
|
File without changes
|
|
File without changes
|
data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/container.rb
RENAMED
|
File without changes
|
data/example/indocker/bounded_contexts/{shared → bad_containers}/bad_container_start/image.rb
RENAMED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
FROM <%= image_url(:parent_image) %>
|
data/example/indocker/bounded_contexts/{shared → good_containers}/daemon_container/container.rb
RENAMED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
FROM <%= image_url(:parent_image) %>
|
data/example/indocker/bounded_contexts/{shared → good_containers}/good_container/container.rb
RENAMED
|
@@ -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
|
+
# })
|
|
@@ -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
|
-
|
|
8
|
-
|
|
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
|
)
|
data/example/indocker/setup.rb
CHANGED
|
@@ -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('
|
|
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
|
|
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 :
|
|
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(
|
|
@@ -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
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
class Indocker::Artifacts::Git
|
|
2
|
-
attr_reader :name, :remote_name, :remote_url, :branch, :
|
|
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
|
|
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
|
-
|
|
10
|
-
@
|
|
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
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
class Indocker::CrontabRedeployRulesBuilder
|
|
2
|
-
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
|
-
|
|
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(
|
|
83
|
+
remote_operations = pull_repositories(cloner, build_servers, configuration.repositories)
|
|
84
84
|
wait_remote_operations(remote_operations)
|
|
85
85
|
|
|
86
|
-
remote_operations = sync_artifacts(
|
|
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
|
-
|
|
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 =
|
|
374
|
+
result = cloner.clone(session, repository)
|
|
386
375
|
|
|
387
376
|
if result.exit_code != 0
|
|
388
|
-
@logger.error("Repository :#{repository.name} was not
|
|
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
|
-
|
|
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(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
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.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
|
|
12
|
+
date: 2020-09-08 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/
|
|
107
|
-
- example/indocker/bounded_contexts/
|
|
108
|
-
- example/indocker/bounded_contexts/
|
|
109
|
-
- example/indocker/bounded_contexts/
|
|
110
|
-
- example/indocker/bounded_contexts/
|
|
111
|
-
- example/indocker/bounded_contexts/
|
|
112
|
-
- example/indocker/bounded_contexts/
|
|
113
|
-
- example/indocker/bounded_contexts/
|
|
114
|
-
- example/indocker/bounded_contexts/
|
|
115
|
-
- example/indocker/bounded_contexts/
|
|
116
|
-
- example/indocker/bounded_contexts/
|
|
117
|
-
- example/indocker/bounded_contexts/
|
|
118
|
-
- example/indocker/bounded_contexts/
|
|
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/
|
|
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
|
|
@@ -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
|