indocker 0.1.12 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +8 -2
- 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 +2 -1
- 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 +2 -1
- 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/good_containers/daemon_container/container.rb +6 -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/good_containers/good_container/container.rb +10 -0
- 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/bounded_contexts/shared/ruby/container.rb +2 -1
- data/example/indocker/configurations/external.rb +11 -1
- data/example/indocker/env_files/development_env.env +1 -0
- data/example/indocker/infrastructure/artifacts.rb +26 -0
- data/example/indocker/infrastructure/env_files.rb +6 -0
- data/example/indocker/setup.rb +3 -1
- data/indocker.gemspec +1 -0
- data/lib/indocker.rb +42 -20
- 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.rb +6 -41
- data/lib/indocker/build_context_helper.rb +1 -1
- data/lib/indocker/container_deployer.rb +12 -23
- data/lib/indocker/crontab_redeploy_rules_builder.rb +6 -6
- data/lib/indocker/deploy_context.rb +4 -32
- data/lib/indocker/deployment_checker.rb +4 -2
- data/lib/indocker/docker_run_args.rb +2 -2
- data/lib/indocker/images/image_compiler.rb +0 -1
- data/lib/indocker/{configuration_deployer.rb → launchers/configuration_deployer.rb} +66 -113
- data/lib/indocker/{container_runner.rb → launchers/container_runner.rb} +2 -3
- data/lib/indocker/launchers/dto/remote_operation_dto.rb +10 -0
- data/lib/indocker/{images_compiler.rb → launchers/images_compiler.rb} +1 -2
- data/lib/indocker/{network.rb → networks/network.rb} +1 -1
- data/lib/indocker/{network_helper.rb → networks/network_helper.rb} +1 -1
- data/lib/indocker/repositories/cloner.rb +73 -0
- data/lib/indocker/server_pools/build_server_connection.rb +15 -0
- data/lib/indocker/server_pools/build_server_pool.rb +40 -0
- data/lib/indocker/server_pools/deploy_server_connection.rb +17 -0
- data/lib/indocker/server_pools/deploy_server_pool.rb +41 -0
- data/lib/indocker/server_pools/server_connection.rb +37 -0
- data/lib/indocker/version.rb +1 -1
- data/lib/indocker/{volume_helper.rb → volumes/volume_helper.rb} +1 -1
- metadata +56 -24
- data/example/indocker/bounded_contexts/shared/good_container/container.rb +0 -5
- data/example/indocker/bounded_contexts/shared/good_container/image.rb +0 -3
- data/example/spec/indocker_spec.rb +0 -39
- data/example/spec/spec_helper.rb +0 -39
- data/lib/indocker/build_context_pool.rb +0 -42
- data/lib/indocker/configurations/formatters/stdout.rb +0 -36
- data/lib/indocker/repositories/clonner.rb +0 -17
- data/lib/indocker/server_pool.rb +0 -38
@@ -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,55 +1,18 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
class Indocker::BuildContext
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :configuration, :logger, :global_logger, :helper
|
5
5
|
|
6
|
-
def initialize(configuration:,
|
6
|
+
def initialize(configuration:, logger:, global_logger:)
|
7
7
|
@configuration = configuration
|
8
8
|
@logger = logger
|
9
9
|
@helper = Indocker::BuildContextHelper.new(@configuration, @build_server)
|
10
|
-
@server = build_server
|
11
10
|
@global_logger = global_logger
|
12
|
-
@compiled_images = Hash.new(false)
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_session!
|
16
|
-
return unless @server
|
17
|
-
|
18
|
-
@session = Indocker::SshSession.new(
|
19
|
-
host: @server.host,
|
20
|
-
user: @server.user,
|
21
|
-
port: @server.port,
|
22
|
-
logger: @logger
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
def exec!(command)
|
27
|
-
@session.exec!(command)
|
28
|
-
end
|
29
|
-
|
30
|
-
def close_session
|
31
|
-
@session.close if @session
|
32
|
-
end
|
33
|
-
|
34
|
-
def image_compiled?(image)
|
35
|
-
@compiled_images[image]
|
36
|
-
end
|
37
|
-
|
38
|
-
def set_busy(flag)
|
39
|
-
@busy = !!flag
|
40
|
-
end
|
41
|
-
|
42
|
-
def busy?
|
43
|
-
!!@busy
|
44
|
-
end
|
45
|
-
|
46
|
-
def set_compiled(image)
|
47
|
-
@compiled_images[image] = true
|
48
11
|
end
|
49
12
|
|
50
13
|
def build_image(image, build_dir, args: [])
|
51
14
|
image_name = image.image_name
|
52
|
-
registry
|
15
|
+
registry = image.registry
|
53
16
|
tag = image.tag
|
54
17
|
|
55
18
|
FileUtils.cd(build_dir) do
|
@@ -79,7 +42,9 @@ class Indocker::BuildContext
|
|
79
42
|
end
|
80
43
|
|
81
44
|
Indocker::Docker.tag(image.local_registry_url, image.registry_url)
|
82
|
-
|
45
|
+
if image.registry_url != image.local_registry_url
|
46
|
+
Indocker::Docker.tag(image.local_registry_url, image.local_registry_url)
|
47
|
+
end
|
83
48
|
|
84
49
|
if !image.registry.is_local?
|
85
50
|
Indocker::Docker.push(image.registry_url)
|
@@ -5,7 +5,7 @@ class Indocker::ContainerDeployer
|
|
5
5
|
@configuration = configuration
|
6
6
|
@logger = logger
|
7
7
|
|
8
|
-
@server_pool = Indocker::
|
8
|
+
@server_pool = Indocker::ServerPools::DeployServerPool.new(
|
9
9
|
configuration: @configuration,
|
10
10
|
logger: logger
|
11
11
|
)
|
@@ -14,10 +14,6 @@ class Indocker::ContainerDeployer
|
|
14
14
|
@deployed_servers = {}
|
15
15
|
end
|
16
16
|
|
17
|
-
def create_sessions!
|
18
|
-
@server_pool.create_sessions!
|
19
|
-
end
|
20
|
-
|
21
17
|
def deploy(container, force_restart, skip_force_restart, progress)
|
22
18
|
return if @deployed_containers[container]
|
23
19
|
|
@@ -37,30 +33,23 @@ class Indocker::ContainerDeployer
|
|
37
33
|
end
|
38
34
|
|
39
35
|
exec_proc.call do
|
40
|
-
|
36
|
+
deploy_server = @server_pool.create_connection!(server)
|
41
37
|
@logger.info("Deploying container: #{container.name.to_s.green} to #{server.user}@#{server.host}")
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
result = deploy_context
|
51
|
-
.session
|
52
|
-
.exec!(
|
53
|
-
"cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/run -C #{Indocker.configuration_name} -c #{container.name} #{debug_options} #{command_output} #{force_restart_options}"
|
39
|
+
result = deploy_server
|
40
|
+
.run_container_remotely(
|
41
|
+
configuration_name: Indocker.configuration_name,
|
42
|
+
container_name: container.name,
|
43
|
+
force_restart: force_restart && !skip_force_restart.include?(container.name)
|
54
44
|
)
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
exit 1 if result.exit_code != 0
|
46
|
+
if result.exit_code != 0
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
61
50
|
@logger.info("Container deployment to #{server.user}@#{server.host} finished: #{container.name.to_s.green}")
|
62
51
|
|
63
|
-
|
52
|
+
deploy_server.close_session
|
64
53
|
progress.finish_deploying_container(container, server)
|
65
54
|
end
|
66
55
|
end
|
@@ -1,14 +1,13 @@
|
|
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"
|
11
|
-
COMMAND = "export TERM=xterm
|
10
|
+
COMMAND = "export TERM=xterm;%{deploy_dir}/indocker/bin/deploy -C %{env} -f -B -y -c %{container_name}"
|
12
11
|
REDEPLOY_RULE = %Q{%{schedule} echo `date` "- %{command}..." >> %{log_file}; %{command} 1>/dev/null 2>>%{log_file}; echo `date` "- done, exitcode = $?" >> %{log_file}}
|
13
12
|
|
14
13
|
def initialize(configuration:, logger:)
|
@@ -41,6 +40,7 @@ PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb
|
|
41
40
|
COMMAND % {
|
42
41
|
env: env,
|
43
42
|
container_name: container.name,
|
43
|
+
deploy_dir: Indocker.deploy_dir
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
@@ -2,42 +2,14 @@ require 'digest'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
class Indocker::DeployContext
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :configuration, :logger
|
6
6
|
|
7
|
-
def initialize(logger:, configuration
|
7
|
+
def initialize(logger:, configuration:)
|
8
8
|
@logger = logger
|
9
9
|
@configuration = configuration
|
10
|
-
@server = server
|
11
10
|
@restart_policy = Indocker::Containers::RestartPolicy.new(configuration, logger)
|
12
11
|
end
|
13
12
|
|
14
|
-
def create_session!
|
15
|
-
return unless @server
|
16
|
-
|
17
|
-
@session = Indocker::SshSession.new(
|
18
|
-
host: @server.host,
|
19
|
-
user: @server.user,
|
20
|
-
port: @server.port,
|
21
|
-
logger: @logger
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def exec!(command)
|
26
|
-
@session.exec!(command)
|
27
|
-
end
|
28
|
-
|
29
|
-
def close_session
|
30
|
-
@session.close if @session
|
31
|
-
end
|
32
|
-
|
33
|
-
def set_busy(flag)
|
34
|
-
@busy = !!flag
|
35
|
-
end
|
36
|
-
|
37
|
-
def busy?
|
38
|
-
!!@busy
|
39
|
-
end
|
40
|
-
|
41
13
|
def deploy(container, force_restart)
|
42
14
|
@logger.info("Deploying container: #{container.name.to_s.green}")
|
43
15
|
@logger.debug("Deploy dir: #{Indocker.deploy_dir}")
|
@@ -46,14 +18,14 @@ class Indocker::DeployContext
|
|
46
18
|
|
47
19
|
container.networks.each do |network|
|
48
20
|
Indocker::Docker.create_network(
|
49
|
-
Indocker::NetworkHelper.name(@configuration.name, network)
|
21
|
+
Indocker::Networks::NetworkHelper.name(@configuration.name, network)
|
50
22
|
)
|
51
23
|
end
|
52
24
|
|
53
25
|
container.volumes.each do |volume|
|
54
26
|
if volume.is_a?(Indocker::Volumes::External)
|
55
27
|
Indocker::Docker.create_volume(
|
56
|
-
Indocker::VolumeHelper.name(@configuration.name, volume)
|
28
|
+
Indocker::Volumes::VolumeHelper.name(@configuration.name, volume)
|
57
29
|
)
|
58
30
|
end
|
59
31
|
end
|
@@ -109,13 +109,15 @@ class Indocker::DeploymentChecker
|
|
109
109
|
{ missing_containers: total_missing_containers, invalid_containers: total_invalid_containers }
|
110
110
|
end
|
111
111
|
|
112
|
-
def launched?(container_name, configuration:, servers:)
|
112
|
+
def launched?(container_name, configuration:, servers: nil)
|
113
113
|
container = Indocker.containers.detect { |c| c.name == container_name.to_sym }
|
114
114
|
hostnames = (container.get_start_option(:scale) || 1).times.map do |number|
|
115
115
|
Indocker::ContainerHelper.hostname(configuration.name, container, number)
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
servers ||= container.servers.map(&:name)
|
119
|
+
|
120
|
+
result = run(configuration: configuration, servers: container.servers.map(&:name), only_containers: [container.name])
|
119
121
|
result[:missing_containers].empty?
|
120
122
|
end
|
121
123
|
end
|
@@ -159,7 +159,7 @@ class Indocker::DockerRunArgs
|
|
159
159
|
if volume.is_a?(Indocker::Volumes::Local)
|
160
160
|
args.push("-v #{volume.local_path}:#{volume.path}")
|
161
161
|
elsif volume.is_a?(Indocker::Volumes::External)
|
162
|
-
name = Indocker::VolumeHelper.name(configuration.name, volume)
|
162
|
+
name = Indocker::Volumes::VolumeHelper.name(configuration.name, volume)
|
163
163
|
args.push("-v #{name}:#{volume.path}")
|
164
164
|
elsif volume.is_a?(Indocker::Volumes::Repository)
|
165
165
|
repository = configuration.repositories.fetch(volume.repository_name) do
|
@@ -173,7 +173,7 @@ class Indocker::DockerRunArgs
|
|
173
173
|
end
|
174
174
|
|
175
175
|
container.networks.each do |network|
|
176
|
-
name = Indocker::NetworkHelper.name(configuration.name, network)
|
176
|
+
name = Indocker::Networks::NetworkHelper.name(configuration.name, network)
|
177
177
|
args.push("--network #{name}")
|
178
178
|
end
|
179
179
|
|
@@ -2,7 +2,7 @@ require 'timeout'
|
|
2
2
|
require 'benchmark'
|
3
3
|
require 'tempfile'
|
4
4
|
|
5
|
-
class Indocker::ConfigurationDeployer
|
5
|
+
class Indocker::Launchers::ConfigurationDeployer
|
6
6
|
REMOTE_OPERATION_TIMEOUT = 60
|
7
7
|
|
8
8
|
def initialize(logger:, global_logger:)
|
@@ -14,13 +14,11 @@ class Indocker::ConfigurationDeployer
|
|
14
14
|
@progress = Indocker::DeploymentProgress.new(
|
15
15
|
Indocker.logger.level == Logger::DEBUG ? nil : Logger.new(STDOUT)
|
16
16
|
)
|
17
|
+
@compiled_images = Hash.new(false)
|
17
18
|
end
|
18
19
|
|
19
20
|
# Launch deployment & measure the benchmark
|
20
21
|
def run(configuration:, deployment_policy:)
|
21
|
-
build_context_pool = nil
|
22
|
-
deployer = nil
|
23
|
-
|
24
22
|
time = Benchmark.realtime do
|
25
23
|
if deployment_policy.force_restart
|
26
24
|
@logger.warn("WARNING. All containers will be forced to restart.")
|
@@ -45,13 +43,12 @@ class Indocker::ConfigurationDeployer
|
|
45
43
|
def run!(configuration:, deployment_policy:)
|
46
44
|
containers = find_containers_to_deploy(configuration, deployment_policy)
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
cloner = Indocker::Repositories::Cloner.new(configuration, @logger)
|
47
|
+
build_server_pool = Indocker::ServerPools::BuildServerPool.new(configuration: configuration, logger: @logger)
|
50
48
|
deployer = Indocker::ContainerDeployer.new(configuration: configuration, logger: @logger)
|
51
|
-
|
49
|
+
|
52
50
|
@global_logger.info("Establishing ssh sessions to all servers...")
|
53
|
-
|
54
|
-
deployer.create_sessions!
|
51
|
+
build_server_pool.create_sessions!
|
55
52
|
|
56
53
|
build_servers = configuration
|
57
54
|
.build_servers
|
@@ -83,24 +80,24 @@ class Indocker::ConfigurationDeployer
|
|
83
80
|
remote_operations = sync_env_files(deploy_servers, configuration.env_files)
|
84
81
|
wait_remote_operations(remote_operations)
|
85
82
|
|
86
|
-
remote_operations = pull_repositories(
|
83
|
+
remote_operations = pull_repositories(cloner, build_servers, configuration.repositories)
|
87
84
|
wait_remote_operations(remote_operations)
|
88
85
|
|
89
|
-
remote_operations = sync_artifacts(
|
86
|
+
remote_operations = sync_artifacts(cloner, configuration.artifact_servers)
|
90
87
|
wait_remote_operations(remote_operations)
|
91
88
|
|
92
89
|
update_crontab_redeploy_rules(configuration, build_servers.first)
|
93
90
|
|
94
91
|
containers.uniq.each do |container|
|
95
92
|
recursively_deploy_container(
|
96
|
-
configuration,
|
97
|
-
deployer,
|
98
|
-
|
99
|
-
container,
|
100
|
-
containers,
|
101
|
-
deployment_policy.skip_build,
|
102
|
-
deployment_policy.skip_deploy,
|
103
|
-
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,
|
104
101
|
deployment_policy.skip_force_restart
|
105
102
|
)
|
106
103
|
end
|
@@ -109,7 +106,7 @@ class Indocker::ConfigurationDeployer
|
|
109
106
|
.list
|
110
107
|
.each { |t| t.join if t != Thread.current }
|
111
108
|
ensure
|
112
|
-
|
109
|
+
build_server_pool.close_sessions if build_server_pool
|
113
110
|
deployer.close_sessions if deployer
|
114
111
|
end
|
115
112
|
|
@@ -130,7 +127,7 @@ class Indocker::ConfigurationDeployer
|
|
130
127
|
|
131
128
|
def find_containers_to_deploy(configuration, deployment_policy)
|
132
129
|
load_enabled_containers(configuration)
|
133
|
-
|
130
|
+
|
134
131
|
containers = []
|
135
132
|
|
136
133
|
deployment_policy.deploy_tags.each do |tag|
|
@@ -261,23 +258,25 @@ class Indocker::ConfigurationDeployer
|
|
261
258
|
def collect_soft_dependent_containers(containers, configuration)
|
262
259
|
result = containers
|
263
260
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
end
|
269
|
-
end.flatten
|
261
|
+
soft_dependent_containers = containers
|
262
|
+
.map(&:soft_dependent_containers)
|
263
|
+
.flatten
|
264
|
+
.uniq(&:name)
|
270
265
|
|
266
|
+
result += soft_dependent_containers.select do |container|
|
267
|
+
configuration.enabled_containers.include?(container.name) &&
|
268
|
+
!Indocker.launched?(container.name)
|
269
|
+
end
|
271
270
|
|
272
|
-
result
|
271
|
+
result
|
273
272
|
end
|
274
273
|
|
275
|
-
def compile_image(configuration, image,
|
276
|
-
return if
|
274
|
+
def compile_image(configuration, image, build_server)
|
275
|
+
return if @compiled_images[image]
|
277
276
|
|
278
277
|
image.dependent_images.each do |dependent_image|
|
279
|
-
next if
|
280
|
-
compile_image(configuration, dependent_image,
|
278
|
+
next if @compiled_images[image]
|
279
|
+
compile_image(configuration, dependent_image, build_server)
|
281
280
|
end
|
282
281
|
|
283
282
|
compiler = Indocker::Images::ImageCompiler.new
|
@@ -287,37 +286,35 @@ class Indocker::ConfigurationDeployer
|
|
287
286
|
result = nil
|
288
287
|
|
289
288
|
time = Benchmark.realtime do
|
290
|
-
result =
|
291
|
-
.
|
292
|
-
|
293
|
-
|
289
|
+
result = build_server
|
290
|
+
.compile_image_remotely(
|
291
|
+
configuration_name: Indocker.configuration_name,
|
292
|
+
image_name: image.name
|
294
293
|
)
|
295
294
|
end
|
296
295
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
exit 1 if result.exit_code != 0
|
296
|
+
if result.exit_code != 0
|
297
|
+
exit 1
|
298
|
+
end
|
302
299
|
|
303
300
|
@logger.info("Image compilation completed #{image.name.to_s.green}. Time taken: #{time}")
|
304
301
|
|
305
|
-
|
302
|
+
@compiled_images[image] = true
|
306
303
|
end
|
307
304
|
|
308
|
-
def recursively_deploy_container(configuration, deployer,
|
305
|
+
def recursively_deploy_container(configuration, deployer, build_server_pool, container,
|
309
306
|
containers, skip_build, skip_deploy, force_restart, skip_force_restart)
|
310
307
|
|
311
308
|
container.dependent_containers.each do |container|
|
312
309
|
recursively_deploy_container(
|
313
|
-
configuration,
|
314
|
-
deployer,
|
315
|
-
|
316
|
-
container,
|
317
|
-
containers,
|
318
|
-
skip_build,
|
310
|
+
configuration,
|
311
|
+
deployer,
|
312
|
+
build_server_pool,
|
313
|
+
container,
|
314
|
+
containers,
|
315
|
+
skip_build,
|
319
316
|
skip_deploy,
|
320
|
-
force_restart,
|
317
|
+
force_restart,
|
321
318
|
skip_force_restart
|
322
319
|
)
|
323
320
|
end
|
@@ -327,32 +324,25 @@ class Indocker::ConfigurationDeployer
|
|
327
324
|
@progress.start_building_container(container)
|
328
325
|
|
329
326
|
if !skip_build
|
330
|
-
|
327
|
+
build_server = build_server_pool.get
|
331
328
|
|
332
|
-
|
333
|
-
compile_image(configuration, container.image,
|
334
|
-
|
329
|
+
build_server.set_busy(true)
|
330
|
+
compile_image(configuration, container.image, build_server)
|
331
|
+
build_server.set_busy(false)
|
335
332
|
end
|
336
333
|
|
337
334
|
@progress.finish_building_container(container)
|
338
335
|
|
339
336
|
if !skip_deploy
|
340
|
-
deployer
|
337
|
+
deploy_container(deployer, container, force_restart, skip_force_restart)
|
341
338
|
end
|
342
339
|
end
|
343
340
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
def initialize(thread, server, operation, message = nil)
|
348
|
-
@thread = thread
|
349
|
-
@server = server
|
350
|
-
@operation = operation
|
351
|
-
@message = message
|
352
|
-
end
|
341
|
+
def deploy_container(deployer, container, force_restart, skip_force_restart)
|
342
|
+
deployer.deploy(container, force_restart, skip_force_restart, @progress)
|
353
343
|
end
|
354
344
|
|
355
|
-
def pull_repositories(
|
345
|
+
def pull_repositories(cloner, servers, repositories)
|
356
346
|
@logger.info("Clonning/pulling repositories")
|
357
347
|
|
358
348
|
remote_operations = []
|
@@ -381,10 +371,10 @@ class Indocker::ConfigurationDeployer
|
|
381
371
|
)
|
382
372
|
elsif repository.is_git?
|
383
373
|
@logger.info("Pulling repository #{alias_name.to_s.green} for #{server.user}@#{server.host}")
|
384
|
-
result =
|
374
|
+
result = cloner.clone(session, repository)
|
385
375
|
|
386
376
|
if result.exit_code != 0
|
387
|
-
@logger.error("Repository :#{repository.name} was not
|
377
|
+
@logger.error("Repository :#{repository.name} was not cloned")
|
388
378
|
@logger.error(result.stderr_data)
|
389
379
|
exit 1
|
390
380
|
end
|
@@ -397,57 +387,20 @@ class Indocker::ConfigurationDeployer
|
|
397
387
|
@progress.finish_syncing_repository(server, alias_name)
|
398
388
|
end
|
399
389
|
|
400
|
-
|
390
|
+
Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :repository_pull)
|
401
391
|
end
|
402
392
|
end
|
403
393
|
|
404
394
|
remote_operations
|
405
395
|
end
|
406
396
|
|
407
|
-
def sync_artifacts(
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
artifact_servers.each do |artifact, servers|
|
413
|
-
remote_operations += servers.map do |server|
|
414
|
-
@progress.start_syncing_artifact(server, artifact)
|
415
|
-
|
416
|
-
thread = Thread.new do
|
417
|
-
server.synchronize do
|
418
|
-
session = Indocker::SshSession.new(
|
419
|
-
host: server.host,
|
420
|
-
user: server.user,
|
421
|
-
port: server.port,
|
422
|
-
logger: @logger
|
423
|
-
)
|
424
|
-
|
425
|
-
@logger.info("Pulling git artifact #{artifact.name.to_s.green} for #{server.user}@#{server.host}")
|
426
|
-
result = clonner.clone(session, artifact.repository)
|
427
|
-
|
428
|
-
if result.exit_code != 0
|
429
|
-
@logger.error("Artifact repository :#{artifact.repository.name} was not clonned")
|
430
|
-
@logger.error(result.stderr_data)
|
431
|
-
exit 1
|
432
|
-
end
|
433
|
-
|
434
|
-
source_path = File.join(artifact.repository.clone_path, artifact.source_path)
|
435
|
-
result = session.exec!("mkdir -p #{artifact.target_path}")
|
436
|
-
result = session.exec!("cp -r #{source_path} #{artifact.target_path}")
|
437
|
-
|
438
|
-
if !result.success?
|
439
|
-
@logger.error(result.stdout_data)
|
440
|
-
@logger.error(result.stderr_data)
|
441
|
-
exit 1
|
442
|
-
end
|
443
|
-
|
444
|
-
@progress.finish_syncing_artifact(server, artifact)
|
445
|
-
end
|
446
|
-
end
|
397
|
+
def sync_artifacts(cloner, artifact_servers)
|
398
|
+
artifacts_synchronizer = Indocker::Artifacts::Services::Synchronizer.new(
|
399
|
+
logger: @logger,
|
400
|
+
progress: @progress,
|
401
|
+
)
|
447
402
|
|
448
|
-
|
449
|
-
end
|
450
|
-
end
|
403
|
+
remote_operations = artifacts_synchronizer.call(cloner, artifact_servers)
|
451
404
|
|
452
405
|
remote_operations
|
453
406
|
end
|
@@ -505,7 +458,7 @@ class Indocker::ConfigurationDeployer
|
|
505
458
|
@progress.finish_syncing_binaries(server)
|
506
459
|
end
|
507
460
|
|
508
|
-
|
461
|
+
Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :indocker_sync)
|
509
462
|
end
|
510
463
|
end
|
511
464
|
|
@@ -546,7 +499,7 @@ class Indocker::ConfigurationDeployer
|
|
546
499
|
@progress.finish_syncing_env_file(server, alias_name)
|
547
500
|
end
|
548
501
|
|
549
|
-
|
502
|
+
Indocker::Launchers::DTO::RemoteOperationDTO.new(thread, server, :env_file_sync)
|
550
503
|
end
|
551
504
|
end
|
552
505
|
|