indocker 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +10 -2
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +5 -2
  6. data/Gemfile.lock +17 -49
  7. data/LICENSE.txt +17 -18
  8. data/README.md +33 -1
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/indocker.gemspec +26 -25
  13. data/lib/indocker.rb +429 -130
  14. data/lib/indocker/artifacts/git.rb +25 -0
  15. data/lib/indocker/build_context.rb +87 -0
  16. data/lib/indocker/build_context_helper.rb +109 -0
  17. data/lib/indocker/build_context_pool.rb +36 -0
  18. data/lib/indocker/build_server.rb +2 -0
  19. data/lib/indocker/colored_string.rb +33 -0
  20. data/lib/indocker/concerns/inspectable.rb +12 -0
  21. data/lib/indocker/configuration_deployer.rb +525 -0
  22. data/lib/indocker/configurations/configuration.rb +122 -0
  23. data/lib/indocker/configurations/configuration_builder.rb +250 -0
  24. data/lib/indocker/configurations/formatters/stdout.rb +36 -0
  25. data/lib/indocker/container_deployer.rb +73 -0
  26. data/lib/indocker/container_helper.rb +13 -0
  27. data/lib/indocker/container_runner.rb +23 -0
  28. data/lib/indocker/containers/container.rb +118 -0
  29. data/lib/indocker/containers/container_builder.rb +186 -0
  30. data/lib/indocker/containers/restart_policy.rb +36 -0
  31. data/lib/indocker/context_args.rb +44 -0
  32. data/lib/indocker/crontab_redeploy_rules_builder.rb +54 -0
  33. data/lib/indocker/deploy_context.rb +126 -0
  34. data/lib/indocker/deployment_checker.rb +121 -0
  35. data/lib/indocker/deployment_progress.rb +495 -0
  36. data/lib/indocker/docker.rb +87 -0
  37. data/lib/indocker/docker_run_args.rb +175 -0
  38. data/lib/indocker/env_file_helper.rb +13 -0
  39. data/lib/indocker/env_files/local.rb +8 -0
  40. data/lib/indocker/env_files/remote.rb +8 -0
  41. data/lib/indocker/hash_merger.rb +9 -0
  42. data/lib/indocker/images/image.rb +86 -0
  43. data/lib/indocker/images/image_builder.rb +98 -0
  44. data/lib/indocker/images/image_compiler.rb +68 -0
  45. data/lib/indocker/images/template_compiler.rb +15 -0
  46. data/lib/indocker/images/templates_compiler.rb +28 -0
  47. data/lib/indocker/images_compiler.rb +38 -0
  48. data/lib/indocker/indocker_helper.rb +9 -0
  49. data/lib/indocker/network.rb +12 -0
  50. data/lib/indocker/network_helper.rb +7 -0
  51. data/lib/indocker/registries/abstract.rb +17 -0
  52. data/lib/indocker/registries/local.rb +5 -0
  53. data/lib/indocker/registries/remote.rb +12 -0
  54. data/lib/indocker/repositories/abstract.rb +25 -0
  55. data/lib/indocker/repositories/clonner.rb +15 -0
  56. data/lib/indocker/repositories/git.rb +21 -0
  57. data/lib/indocker/repositories/local.rb +20 -0
  58. data/lib/indocker/repositories/no_sync.rb +20 -0
  59. data/lib/indocker/rsync.rb +52 -0
  60. data/lib/indocker/server.rb +20 -0
  61. data/lib/indocker/server_pool.rb +30 -0
  62. data/lib/indocker/shell.rb +60 -0
  63. data/lib/indocker/ssh_result_logger.rb +18 -0
  64. data/lib/indocker/ssh_session.rb +92 -0
  65. data/lib/indocker/version.rb +1 -1
  66. data/lib/indocker/volume_helper.rb +7 -0
  67. data/lib/indocker/volumes/external.rb +8 -0
  68. data/lib/indocker/volumes/local.rb +9 -0
  69. data/lib/indocker/volumes/repository.rb +9 -0
  70. metadata +88 -230
  71. data/bin/indocker +0 -9
  72. data/lib/indocker/application_initializer.rb +0 -19
  73. data/lib/indocker/cli.rb +0 -27
  74. data/lib/indocker/configs/config.rb +0 -147
  75. data/lib/indocker/configs/config_factory.rb +0 -37
  76. data/lib/indocker/configs/config_initializer.rb +0 -9
  77. data/lib/indocker/configs/locator.rb +0 -23
  78. data/lib/indocker/container/container_builder.rb +0 -29
  79. data/lib/indocker/container/container_directives_runner.rb +0 -54
  80. data/lib/indocker/container/container_dsl.rb +0 -83
  81. data/lib/indocker/container/container_evaluator.rb +0 -13
  82. data/lib/indocker/container/container_inspector.rb +0 -26
  83. data/lib/indocker/container/container_manager.rb +0 -122
  84. data/lib/indocker/container/container_metadata.rb +0 -112
  85. data/lib/indocker/container/container_metadata_factory.rb +0 -30
  86. data/lib/indocker/container/container_metadata_repository.rb +0 -27
  87. data/lib/indocker/directives/base.rb +0 -17
  88. data/lib/indocker/directives/container_directives/base.rb +0 -23
  89. data/lib/indocker/directives/container_directives/cmd.rb +0 -7
  90. data/lib/indocker/directives/container_directives/depends_on.rb +0 -7
  91. data/lib/indocker/directives/container_directives/env.rb +0 -7
  92. data/lib/indocker/directives/container_directives/env_file.rb +0 -7
  93. data/lib/indocker/directives/container_directives/expose.rb +0 -7
  94. data/lib/indocker/directives/container_directives/from.rb +0 -14
  95. data/lib/indocker/directives/container_directives/network.rb +0 -12
  96. data/lib/indocker/directives/container_directives/ports.rb +0 -15
  97. data/lib/indocker/directives/container_directives/ready.rb +0 -16
  98. data/lib/indocker/directives/container_directives/volume.rb +0 -23
  99. data/lib/indocker/directives/image_directives/base.rb +0 -27
  100. data/lib/indocker/directives/image_directives/cmd.rb +0 -19
  101. data/lib/indocker/directives/image_directives/copy.rb +0 -32
  102. data/lib/indocker/directives/image_directives/docker_cp.rb +0 -20
  103. data/lib/indocker/directives/image_directives/entrypoint.rb +0 -19
  104. data/lib/indocker/directives/image_directives/env.rb +0 -9
  105. data/lib/indocker/directives/image_directives/env_file.rb +0 -19
  106. data/lib/indocker/directives/image_directives/expose.rb +0 -9
  107. data/lib/indocker/directives/image_directives/from.rb +0 -36
  108. data/lib/indocker/directives/image_directives/registry.rb +0 -30
  109. data/lib/indocker/directives/image_directives/run.rb +0 -17
  110. data/lib/indocker/directives/image_directives/workdir.rb +0 -9
  111. data/lib/indocker/directives/partial.rb +0 -21
  112. data/lib/indocker/docker_api/container_config.rb +0 -121
  113. data/lib/indocker/docker_api/docker_api.rb +0 -207
  114. data/lib/indocker/dsl_context.rb +0 -21
  115. data/lib/indocker/envs/env_metadata.rb +0 -39
  116. data/lib/indocker/envs/loader.rb +0 -19
  117. data/lib/indocker/errors.rb +0 -21
  118. data/lib/indocker/git/git_api.rb +0 -32
  119. data/lib/indocker/git/git_helper.rb +0 -34
  120. data/lib/indocker/git/git_service.rb +0 -21
  121. data/lib/indocker/handlers/container_run.rb +0 -20
  122. data/lib/indocker/handlers/container_stop.rb +0 -17
  123. data/lib/indocker/handlers/performable.rb +0 -22
  124. data/lib/indocker/image/image_builder.rb +0 -54
  125. data/lib/indocker/image/image_dependencies_manager.rb +0 -47
  126. data/lib/indocker/image/image_directives_runner.rb +0 -99
  127. data/lib/indocker/image/image_dockerfile_builder.rb +0 -24
  128. data/lib/indocker/image/image_dsl.rb +0 -89
  129. data/lib/indocker/image/image_evaluator.rb +0 -21
  130. data/lib/indocker/image/image_helper.rb +0 -9
  131. data/lib/indocker/image/image_metadata.rb +0 -50
  132. data/lib/indocker/image/image_metadata_factory.rb +0 -31
  133. data/lib/indocker/image/image_metadata_repository.rb +0 -29
  134. data/lib/indocker/networks/network_metadata.rb +0 -9
  135. data/lib/indocker/networks/network_metadata_factory.rb +0 -9
  136. data/lib/indocker/networks/network_metadata_repository.rb +0 -34
  137. data/lib/indocker/partial/partial_metadata.rb +0 -8
  138. data/lib/indocker/partial/partial_metadata_repository.rb +0 -26
  139. data/lib/indocker/registry/registry_api.rb +0 -46
  140. data/lib/indocker/registry/registry_helper.rb +0 -20
  141. data/lib/indocker/registry/registry_service.rb +0 -28
  142. data/lib/indocker/utils/ioc_container.rb +0 -17
  143. data/lib/indocker/utils/logger.rb +0 -62
  144. data/lib/indocker/utils/logger_factory.rb +0 -13
  145. data/lib/indocker/utils/registry_authenticator.rb +0 -19
  146. data/lib/indocker/utils/render_namespace.rb +0 -11
  147. data/lib/indocker/utils/render_util.rb +0 -15
  148. data/lib/indocker/utils/string_utils.rb +0 -11
  149. data/lib/indocker/utils/tar_helper.rb +0 -40
  150. data/lib/indocker/utils/test_logger_factory.rb +0 -9
  151. data/lib/indocker/volumes/volume_metadata.rb +0 -9
  152. data/lib/indocker/volumes/volume_metadata_factory.rb +0 -9
  153. data/lib/indocker/volumes/volume_metadata_repository.rb +0 -34
  154. data/spec/example/.indocker/config.rb +0 -30
  155. data/spec/example/.indocker/images_and_containers.rb +0 -25
  156. data/spec/example/assets/index.css +0 -1
  157. data/spec/example/assets/index.js +0 -1
  158. data/spec/fixtures/spec.env +0 -2
  159. data/spec/indocker/configs/config_factory_spec.rb +0 -18
  160. data/spec/indocker/configs/config_spec.rb +0 -88
  161. data/spec/indocker/container/container_builder_spec.rb +0 -67
  162. data/spec/indocker/container/container_manager_spec.rb +0 -278
  163. data/spec/indocker/docker_api/container_config_spec.rb +0 -64
  164. data/spec/indocker/docker_api/docker_api_spec.rb +0 -112
  165. data/spec/indocker/handlers/container_run_spec.rb +0 -60
  166. data/spec/indocker/image/image_builder_spec.rb +0 -153
  167. data/spec/indocker/image/image_directives_runner_spec.rb +0 -141
  168. data/spec/indocker/image/image_dockerfile_builder_spec.rb +0 -25
  169. data/spec/indocker/image/image_evaluator_spec.rb +0 -85
  170. 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,175 @@
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
+ if container.is_daemonized?
64
+ args.push("--detach")
65
+ end
66
+
67
+ hostname = Indocker::ContainerHelper.hostname(configuration.name, container, number)
68
+ args.push("--hostname #{hostname}")
69
+ args.push("--name #{hostname}")
70
+
71
+ read_only = container.get_start_option(:read_only) || false
72
+
73
+ if read_only
74
+ args.push("--read-only")
75
+ end
76
+
77
+ labels = container.get_start_option(:labels) || []
78
+
79
+ labels += container.tags
80
+ labels.uniq!
81
+
82
+ labels.each do |label|
83
+ args.push("--label #{label}")
84
+ end
85
+
86
+ stop_timeout = container.get_start_option(:stop_timeout)
87
+
88
+ if stop_timeout
89
+ args.push("--stop-timeout #{stop_timeout}")
90
+ end
91
+
92
+ add_hosts = container.get_start_option(:add_hosts) || []
93
+
94
+ add_hosts.each do |host|
95
+ args.push("--add-host #{host}")
96
+ end
97
+
98
+ mounts = container.get_start_option(:mounts) || []
99
+
100
+ mounts.each do |mount|
101
+ args.push("--mount #{mount}")
102
+ end
103
+
104
+ nets = container.get_start_option(:nets) || []
105
+
106
+ nets.each do |net|
107
+ args.push("--net #{net}")
108
+ end
109
+
110
+ user = container.get_start_option(:user)
111
+
112
+ if user
113
+ args.push("--user #{user}")
114
+ end
115
+
116
+ max_size = container.get_start_option(:max_size) || DEFAULT_LOG_MAX_SIZE
117
+
118
+ if max_size
119
+ args.push("--log-opt max-size=#{max_size}")
120
+ end
121
+
122
+ max_file = container.get_start_option(:max_file) || DEFAULT_LOG_MAX_FILE
123
+
124
+ if max_file
125
+ args.push("--log-opt max-file=#{max_file}")
126
+ end
127
+
128
+ health = container.get_start_option(:health) || {}
129
+
130
+ if !health.is_a?(Hash)
131
+ raise ArgumentError.new("health should be a Hash for container :#{container.name}")
132
+ end
133
+
134
+ if health.has_key?(:cmd)
135
+ args.push("--health-cmd \"#{health[:cmd]}\"")
136
+ end
137
+
138
+ if health.has_key?(:interval)
139
+ args.push("--health-interval #{health[:interval]}")
140
+ end
141
+
142
+ if health.has_key?(:retries)
143
+ args.push("--health-retries #{health[:retries]}")
144
+ end
145
+
146
+ if health.has_key?(:timeout)
147
+ args.push("--health-timeout #{health[:timeout]}")
148
+ end
149
+
150
+ container.volumes.each do |volume|
151
+ if volume.is_a?(Indocker::Volumes::Local)
152
+ args.push("-v #{volume.local_path}:#{volume.path}")
153
+ elsif volume.is_a?(Indocker::Volumes::External)
154
+ name = Indocker::VolumeHelper.name(configuration.name, volume)
155
+ args.push("-v #{name}:#{volume.path}")
156
+ elsif volume.is_a?(Indocker::Volumes::Repository)
157
+ repository = configuration.repositories.fetch(volume.repository_name) do
158
+ raise ArgumentError.new("specified repository :#{volume.repository_name} for volume :#{volume.name} was not found")
159
+ end
160
+
161
+ args.push("-v #{File.join(repository.clone_path)}:#{volume.path}:cached")
162
+ else
163
+ raise NotImplementedError.new("unsupported volume type: #{volume.inspect}")
164
+ end
165
+ end
166
+
167
+ container.networks.each do |network|
168
+ name = Indocker::NetworkHelper.name(configuration.name, network)
169
+ args.push("--network #{name}")
170
+ end
171
+
172
+ args
173
+ end
174
+ end
175
+ 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,8 @@
1
+ class Indocker::EnvFiles::Local
2
+ attr_reader :name, :path
3
+
4
+ def initialize(name, path)
5
+ @name = name
6
+ @path = path
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class Indocker::EnvFiles::Remote
2
+ attr_reader :name, :path
3
+
4
+ def initialize(name, path)
5
+ @name = name
6
+ @path = path
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class Indocker::HashMerger
2
+ def self.deep_merge(source, target)
3
+ merger = proc { |key, v1, v2|
4
+ Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
5
+ }
6
+
7
+ source.merge(target, &merger)
8
+ end
9
+ 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