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,13 @@
|
|
1
|
+
class Indocker::ContainerHelper
|
2
|
+
class << self
|
3
|
+
def hostname(configuration_name, container, number = nil)
|
4
|
+
scale = container.get_start_option(:scale)
|
5
|
+
|
6
|
+
if scale == 1 || number.nil?
|
7
|
+
"#{configuration_name}_#{container.name}"
|
8
|
+
else
|
9
|
+
"#{configuration_name}_#{container.name}_#{number}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Indocker::ContainerRunner
|
2
|
+
def initialize(logger)
|
3
|
+
@logger = logger
|
4
|
+
end
|
5
|
+
|
6
|
+
def run(configuration:, container_name:, force_restart:)
|
7
|
+
path = Indocker.container_files.fetch(container_name) do
|
8
|
+
@logger.error("container #{container_name} was not found in configuration #{configuration.name}")
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
require path
|
13
|
+
|
14
|
+
deploy_context = Indocker::DeployContext.new(
|
15
|
+
logger: @logger,
|
16
|
+
configuration: configuration,
|
17
|
+
server: nil
|
18
|
+
)
|
19
|
+
|
20
|
+
container = configuration.containers.detect { |c| c.name == container_name }
|
21
|
+
deploy_context.deploy(container, force_restart)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
class Indocker::Containers::Container
|
2
|
+
attr_reader :name, :parent_containers, :dependent_containers, :soft_dependent_containers,
|
3
|
+
:volumes, :networks, :servers, :start_command,
|
4
|
+
:before_start_proc, :after_start_proc, :after_deploy_proc,
|
5
|
+
:build_args, :start_options, :redeploy_schedule
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
@daemonize = true
|
10
|
+
@parent_containers = []
|
11
|
+
@dependent_containers = []
|
12
|
+
@soft_dependent_containers = []
|
13
|
+
@volumes = []
|
14
|
+
@networks = []
|
15
|
+
@servers = []
|
16
|
+
@start_options = {}
|
17
|
+
@build_args = {}
|
18
|
+
@redeploy_schedule = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_build_args(opts)
|
22
|
+
@build_args = opts
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_before_start_proc(proc)
|
26
|
+
@before_start_proc = proc
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_after_start_proc(proc)
|
30
|
+
@after_start_proc = proc
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_after_deploy_proc(proc)
|
34
|
+
@after_deploy_proc = proc
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_start_command(name)
|
38
|
+
@start_command = name
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_tags(tag_list)
|
42
|
+
@tags = tag_list
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_scale(count)
|
46
|
+
@start_options[:scale] = count
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_attached
|
50
|
+
@daemonize = false
|
51
|
+
end
|
52
|
+
|
53
|
+
def tags
|
54
|
+
@tags || (raise ArgumentError.new("tags not defined for container :#{@name}"))
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_image(image)
|
58
|
+
@image = image
|
59
|
+
end
|
60
|
+
|
61
|
+
def image
|
62
|
+
@image || (raise ArgumentError.new("image not defined for container :#{@name}"))
|
63
|
+
end
|
64
|
+
|
65
|
+
def servers
|
66
|
+
@servers || (raise ArgumentError.new("servers not defined for container :#{@name}"))
|
67
|
+
end
|
68
|
+
|
69
|
+
def daemonize(flag)
|
70
|
+
@daemonize = flag
|
71
|
+
@attach = false
|
72
|
+
end
|
73
|
+
|
74
|
+
def is_daemonized?
|
75
|
+
@daemonize
|
76
|
+
end
|
77
|
+
|
78
|
+
def set_servers(servers)
|
79
|
+
@servers = servers
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_parent_container(container)
|
83
|
+
@parent_containers.push(container) if !@parent_containers.include?(container)
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_dependent_container(container)
|
87
|
+
container.add_parent_container(self)
|
88
|
+
@dependent_containers.push(container) if !@dependent_containers.include?(container)
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_soft_dependent_container(container)
|
92
|
+
@soft_dependent_containers.push(container) if !@soft_dependent_containers.include?(container)
|
93
|
+
end
|
94
|
+
|
95
|
+
def set_start_options(opts)
|
96
|
+
@start_options = opts
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_start_option(name, default: nil)
|
100
|
+
@start_options.fetch(name) { default }
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_volumes(volumes)
|
104
|
+
@volumes = volumes
|
105
|
+
end
|
106
|
+
|
107
|
+
def set_networks(networks)
|
108
|
+
@networks = networks
|
109
|
+
|
110
|
+
networks.each do |network|
|
111
|
+
network.add_container(self)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def set_redeploy_schedule(schedule)
|
116
|
+
@redeploy_schedule = schedule
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
class Indocker::Containers::ContainerBuilder
|
2
|
+
attr_reader :container
|
3
|
+
|
4
|
+
def initialize(name:, configuration:, container: nil)
|
5
|
+
@container = container || Indocker::Containers::Container.new(name)
|
6
|
+
@configuration = configuration
|
7
|
+
configuration.add_container(@container)
|
8
|
+
end
|
9
|
+
|
10
|
+
def command(name)
|
11
|
+
@container.set_start_command(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_args(opts)
|
15
|
+
raise ArgumentError.new("build args should be a Hash") if !opts.is_a?(Hash)
|
16
|
+
opts = Indocker::HashMerger.deep_merge(@container.build_args, opts) # merge with already defined args
|
17
|
+
@container.set_build_args(opts)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def tags(*tag_list)
|
22
|
+
if !tag_list.is_a?(Array)
|
23
|
+
tag_list = [tag_list]
|
24
|
+
end
|
25
|
+
|
26
|
+
@container.set_tags(tag_list)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def image(name)
|
31
|
+
path = Indocker.image_files[name]
|
32
|
+
|
33
|
+
if !path
|
34
|
+
raise ArgumentError.new("Image :#{name} was not found in bounded contexts folder")
|
35
|
+
else
|
36
|
+
require path
|
37
|
+
end
|
38
|
+
|
39
|
+
image = @configuration.images.detect do |image|
|
40
|
+
image.name == name
|
41
|
+
end
|
42
|
+
|
43
|
+
if !image
|
44
|
+
Indocker.logger.error("image :#{name} was not found in configuration :#{@configuration.name}")
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
@container.set_image(image)
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def servers(*server_list)
|
53
|
+
server_list.uniq!
|
54
|
+
|
55
|
+
extra_servers = server_list - Indocker.servers.map(&:name)
|
56
|
+
|
57
|
+
if !extra_servers.empty?
|
58
|
+
Indocker.logger.error("unrecognized servers #{extra_servers.inspect} for container :#{@container.name} in configuration :#{@configuration.name}")
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
|
62
|
+
servers = Indocker.servers.select {|s| server_list.include?(s.name)}
|
63
|
+
@container.set_servers(servers)
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def networks(*network_list)
|
68
|
+
network_list.uniq!
|
69
|
+
|
70
|
+
networks = Indocker.networks.select do |network|
|
71
|
+
network_list.include?(network.name)
|
72
|
+
end
|
73
|
+
|
74
|
+
extra_networks = network_list - networks.map(&:name)
|
75
|
+
|
76
|
+
if !extra_networks.empty?
|
77
|
+
raise ArgumentError.new("unknown networks: #{extra_networks.inspect} for container :#{@container.name}")
|
78
|
+
end
|
79
|
+
|
80
|
+
@container.set_networks(networks)
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def volumes(*volume_list)
|
85
|
+
volume_list.uniq!
|
86
|
+
|
87
|
+
volumes = Indocker.volumes.select do |volume|
|
88
|
+
volume_list.include?(volume.name)
|
89
|
+
end
|
90
|
+
|
91
|
+
extra_volumes = volume_list - volumes.map(&:name)
|
92
|
+
|
93
|
+
if !extra_volumes.empty?
|
94
|
+
raise Indocker.logger.error("unknown volumes: #{extra_volumes.inspect} for container :#{@container.name}")
|
95
|
+
exit 1
|
96
|
+
end
|
97
|
+
|
98
|
+
@container.set_volumes(volumes)
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
def daemonize(flag)
|
103
|
+
@container.daemonize(flag)
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def depends_on(*container_list)
|
108
|
+
if !container_list.is_a?(Array)
|
109
|
+
container_list = [container_list]
|
110
|
+
end
|
111
|
+
|
112
|
+
container_list.uniq!
|
113
|
+
|
114
|
+
container_list.each do |name|
|
115
|
+
path = Indocker.container_files.fetch(name) do
|
116
|
+
Indocker.logger.error("Dependent container :#{name} was not found in bounded contexts dir for container :#{@container.name}")
|
117
|
+
exit 1
|
118
|
+
end
|
119
|
+
|
120
|
+
require path
|
121
|
+
end
|
122
|
+
|
123
|
+
containers = @configuration.containers.select do |container|
|
124
|
+
container_list.include?(container.name)
|
125
|
+
end
|
126
|
+
|
127
|
+
containers.each do |container|
|
128
|
+
@container.add_dependent_container(container)
|
129
|
+
end
|
130
|
+
|
131
|
+
self
|
132
|
+
end
|
133
|
+
|
134
|
+
def soft_depends_on(*container_list)
|
135
|
+
container_list = Array(container_list).uniq
|
136
|
+
|
137
|
+
container_list.each do |name|
|
138
|
+
path = Indocker.container_files.fetch(name) do
|
139
|
+
Indocker.logger.error("Soft dependent container :#{name} was not found in bounded contexts dir for container :#{@container.name}")
|
140
|
+
exit 1
|
141
|
+
end
|
142
|
+
|
143
|
+
require path
|
144
|
+
end
|
145
|
+
|
146
|
+
containers = @configuration.containers.select do |container|
|
147
|
+
container_list.include?(container.name)
|
148
|
+
end
|
149
|
+
|
150
|
+
containers.each do |container|
|
151
|
+
@container.add_soft_dependent_container(container)
|
152
|
+
end
|
153
|
+
|
154
|
+
self
|
155
|
+
end
|
156
|
+
|
157
|
+
def before_start(proc)
|
158
|
+
container.set_before_start_proc(proc)
|
159
|
+
self
|
160
|
+
end
|
161
|
+
|
162
|
+
def after_start(proc)
|
163
|
+
container.set_after_start_proc(proc)
|
164
|
+
self
|
165
|
+
end
|
166
|
+
|
167
|
+
def after_deploy(proc)
|
168
|
+
container.set_after_deploy_proc(proc)
|
169
|
+
self
|
170
|
+
end
|
171
|
+
|
172
|
+
def start(opts)
|
173
|
+
opts = Indocker::HashMerger.deep_merge(container.start_options, opts)
|
174
|
+
container.set_start_options(opts)
|
175
|
+
self
|
176
|
+
end
|
177
|
+
|
178
|
+
def scale(number)
|
179
|
+
container.set_scale(number)
|
180
|
+
end
|
181
|
+
|
182
|
+
def redeploy_schedule(schedule)
|
183
|
+
container.set_redeploy_schedule(schedule)
|
184
|
+
self
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Indocker::Containers::RestartPolicy
|
4
|
+
TIMESTAMPS_DIR = 'timestamps'
|
5
|
+
|
6
|
+
def initialize(configuration, logger)
|
7
|
+
@configuration = configuration
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def restart?(container, timestamp)
|
12
|
+
file = timestamp_file(container)
|
13
|
+
return true if !File.exists?(file)
|
14
|
+
|
15
|
+
last_timestamp = File.read(file).strip
|
16
|
+
timestamp != last_timestamp
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(container, timestamp)
|
20
|
+
FileUtils.mkdir_p(timestamp_folder)
|
21
|
+
|
22
|
+
File.open(timestamp_file(container), 'w') do |f|
|
23
|
+
f.write(timestamp)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def timestamp_folder
|
30
|
+
timestamp = File.join(File.expand_path(Indocker.deploy_dir), TIMESTAMPS_DIR)
|
31
|
+
end
|
32
|
+
|
33
|
+
def timestamp_file(container)
|
34
|
+
File.join(timestamp_folder, container.name.to_s)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Indocker::ContextArgs
|
2
|
+
attr_reader :parent, :name
|
3
|
+
|
4
|
+
def initialize(name, context_args, parent, container = nil)
|
5
|
+
@name = name
|
6
|
+
@parent = parent
|
7
|
+
@container = container
|
8
|
+
@context_args = context_args
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(name, *args)
|
12
|
+
if args.size > 0
|
13
|
+
raise ArgumentError.new("context args does not accept any arguments")
|
14
|
+
end
|
15
|
+
|
16
|
+
value = @context_args.fetch(name) do
|
17
|
+
Indocker.logger.warn("build arg '#{format_arg(name)}' is not defined#{@container ? " for container :#{@container.name}" : ""}")
|
18
|
+
Indocker.logger.warn("available args: #{@context_args.inspect}")
|
19
|
+
end
|
20
|
+
|
21
|
+
if value.is_a?(Hash)
|
22
|
+
Indocker::ContextArgs.new(name, value, self, @container)
|
23
|
+
else
|
24
|
+
value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def format_arg(name)
|
31
|
+
string = name
|
32
|
+
parent = @parent
|
33
|
+
|
34
|
+
while parent do
|
35
|
+
name = parent.name
|
36
|
+
string = "#{name}.#{string}" if name
|
37
|
+
parent = parent.parent
|
38
|
+
break if !parent
|
39
|
+
end
|
40
|
+
|
41
|
+
string
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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}
|
7
|
+
|
8
|
+
CRONTAB
|
9
|
+
|
10
|
+
LOG_FILE = "/var/log/indocker-redeploy-%{env}.log"
|
11
|
+
COMMAND = "export TERM=xterm;#{Indocker.deploy_dir}/indocker/bin/deploy -C %{env} -f -B -y -c %{container_name}"
|
12
|
+
REDEPLOY_RULE = %Q{%{schedule} echo `date` "- %{command}..." >> %{log_file}; %{command} 1>/dev/null 2>>%{log_file}; echo `date` "- done, exitcode = $?" >> %{log_file}}
|
13
|
+
|
14
|
+
def initialize(configuration:, logger:)
|
15
|
+
@configuration = configuration
|
16
|
+
@logger = logger
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(containers)
|
20
|
+
CRONTAB % {
|
21
|
+
rules: containers.map{ |c| redeploy_rule(c) }.join("\n"),
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def self.env
|
27
|
+
Indocker.configuration_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def env
|
31
|
+
self.class.env
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_file
|
35
|
+
LOG_FILE % {
|
36
|
+
env: env,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def command(container)
|
41
|
+
COMMAND % {
|
42
|
+
env: env,
|
43
|
+
container_name: container.name,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def redeploy_rule(container)
|
48
|
+
REDEPLOY_RULE % {
|
49
|
+
schedule: container.redeploy_schedule,
|
50
|
+
command: command(container),
|
51
|
+
log_file: log_file,
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|