indocker 0.0.6 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +10 -2
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +19 -49
- data/LICENSE.txt +17 -18
- data/README.md +20 -1
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/indocker/bin/deploy +120 -0
- data/example/indocker/bin/remote/compile +72 -0
- data/example/indocker/bin/remote/run +66 -0
- data/example/indocker/bin/utils/configurations.rb +3 -0
- data/example/indocker/bounded_contexts/shared/ruby/Dockerfile +10 -0
- data/example/indocker/bounded_contexts/shared/ruby/container.rb +5 -0
- data/example/indocker/bounded_contexts/shared/ruby/image.rb +3 -0
- data/example/indocker/configurations/dev.rb +9 -0
- data/example/indocker/infrastructure/build_servers.rb +8 -0
- data/example/indocker/infrastructure/networks.rb +1 -0
- data/example/indocker/infrastructure/registries.rb +3 -0
- data/example/indocker/infrastructure/servers.rb +8 -0
- data/example/indocker/setup.rb +24 -0
- data/indocker.gemspec +27 -25
- data/lib/indocker.rb +437 -130
- data/lib/indocker/artifacts/git.rb +25 -0
- data/lib/indocker/build_context.rb +87 -0
- data/lib/indocker/build_context_helper.rb +109 -0
- data/lib/indocker/build_context_pool.rb +36 -0
- data/lib/indocker/build_server.rb +2 -0
- data/lib/indocker/colored_string.rb +33 -0
- data/lib/indocker/concerns/inspectable.rb +12 -0
- data/lib/indocker/configuration_deployer.rb +525 -0
- data/lib/indocker/configurations/configuration.rb +122 -0
- data/lib/indocker/configurations/configuration_builder.rb +250 -0
- data/lib/indocker/configurations/formatters/stdout.rb +36 -0
- data/lib/indocker/container_deployer.rb +73 -0
- data/lib/indocker/container_helper.rb +13 -0
- data/lib/indocker/container_runner.rb +23 -0
- data/lib/indocker/containers/container.rb +118 -0
- data/lib/indocker/containers/container_builder.rb +186 -0
- data/lib/indocker/containers/restart_policy.rb +36 -0
- data/lib/indocker/context_args.rb +43 -0
- data/lib/indocker/crontab_redeploy_rules_builder.rb +54 -0
- data/lib/indocker/deploy_context.rb +126 -0
- data/lib/indocker/deployment_checker.rb +121 -0
- data/lib/indocker/deployment_progress.rb +495 -0
- data/lib/indocker/docker.rb +87 -0
- data/lib/indocker/docker_run_args.rb +183 -0
- data/lib/indocker/env_file_helper.rb +13 -0
- data/lib/indocker/env_files/local.rb +8 -0
- data/lib/indocker/env_files/remote.rb +8 -0
- data/lib/indocker/hash_merger.rb +9 -0
- data/lib/indocker/images/image.rb +86 -0
- data/lib/indocker/images/image_builder.rb +98 -0
- data/lib/indocker/images/image_compiler.rb +68 -0
- data/lib/indocker/images/template_compiler.rb +15 -0
- data/lib/indocker/images/templates_compiler.rb +28 -0
- data/lib/indocker/images_compiler.rb +38 -0
- data/lib/indocker/indocker_helper.rb +9 -0
- data/lib/indocker/network.rb +12 -0
- data/lib/indocker/network_helper.rb +7 -0
- data/lib/indocker/registries/abstract.rb +17 -0
- data/lib/indocker/registries/local.rb +5 -0
- data/lib/indocker/registries/remote.rb +12 -0
- data/lib/indocker/repositories/abstract.rb +25 -0
- data/lib/indocker/repositories/clonner.rb +17 -0
- data/lib/indocker/repositories/git.rb +24 -0
- data/lib/indocker/repositories/local.rb +20 -0
- data/lib/indocker/repositories/no_sync.rb +20 -0
- data/lib/indocker/rsync.rb +52 -0
- data/lib/indocker/server.rb +20 -0
- data/lib/indocker/server_pool.rb +30 -0
- data/lib/indocker/shell.rb +60 -0
- data/lib/indocker/ssh_result_logger.rb +18 -0
- data/lib/indocker/ssh_session.rb +92 -0
- data/lib/indocker/version.rb +1 -1
- data/lib/indocker/volume_helper.rb +7 -0
- data/lib/indocker/volumes/external.rb +8 -0
- data/lib/indocker/volumes/local.rb +9 -0
- data/lib/indocker/volumes/repository.rb +9 -0
- metadata +107 -222
- data/bin/indocker +0 -9
- data/lib/indocker/application_initializer.rb +0 -19
- data/lib/indocker/cli.rb +0 -27
- data/lib/indocker/configs/config.rb +0 -147
- data/lib/indocker/configs/config_factory.rb +0 -37
- data/lib/indocker/configs/config_initializer.rb +0 -9
- data/lib/indocker/configs/locator.rb +0 -23
- data/lib/indocker/container/container_builder.rb +0 -29
- data/lib/indocker/container/container_directives_runner.rb +0 -54
- data/lib/indocker/container/container_dsl.rb +0 -83
- data/lib/indocker/container/container_evaluator.rb +0 -13
- data/lib/indocker/container/container_inspector.rb +0 -26
- data/lib/indocker/container/container_manager.rb +0 -122
- data/lib/indocker/container/container_metadata.rb +0 -112
- data/lib/indocker/container/container_metadata_factory.rb +0 -30
- data/lib/indocker/container/container_metadata_repository.rb +0 -27
- data/lib/indocker/directives/base.rb +0 -17
- data/lib/indocker/directives/container_directives/base.rb +0 -23
- data/lib/indocker/directives/container_directives/cmd.rb +0 -7
- data/lib/indocker/directives/container_directives/depends_on.rb +0 -7
- data/lib/indocker/directives/container_directives/env.rb +0 -7
- data/lib/indocker/directives/container_directives/env_file.rb +0 -7
- data/lib/indocker/directives/container_directives/expose.rb +0 -7
- data/lib/indocker/directives/container_directives/from.rb +0 -14
- data/lib/indocker/directives/container_directives/network.rb +0 -12
- data/lib/indocker/directives/container_directives/ports.rb +0 -15
- data/lib/indocker/directives/container_directives/ready.rb +0 -16
- data/lib/indocker/directives/container_directives/volume.rb +0 -23
- data/lib/indocker/directives/image_directives/base.rb +0 -27
- data/lib/indocker/directives/image_directives/cmd.rb +0 -19
- data/lib/indocker/directives/image_directives/copy.rb +0 -32
- data/lib/indocker/directives/image_directives/docker_cp.rb +0 -20
- data/lib/indocker/directives/image_directives/entrypoint.rb +0 -19
- data/lib/indocker/directives/image_directives/env.rb +0 -9
- data/lib/indocker/directives/image_directives/env_file.rb +0 -19
- data/lib/indocker/directives/image_directives/expose.rb +0 -9
- data/lib/indocker/directives/image_directives/from.rb +0 -36
- data/lib/indocker/directives/image_directives/registry.rb +0 -30
- data/lib/indocker/directives/image_directives/run.rb +0 -17
- data/lib/indocker/directives/image_directives/workdir.rb +0 -9
- data/lib/indocker/directives/partial.rb +0 -21
- data/lib/indocker/docker_api/container_config.rb +0 -121
- data/lib/indocker/docker_api/docker_api.rb +0 -207
- data/lib/indocker/dsl_context.rb +0 -21
- data/lib/indocker/envs/env_metadata.rb +0 -39
- data/lib/indocker/envs/loader.rb +0 -19
- data/lib/indocker/errors.rb +0 -21
- data/lib/indocker/git/git_api.rb +0 -32
- data/lib/indocker/git/git_helper.rb +0 -34
- data/lib/indocker/git/git_service.rb +0 -21
- data/lib/indocker/handlers/container_run.rb +0 -20
- data/lib/indocker/handlers/container_stop.rb +0 -17
- data/lib/indocker/handlers/performable.rb +0 -22
- data/lib/indocker/image/image_builder.rb +0 -54
- data/lib/indocker/image/image_dependencies_manager.rb +0 -47
- data/lib/indocker/image/image_directives_runner.rb +0 -99
- data/lib/indocker/image/image_dockerfile_builder.rb +0 -24
- data/lib/indocker/image/image_dsl.rb +0 -89
- data/lib/indocker/image/image_evaluator.rb +0 -21
- data/lib/indocker/image/image_helper.rb +0 -9
- data/lib/indocker/image/image_metadata.rb +0 -50
- data/lib/indocker/image/image_metadata_factory.rb +0 -31
- data/lib/indocker/image/image_metadata_repository.rb +0 -29
- data/lib/indocker/networks/network_metadata.rb +0 -9
- data/lib/indocker/networks/network_metadata_factory.rb +0 -9
- data/lib/indocker/networks/network_metadata_repository.rb +0 -34
- data/lib/indocker/partial/partial_metadata.rb +0 -8
- data/lib/indocker/partial/partial_metadata_repository.rb +0 -26
- data/lib/indocker/registry/registry_api.rb +0 -46
- data/lib/indocker/registry/registry_helper.rb +0 -20
- data/lib/indocker/registry/registry_service.rb +0 -28
- data/lib/indocker/utils/ioc_container.rb +0 -17
- data/lib/indocker/utils/logger.rb +0 -62
- data/lib/indocker/utils/logger_factory.rb +0 -13
- data/lib/indocker/utils/registry_authenticator.rb +0 -19
- data/lib/indocker/utils/render_namespace.rb +0 -11
- data/lib/indocker/utils/render_util.rb +0 -15
- data/lib/indocker/utils/string_utils.rb +0 -11
- data/lib/indocker/utils/tar_helper.rb +0 -40
- data/lib/indocker/utils/test_logger_factory.rb +0 -9
- data/lib/indocker/volumes/volume_metadata.rb +0 -9
- data/lib/indocker/volumes/volume_metadata_factory.rb +0 -9
- data/lib/indocker/volumes/volume_metadata_repository.rb +0 -34
- data/spec/example/.indocker/config.rb +0 -30
- data/spec/example/.indocker/images_and_containers.rb +0 -25
- data/spec/example/assets/index.css +0 -1
- data/spec/example/assets/index.js +0 -1
- data/spec/fixtures/spec.env +0 -2
- data/spec/indocker/configs/config_factory_spec.rb +0 -18
- data/spec/indocker/configs/config_spec.rb +0 -88
- data/spec/indocker/container/container_builder_spec.rb +0 -67
- data/spec/indocker/container/container_manager_spec.rb +0 -278
- data/spec/indocker/docker_api/container_config_spec.rb +0 -64
- data/spec/indocker/docker_api/docker_api_spec.rb +0 -112
- data/spec/indocker/handlers/container_run_spec.rb +0 -60
- data/spec/indocker/image/image_builder_spec.rb +0 -153
- data/spec/indocker/image/image_directives_runner_spec.rb +0 -141
- data/spec/indocker/image/image_dockerfile_builder_spec.rb +0 -25
- data/spec/indocker/image/image_evaluator_spec.rb +0 -85
- data/spec/spec_helper.rb +0 -68
@@ -0,0 +1,122 @@
|
|
1
|
+
class Indocker::Configurations::Configuration
|
2
|
+
attr_reader :name
|
3
|
+
attr_reader :repositories
|
4
|
+
attr_reader :registries
|
5
|
+
attr_reader :build_servers
|
6
|
+
attr_reader :global_build_args
|
7
|
+
attr_reader :images
|
8
|
+
attr_reader :containers
|
9
|
+
attr_reader :volumes
|
10
|
+
attr_reader :networks
|
11
|
+
attr_reader :env_files
|
12
|
+
attr_reader :artifact_servers
|
13
|
+
attr_reader :confirm_deployment
|
14
|
+
|
15
|
+
def initialize(name)
|
16
|
+
@name = name
|
17
|
+
@repositories = {}
|
18
|
+
@registries = {}
|
19
|
+
@env_files = {}
|
20
|
+
@build_servers = []
|
21
|
+
@images = []
|
22
|
+
@volumes = []
|
23
|
+
@networks = []
|
24
|
+
@containers = []
|
25
|
+
@artifact_servers = {}
|
26
|
+
@confirm_deployment = false
|
27
|
+
end
|
28
|
+
|
29
|
+
def servers
|
30
|
+
@containers.map(&:servers).flatten.uniq
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_artifact_servers(artifact, servers)
|
34
|
+
@artifact_servers[artifact] = servers
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_confirm_deployment(flag)
|
38
|
+
@confirm_deployment = !!flag
|
39
|
+
end
|
40
|
+
|
41
|
+
def container(name)
|
42
|
+
@containers.detect {|c| c.name == name}
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_enabled_containers(list)
|
46
|
+
@enabled_containers = list
|
47
|
+
end
|
48
|
+
|
49
|
+
def enabled_containers
|
50
|
+
@enabled_containers || (raise ArgumentError.new("enabled container list was not specified in configuration"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def container_enabled?(container)
|
54
|
+
@enabled_containers.include?(container.name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_repository(alias_name, repository)
|
58
|
+
if @repositories.has_key?(alias_name)
|
59
|
+
raise ArgumentError.new("alias name :#{alias_name} is already used by repository: #{@repositories[alias_name].inspect}")
|
60
|
+
end
|
61
|
+
|
62
|
+
@repositories[alias_name] = repository
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_registry(alias_name, registry)
|
66
|
+
if @registries.has_key?(alias_name)
|
67
|
+
raise ArgumentError.new("alias name :#{alias_name} is already used by registry: #{@registries[alias_name].inspect}")
|
68
|
+
end
|
69
|
+
|
70
|
+
@registries[alias_name] = registry
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_env_file(alias_name, env_file)
|
74
|
+
if @env_files.has_key?(alias_name)
|
75
|
+
raise ArgumentError.new("alias name :#{alias_name} is already used by env file: #{@env_files[alias_name].inspect}")
|
76
|
+
end
|
77
|
+
|
78
|
+
@env_files[alias_name] = env_file
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_build_server(build_server)
|
82
|
+
if !@build_servers.include?(build_server)
|
83
|
+
@build_servers.push(build_server)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def set_global_build_args(hash)
|
88
|
+
@global_build_args = hash
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_image(image)
|
92
|
+
@images.push(image)
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_container(container)
|
96
|
+
@containers.push(container)
|
97
|
+
end
|
98
|
+
|
99
|
+
def next_build_server
|
100
|
+
@current_position ||= 0
|
101
|
+
build_server = @build_servers[@current_position]
|
102
|
+
@current_position += 1
|
103
|
+
|
104
|
+
if @current_position >= @build_servers.size - 1
|
105
|
+
@current_position = 0
|
106
|
+
end
|
107
|
+
|
108
|
+
build_server
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_dir
|
112
|
+
"/tmp/#{@name}"
|
113
|
+
end
|
114
|
+
|
115
|
+
def hostname(container, number)
|
116
|
+
Indocker::ContainerHelper.hostname(@name, container, number)
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_binding
|
120
|
+
binding
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
class Indocker::Configurations::ConfigurationBuilder
|
2
|
+
attr_reader :repositories
|
3
|
+
attr_reader :registries
|
4
|
+
attr_reader :servers
|
5
|
+
attr_reader :build_servers
|
6
|
+
attr_reader :volumes
|
7
|
+
attr_reader :networks
|
8
|
+
attr_reader :env_files
|
9
|
+
attr_reader :configuration
|
10
|
+
|
11
|
+
def initialize(repositories:, name:, registries:, servers:, build_servers:, volumes:, networks:, env_files:, containers:)
|
12
|
+
@repositories = repositories
|
13
|
+
@registries = registries
|
14
|
+
@servers = servers
|
15
|
+
@volumes = volumes
|
16
|
+
@networks = networks
|
17
|
+
@build_servers = build_servers
|
18
|
+
@env_files = env_files
|
19
|
+
@containers = containers
|
20
|
+
@configuration = Indocker::Configurations::Configuration.new(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def use_repository(name, as:)
|
24
|
+
repository = @repositories.detect do |repo|
|
25
|
+
repo.name == name
|
26
|
+
end
|
27
|
+
|
28
|
+
if !repository
|
29
|
+
raise ArgumentError.new("repository :#{name} was not found")
|
30
|
+
end
|
31
|
+
|
32
|
+
@configuration.set_repository(as, repository)
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def confirm_deployment
|
38
|
+
@configuration.set_confirm_deployment(true)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def artifacts(server_artifacts)
|
43
|
+
if !server_artifacts.is_a?(Hash)
|
44
|
+
Indocker.logger.error("artifacts should be a hash for configuration :#{@configuration.name}")
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
server_artifacts.each do |artifact_name, server_names|
|
49
|
+
artifact = Indocker.artifacts.detect do |a|
|
50
|
+
a.name == artifact_name
|
51
|
+
end
|
52
|
+
|
53
|
+
if !artifact
|
54
|
+
Indocker.logger.error("artifact :#{artifact_name} was not found")
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
|
58
|
+
if @configuration.servers.empty?
|
59
|
+
Indocker.logger.error("artifacts should go after enabled_containers section")
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
|
63
|
+
servers = @configuration.servers.select do |s|
|
64
|
+
server_names.include?(s.name)
|
65
|
+
end
|
66
|
+
|
67
|
+
servers += @configuration.build_servers.select do |s|
|
68
|
+
server_names.include?(s.name)
|
69
|
+
end
|
70
|
+
|
71
|
+
extra_servers = server_names - servers.map(&:name)
|
72
|
+
|
73
|
+
if !extra_servers.empty?
|
74
|
+
Indocker.logger.error("invalid servers #{extra_servers.inspect} provided for artifact :#{artifact_name}")
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
|
78
|
+
@configuration.set_artifact_servers(artifact, servers)
|
79
|
+
end
|
80
|
+
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def use_registry(name, as:)
|
85
|
+
registry = @registries.detect do |r|
|
86
|
+
r.repository_name == name
|
87
|
+
end
|
88
|
+
|
89
|
+
if !registry
|
90
|
+
raise ArgumentError.new("registry :#{name} was not found")
|
91
|
+
end
|
92
|
+
|
93
|
+
@configuration.set_registry(as, registry)
|
94
|
+
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
def use_env_file(name, as:)
|
99
|
+
env_file = @env_files.detect do |ef|
|
100
|
+
ef.name == name
|
101
|
+
end
|
102
|
+
|
103
|
+
if !env_file
|
104
|
+
raise ArgumentError.new("env_file :#{name} was not found")
|
105
|
+
end
|
106
|
+
|
107
|
+
@configuration.set_env_file(as, env_file)
|
108
|
+
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def use_build_server(name)
|
113
|
+
build_server = @build_servers.detect do |bs|
|
114
|
+
bs.name == name
|
115
|
+
end
|
116
|
+
|
117
|
+
if !build_server
|
118
|
+
raise ArgumentError.new("build_server :#{name} was not found")
|
119
|
+
end
|
120
|
+
|
121
|
+
@configuration.add_build_server(build_server)
|
122
|
+
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
def enabled_containers(container_list)
|
127
|
+
containers = container_list.keys
|
128
|
+
extra_containers = containers - Indocker.container_files.keys
|
129
|
+
|
130
|
+
if !extra_containers.empty?
|
131
|
+
Indocker.logger.error("unrecognised containers: #{extra_containers.inspect} for configuration :#{Indocker.configuration.name}")
|
132
|
+
exit 1
|
133
|
+
end
|
134
|
+
|
135
|
+
containers.each do |name|
|
136
|
+
path = Indocker.container_files.fetch(name) do
|
137
|
+
Indocker.logger.error("invalid container name :#{name} provided in enabled containers for configuration :#{@configuration.name}")
|
138
|
+
end
|
139
|
+
|
140
|
+
require path
|
141
|
+
end
|
142
|
+
|
143
|
+
@configuration.set_enabled_containers(containers.map(&:to_sym))
|
144
|
+
|
145
|
+
container_list.each do |container_name, opts|
|
146
|
+
if !opts.is_a?(Hash)
|
147
|
+
Indocker.logger.error("container options should be a Hash for :#{container_name} in configuration :#{@configuration.name}")
|
148
|
+
exit 1
|
149
|
+
end
|
150
|
+
|
151
|
+
count = opts[:scale] || 1
|
152
|
+
|
153
|
+
if count <= 0
|
154
|
+
raise ArgumentError.new("count should be > 0")
|
155
|
+
end
|
156
|
+
|
157
|
+
container = @configuration.containers.detect {|c| c.name == container_name}
|
158
|
+
|
159
|
+
builder = Indocker::Containers::ContainerBuilder
|
160
|
+
.new(name: container.name, configuration: @configuration, container: container)
|
161
|
+
|
162
|
+
builder.scale(count)
|
163
|
+
|
164
|
+
if opts[:build_args]
|
165
|
+
builder.build_args(opts[:build_args])
|
166
|
+
end
|
167
|
+
|
168
|
+
if opts[:start]
|
169
|
+
builder.start(opts[:start])
|
170
|
+
end
|
171
|
+
|
172
|
+
if opts[:redeploy_schedule]
|
173
|
+
builder.redeploy_schedule(opts[:redeploy_schedule])
|
174
|
+
end
|
175
|
+
|
176
|
+
if !opts[:servers] && !opts[:servers_from]
|
177
|
+
Indocker.logger.error("servers or servers_from should be defined for container :#{container_name} in configuration :#{@configuration.name}")
|
178
|
+
exit 1
|
179
|
+
end
|
180
|
+
|
181
|
+
servers = recursively_fetch_servers(container_list, container_name)
|
182
|
+
builder.servers(*servers)
|
183
|
+
end
|
184
|
+
|
185
|
+
self
|
186
|
+
end
|
187
|
+
|
188
|
+
def scale(opts)
|
189
|
+
opts.each do |container_name, count|
|
190
|
+
if count <= 0
|
191
|
+
raise ArgumentError.new("count should be > 0")
|
192
|
+
end
|
193
|
+
|
194
|
+
container = @containers.detect {|c| c.name == container_name}
|
195
|
+
|
196
|
+
if !container
|
197
|
+
Indocker.logger.error("container :#{name} is not presented in enabled containers for configuration :#{@configuration.name}")
|
198
|
+
end
|
199
|
+
|
200
|
+
Indocker::Containers::ContainerBuilder
|
201
|
+
.new(name: container.name, configuration: @configuration, container: container)
|
202
|
+
.scale(count)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def global_build_args(hash)
|
207
|
+
@configuration.set_global_build_args(hash)
|
208
|
+
self
|
209
|
+
end
|
210
|
+
|
211
|
+
private
|
212
|
+
|
213
|
+
def recursively_fetch_servers(container_list, container_name)
|
214
|
+
opts = container_list.fetch(container_name) do
|
215
|
+
Indocker.logger.error("container :#{container_name} is not presented in enabled containers for configuration :#{@configuration.name}")
|
216
|
+
exit 1
|
217
|
+
end
|
218
|
+
|
219
|
+
if !opts[:servers] && !opts[:servers_from]
|
220
|
+
Indocker.logger.error("servers or servers_from should be defined for container :#{container_name} in configuration :#{@configuration.name}")
|
221
|
+
exit 1
|
222
|
+
end
|
223
|
+
|
224
|
+
servers = if opts[:servers_from]
|
225
|
+
if !opts[:servers_from].is_a?(Array)
|
226
|
+
Indocker.logger.error("servers_from should be Array[Symbol] for container :#{container_name} in configuration :#{@configuration.name}")
|
227
|
+
exit 1
|
228
|
+
end
|
229
|
+
|
230
|
+
opts[:servers_from].map do |name|
|
231
|
+
recursively_fetch_servers(container_list, name)
|
232
|
+
end.flatten
|
233
|
+
else
|
234
|
+
[]
|
235
|
+
end
|
236
|
+
|
237
|
+
servers += if opts[:servers]
|
238
|
+
if !opts[:servers].is_a?(Array)
|
239
|
+
Indocker.logger.error("servers should be Array[Symbol] for container :#{container_name} in configuration :#{@configuration.name}")
|
240
|
+
exit 1
|
241
|
+
end
|
242
|
+
|
243
|
+
opts[:servers]
|
244
|
+
else
|
245
|
+
[]
|
246
|
+
end
|
247
|
+
|
248
|
+
servers.uniq
|
249
|
+
end
|
250
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Indocker::ContainerDeployer
|
2
|
+
attr_reader :server_pool
|
3
|
+
|
4
|
+
def initialize(configuration:, logger:)
|
5
|
+
@configuration = configuration
|
6
|
+
@logger = logger
|
7
|
+
|
8
|
+
@server_pool = Indocker::ServerPool.new(
|
9
|
+
configuration: @configuration,
|
10
|
+
logger: logger
|
11
|
+
)
|
12
|
+
|
13
|
+
@deployed_containers = Hash.new(false)
|
14
|
+
@deployed_servers = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def deploy(container, force_restart, skip_force_restart, progress)
|
18
|
+
return if @deployed_containers[container]
|
19
|
+
|
20
|
+
container.servers.each do |server|
|
21
|
+
progress.start_deploying_container(container, server)
|
22
|
+
|
23
|
+
exec_proc = if !container.is_daemonized?
|
24
|
+
Proc.new do |&block|
|
25
|
+
block.call
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Proc.new do |&block|
|
29
|
+
Thread.new do
|
30
|
+
block.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
exec_proc.call do
|
36
|
+
deploy_context = @server_pool.get(server)
|
37
|
+
@logger.info("{timestamp}")
|
38
|
+
@logger.info("Deploying container: #{container.name.to_s.green} to #{server.user}@#{server.host}")
|
39
|
+
|
40
|
+
command_output = @logger.debug? ? "" : " > /dev/null"
|
41
|
+
debug_options = @logger.debug? ? "-d" : ""
|
42
|
+
|
43
|
+
if force_restart && !skip_force_restart.include?(container.name)
|
44
|
+
force_restart_options = force_restart ? "-f" : ""
|
45
|
+
end
|
46
|
+
|
47
|
+
result = deploy_context
|
48
|
+
.session
|
49
|
+
.exec!(
|
50
|
+
"cd #{Indocker::IndockerHelper.indocker_dir} && ./bin/remote/run -C #{Indocker.configuration_name} -c #{container.name} #{debug_options} #{command_output} #{force_restart_options}"
|
51
|
+
)
|
52
|
+
|
53
|
+
Indocker::SshResultLogger
|
54
|
+
.new(@logger)
|
55
|
+
.log(result, "#{container.name.to_s.green} deployment for server #{server.name} failed")
|
56
|
+
|
57
|
+
exit 1 if result.exit_code != 0
|
58
|
+
@logger.info("Container deployment to #{server.user}@#{server.host} finished: #{container.name.to_s.green}")
|
59
|
+
|
60
|
+
deploy_context.close_session
|
61
|
+
progress.finish_deploying_container(container, server)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
@deployed_containers[container] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
def close_sessions
|
69
|
+
@server_pool.close_sessions
|
70
|
+
rescue => e
|
71
|
+
@logger.error("error during closing sessions #{e.inspect}")
|
72
|
+
end
|
73
|
+
end
|