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,87 @@
|
|
1
|
+
require_relative './shell'
|
2
|
+
|
3
|
+
class Indocker::Docker
|
4
|
+
class << self
|
5
|
+
def build(image, build_args = '')
|
6
|
+
Indocker::Shell.command_with_result("docker build #{build_args} --rm=true -t #{image} .", Indocker.logger)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tag(image, tag)
|
10
|
+
Indocker::Shell.command_with_result("docker tag #{image} #{tag}", Indocker.logger)
|
11
|
+
end
|
12
|
+
|
13
|
+
def push(tag)
|
14
|
+
Indocker::Shell.command("docker push #{tag}", Indocker.logger)
|
15
|
+
end
|
16
|
+
|
17
|
+
def pull(url)
|
18
|
+
Indocker::Shell.command("docker pull #{url}", Indocker.logger)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop(container_name, time = 10, skip_errors: false)
|
22
|
+
Indocker::Shell.command("docker stop --time=#{time} #{container_name}", Indocker.logger, skip_errors: skip_errors)
|
23
|
+
rm(container_name, skip_errors: skip_errors)
|
24
|
+
end
|
25
|
+
|
26
|
+
def rm(container_name, skip_errors: false)
|
27
|
+
Indocker::Shell.command("docker rm -fv #{container_name}", Indocker.logger, skip_errors: skip_errors)
|
28
|
+
end
|
29
|
+
|
30
|
+
def run_command(image, args_list, command, service_args)
|
31
|
+
extra_args = ""
|
32
|
+
|
33
|
+
if service_args && service_args.is_a?(Hash)
|
34
|
+
service_args.each do |arg, val|
|
35
|
+
extra_args += " #{arg} #{val}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
"docker run #{args_list} #{image} #{command} #{extra_args}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def run(image, args_list, command, service_args)
|
43
|
+
Indocker::Shell.command(run_command(image, args_list, command, service_args), Indocker.logger)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_volume(name)
|
47
|
+
res = Indocker::Shell.command_with_result("docker volume ls --filter \"name=^#{name}$\" --format \"{{.Name}}\"", Indocker.logger)
|
48
|
+
volume_exist = !res.stdout.empty?
|
49
|
+
|
50
|
+
if !volume_exist
|
51
|
+
Indocker::Shell.command("docker volume create #{name}", Indocker.logger, skip_errors: true)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_network(name)
|
56
|
+
network_exist = false
|
57
|
+
|
58
|
+
res = Indocker::Shell.command_with_result("docker network ls --filter \"name=^#{name}$\" --format \"{{.Name}}\"", Indocker.logger)
|
59
|
+
network_exist = !res.stdout.empty?
|
60
|
+
|
61
|
+
if !network_exist
|
62
|
+
Indocker::Shell.command("docker network create #{name}", Indocker.logger, skip_errors: true)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def image_id(image_url)
|
67
|
+
command = "docker image inspect #{image_url} --format \"{{.Id}}\""
|
68
|
+
|
69
|
+
res = Indocker::Shell.command_with_result(command, Indocker.logger)
|
70
|
+
res.stdout
|
71
|
+
end
|
72
|
+
|
73
|
+
def container_id_by_name(container_name, only_healthy: false)
|
74
|
+
health_args = if only_healthy
|
75
|
+
'--filter="health=healthy"'
|
76
|
+
end
|
77
|
+
|
78
|
+
command = "docker ps -a #{health_args} --filter=\"status=running\" --filter \"name=#{container_name}$\" -q"
|
79
|
+
|
80
|
+
id = nil
|
81
|
+
|
82
|
+
res = Indocker::Shell.command_with_result(command, Indocker.logger)
|
83
|
+
|
84
|
+
res.stdout.empty? ? nil : res.stdout
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
class Indocker::DockerRunArgs
|
2
|
+
DEFAULT_LOG_MAX_SIZE = "400m"
|
3
|
+
DEFAULT_LOG_MAX_FILE = "2"
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def get(container, configuration, number)
|
7
|
+
args = []
|
8
|
+
restart = container.get_start_option(:restart)
|
9
|
+
|
10
|
+
if restart
|
11
|
+
args.push("--restart #{restart}")
|
12
|
+
end
|
13
|
+
|
14
|
+
env_files = container.get_start_option(:env_files)
|
15
|
+
|
16
|
+
if env_files
|
17
|
+
env_files = env_files.is_a?(Array) ? env_files : [env_files]
|
18
|
+
|
19
|
+
env_files.each do |val|
|
20
|
+
env_file = configuration.env_files.fetch(val) do
|
21
|
+
Indocker.logger.error("env file :#{val} for container :#{container.name} is not specified in configuration :#{configuration.name}")
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
path = Indocker::EnvFileHelper.path(env_file)
|
26
|
+
|
27
|
+
if !File.exists?(path)
|
28
|
+
raise ArgumentError.new("env file not found: #{path}")
|
29
|
+
end
|
30
|
+
|
31
|
+
args.push("--env-file #{path}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
expose = container.get_start_option(:expose)
|
36
|
+
|
37
|
+
if expose
|
38
|
+
expose = expose.is_a?(Array) ? expose : [expose]
|
39
|
+
|
40
|
+
expose.each do |val|
|
41
|
+
args.push("--expose #{val}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
ports = container.get_start_option(:ports)
|
46
|
+
|
47
|
+
if ports
|
48
|
+
ports = ports.is_a?(Array) ? ports : [ports]
|
49
|
+
|
50
|
+
ports.each do |val|
|
51
|
+
args.push("--publish #{val}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
environment = container.get_start_option(:environment)
|
56
|
+
|
57
|
+
if environment
|
58
|
+
environment.each do |key, val|
|
59
|
+
args.push("--env #{key}=#{val}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
sysctl = container.get_start_option(:sysctl)
|
64
|
+
|
65
|
+
if sysctl
|
66
|
+
Array(sysctl).each do |val|
|
67
|
+
args.push("--sysctl #{val}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if container.is_daemonized?
|
72
|
+
args.push("--detach")
|
73
|
+
end
|
74
|
+
|
75
|
+
hostname = Indocker::ContainerHelper.hostname(configuration.name, container, number)
|
76
|
+
args.push("--hostname #{hostname}")
|
77
|
+
args.push("--name #{hostname}")
|
78
|
+
|
79
|
+
read_only = container.get_start_option(:read_only) || false
|
80
|
+
|
81
|
+
if read_only
|
82
|
+
args.push("--read-only")
|
83
|
+
end
|
84
|
+
|
85
|
+
labels = container.get_start_option(:labels) || []
|
86
|
+
|
87
|
+
labels += container.tags
|
88
|
+
labels.uniq!
|
89
|
+
|
90
|
+
labels.each do |label|
|
91
|
+
args.push("--label #{label}")
|
92
|
+
end
|
93
|
+
|
94
|
+
stop_timeout = container.get_start_option(:stop_timeout)
|
95
|
+
|
96
|
+
if stop_timeout
|
97
|
+
args.push("--stop-timeout #{stop_timeout}")
|
98
|
+
end
|
99
|
+
|
100
|
+
add_hosts = container.get_start_option(:add_hosts) || []
|
101
|
+
|
102
|
+
add_hosts.each do |host|
|
103
|
+
args.push("--add-host #{host}")
|
104
|
+
end
|
105
|
+
|
106
|
+
mounts = container.get_start_option(:mounts) || []
|
107
|
+
|
108
|
+
mounts.each do |mount|
|
109
|
+
args.push("--mount #{mount}")
|
110
|
+
end
|
111
|
+
|
112
|
+
nets = container.get_start_option(:nets) || []
|
113
|
+
|
114
|
+
nets.each do |net|
|
115
|
+
args.push("--net #{net}")
|
116
|
+
end
|
117
|
+
|
118
|
+
user = container.get_start_option(:user)
|
119
|
+
|
120
|
+
if user
|
121
|
+
args.push("--user #{user}")
|
122
|
+
end
|
123
|
+
|
124
|
+
max_size = container.get_start_option(:max_size) || DEFAULT_LOG_MAX_SIZE
|
125
|
+
|
126
|
+
if max_size
|
127
|
+
args.push("--log-opt max-size=#{max_size}")
|
128
|
+
end
|
129
|
+
|
130
|
+
max_file = container.get_start_option(:max_file) || DEFAULT_LOG_MAX_FILE
|
131
|
+
|
132
|
+
if max_file
|
133
|
+
args.push("--log-opt max-file=#{max_file}")
|
134
|
+
end
|
135
|
+
|
136
|
+
health = container.get_start_option(:health) || {}
|
137
|
+
|
138
|
+
if !health.is_a?(Hash)
|
139
|
+
raise ArgumentError.new("health should be a Hash for container :#{container.name}")
|
140
|
+
end
|
141
|
+
|
142
|
+
if health.has_key?(:cmd)
|
143
|
+
args.push("--health-cmd \"#{health[:cmd]}\"")
|
144
|
+
end
|
145
|
+
|
146
|
+
if health.has_key?(:interval)
|
147
|
+
args.push("--health-interval #{health[:interval]}")
|
148
|
+
end
|
149
|
+
|
150
|
+
if health.has_key?(:retries)
|
151
|
+
args.push("--health-retries #{health[:retries]}")
|
152
|
+
end
|
153
|
+
|
154
|
+
if health.has_key?(:timeout)
|
155
|
+
args.push("--health-timeout #{health[:timeout]}")
|
156
|
+
end
|
157
|
+
|
158
|
+
container.volumes.each do |volume|
|
159
|
+
if volume.is_a?(Indocker::Volumes::Local)
|
160
|
+
args.push("-v #{volume.local_path}:#{volume.path}")
|
161
|
+
elsif volume.is_a?(Indocker::Volumes::External)
|
162
|
+
name = Indocker::VolumeHelper.name(configuration.name, volume)
|
163
|
+
args.push("-v #{name}:#{volume.path}")
|
164
|
+
elsif volume.is_a?(Indocker::Volumes::Repository)
|
165
|
+
repository = configuration.repositories.fetch(volume.repository_name) do
|
166
|
+
raise ArgumentError.new("specified repository :#{volume.repository_name} for volume :#{volume.name} was not found")
|
167
|
+
end
|
168
|
+
|
169
|
+
args.push("-v #{File.join(repository.clone_path)}:#{volume.path}:cached")
|
170
|
+
else
|
171
|
+
raise NotImplementedError.new("unsupported volume type: #{volume.inspect}")
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
container.networks.each do |network|
|
176
|
+
name = Indocker::NetworkHelper.name(configuration.name, network)
|
177
|
+
args.push("--network #{name}")
|
178
|
+
end
|
179
|
+
|
180
|
+
args
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Indocker::EnvFileHelper
|
2
|
+
ENV_FILES_FOLDER = 'env_files'.freeze
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def path(env_file)
|
6
|
+
File.expand_path(File.join(folder, File.basename(env_file.path)))
|
7
|
+
end
|
8
|
+
|
9
|
+
def folder
|
10
|
+
File.join(Indocker.deploy_dir, ENV_FILES_FOLDER)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
class Indocker::Images::Image
|
2
|
+
attr_reader :name
|
3
|
+
attr_reader :dependent_images
|
4
|
+
attr_reader :build_args
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
@dependent_images = []
|
9
|
+
@build_args = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def image_name
|
13
|
+
"#{@name}_image"
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_tag(tag)
|
17
|
+
@tag = tag
|
18
|
+
end
|
19
|
+
|
20
|
+
def tag
|
21
|
+
@tag || (raise ArgumentError.new("tag is not set for image :#{@name}"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_build_args(opts)
|
25
|
+
@build_args = opts
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_registry(registry)
|
29
|
+
@registry = registry
|
30
|
+
end
|
31
|
+
|
32
|
+
def registry
|
33
|
+
@registry || (raise ArgumentError.new("registry is not set for image :#{@name}"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_dockerfile(path)
|
37
|
+
@dockerfile = path
|
38
|
+
end
|
39
|
+
|
40
|
+
def dockerfile
|
41
|
+
@dockerfile || (raise ArgumentError.new("Dockerfile path is not set for image :#{@name}"))
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_build_context(path)
|
45
|
+
@build_context = path
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_context
|
49
|
+
@build_context
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_before_build(proc)
|
53
|
+
@before_build = proc
|
54
|
+
end
|
55
|
+
|
56
|
+
def before_build
|
57
|
+
@before_build
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_after_build(proc)
|
61
|
+
@after_build = proc
|
62
|
+
end
|
63
|
+
|
64
|
+
def after_build
|
65
|
+
@after_build
|
66
|
+
end
|
67
|
+
|
68
|
+
def registry_url
|
69
|
+
url = if registry.is_local?
|
70
|
+
File.join(registry.repository_name.to_s, image_name)
|
71
|
+
else
|
72
|
+
File.join(registry.url, registry.repository_name.to_s, image_name)
|
73
|
+
end
|
74
|
+
|
75
|
+
"#{url}:#{tag}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def local_registry_url
|
79
|
+
url = File.join(registry.repository_name.to_s, image_name)
|
80
|
+
"#{url}:#{tag}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_dependent_image(image)
|
84
|
+
@dependent_images.push(image) if !@dependent_images.include?(image)
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class Indocker::Images::ImageBuilder
|
2
|
+
attr_reader :image
|
3
|
+
|
4
|
+
def initialize(name:, configuration:, dir:)
|
5
|
+
@configuration = configuration
|
6
|
+
@image = Indocker::Images::Image.new(name)
|
7
|
+
dockerfile = File.join(dir, 'Dockerfile')
|
8
|
+
|
9
|
+
if File.exists?(dockerfile)
|
10
|
+
@image.set_dockerfile(dockerfile)
|
11
|
+
end
|
12
|
+
|
13
|
+
build_context = File.join(dir, 'build_context')
|
14
|
+
|
15
|
+
if Dir.exist?(build_context)
|
16
|
+
@image.set_build_context(build_context)
|
17
|
+
end
|
18
|
+
|
19
|
+
@image.set_tag('latest')
|
20
|
+
@configuration.add_image(@image)
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_args(opts)
|
24
|
+
@image.set_build_args(opts)
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def registry(name)
|
29
|
+
registry = @configuration.registries.fetch(name) do
|
30
|
+
raise ArgumentError.new("registry with alias name :#{name} is not defined in configuration :#{@configuration.name}")
|
31
|
+
end
|
32
|
+
|
33
|
+
@image.set_registry(registry)
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def dockerfile(path)
|
38
|
+
if !File.exists?(path)
|
39
|
+
raise ArgumentError.new("Dockerfile was not found in #{path}")
|
40
|
+
end
|
41
|
+
|
42
|
+
@image.set_dockerfile(path)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def depends_on(*image_list)
|
47
|
+
if !image_list.is_a?(Array)
|
48
|
+
image_list = [image_list]
|
49
|
+
end
|
50
|
+
|
51
|
+
image_list.uniq!
|
52
|
+
|
53
|
+
image_list.each do |name|
|
54
|
+
path = Indocker.image_files.fetch(name) do
|
55
|
+
Indocker.logger.error("Dependent image :#{name} was not found in bounded contexts dir for image :#{@image.name}")
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
59
|
+
require path
|
60
|
+
end
|
61
|
+
|
62
|
+
images = image_list.map do |image_sym|
|
63
|
+
@configuration.images.detect do |i|
|
64
|
+
i.name == image_sym
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
images.each do |image|
|
69
|
+
@image.add_dependent_image(image)
|
70
|
+
end
|
71
|
+
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
def tag(tag)
|
76
|
+
@image.set_tag(tag)
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def build_context(path)
|
81
|
+
if !File.directory?(path)
|
82
|
+
raise ArgumentError.new("No directory found in #{path}")
|
83
|
+
end
|
84
|
+
|
85
|
+
@image.set_build_context(path)
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def before_build(proc)
|
90
|
+
@image.set_before_build(proc)
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
def after_build(proc)
|
95
|
+
@image.set_after_build(proc)
|
96
|
+
self
|
97
|
+
end
|
98
|
+
end
|