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
data/bin/indocker
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Indocker::ApplicationInitializer
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :application_initializer
|
5
|
-
|
6
|
-
inject :config_locator
|
7
|
-
inject :docker_api
|
8
|
-
inject :registry_authenticator
|
9
|
-
inject :config
|
10
|
-
|
11
|
-
|
12
|
-
def init_app(current_path, env: :development)
|
13
|
-
docker_api.check_docker_installed!
|
14
|
-
|
15
|
-
require(config_locator.locate(current_path))
|
16
|
-
|
17
|
-
# registry_authenticator.authenticate!()
|
18
|
-
end
|
19
|
-
end
|
data/lib/indocker/cli.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
|
3
|
-
module Indocker
|
4
|
-
module CLI
|
5
|
-
class Application < Thor
|
6
|
-
desc "container:run CONTAINER_NAME", "runs specified container"
|
7
|
-
option :env
|
8
|
-
define_method('container:run') do |name, env = :development|
|
9
|
-
ioc.run_container_handler.perform(
|
10
|
-
name: name,
|
11
|
-
current_path: Dir.pwd,
|
12
|
-
env: env
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "container:stop CONTAINER_NAME", "stops specified container"
|
17
|
-
option :env
|
18
|
-
define_method('container:stop') do |name, env = :development|
|
19
|
-
ioc.stop_container_handler.perform(
|
20
|
-
name: name,
|
21
|
-
current_path: Dir.pwd,
|
22
|
-
env: env
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
module Indocker::Configs
|
2
|
-
class Config
|
3
|
-
attr_reader :scope
|
4
|
-
|
5
|
-
def scope
|
6
|
-
@scope ||= Hash.new()
|
7
|
-
end
|
8
|
-
|
9
|
-
def options
|
10
|
-
scope.reject {|_, opt| opt.is_a?(Indocker::Configs::Config)}.keys
|
11
|
-
end
|
12
|
-
|
13
|
-
def configs
|
14
|
-
scope.select {|_, opt| opt.is_a?(Indocker::Configs::Config)}.keys
|
15
|
-
end
|
16
|
-
|
17
|
-
def set(&block)
|
18
|
-
instance_exec(&block)
|
19
|
-
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
|
-
def option(name, group: nil, type: nil, required: nil)
|
24
|
-
raise Indocker::Errors::ReservedKeywordUsed, name if respond_to?(name.to_sym)
|
25
|
-
|
26
|
-
define_singleton_method(name) do |value = nil, &block|
|
27
|
-
if type == :config and options.include?(name) and block
|
28
|
-
return read_setting(name).set(&block)
|
29
|
-
end
|
30
|
-
|
31
|
-
if block || value
|
32
|
-
write_setting(
|
33
|
-
name: name,
|
34
|
-
value: block || value,
|
35
|
-
group: group,
|
36
|
-
type: type,
|
37
|
-
required: required
|
38
|
-
)
|
39
|
-
else
|
40
|
-
read_setting(name)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def config(name, group: :default, &block)
|
46
|
-
raise Indocker::Errors::ReservedKeywordUsed, name if respond_to?(name.to_sym)
|
47
|
-
|
48
|
-
subconfiguration = Indocker::Configs::Config.new
|
49
|
-
subconfiguration.instance_exec(&block)
|
50
|
-
|
51
|
-
option(name, group: group, type: :config)
|
52
|
-
send(name, subconfiguration)
|
53
|
-
|
54
|
-
subconfiguration
|
55
|
-
end
|
56
|
-
|
57
|
-
def hash_config(hash_config_name, group: :default, &hash_config_block)
|
58
|
-
raise Indocker::Errors::ReservedKeywordUsed, hash_config_name if respond_to?(hash_config_name.to_sym)
|
59
|
-
|
60
|
-
define_singleton_method(hash_config_name) do |name, &self_block|
|
61
|
-
config = config(name, &hash_config_block)
|
62
|
-
config.set(&self_block)
|
63
|
-
|
64
|
-
config
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def read_setting(name)
|
71
|
-
read_value = scope.has_key?(name.intern) ? scope[name.intern].value : nil
|
72
|
-
|
73
|
-
read_value.is_a?(Proc) ? read_value.call : read_value
|
74
|
-
end
|
75
|
-
|
76
|
-
def write_setting(name:, value:, group:, type:, required:)
|
77
|
-
new_option = Option.new(
|
78
|
-
name: name,
|
79
|
-
value: value,
|
80
|
-
group: group,
|
81
|
-
required: required,
|
82
|
-
type: type
|
83
|
-
)
|
84
|
-
|
85
|
-
new_option.validate!
|
86
|
-
|
87
|
-
scope[name.intern] = new_option
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
def method_missing(method, *args, &block)
|
92
|
-
raise "Undefined keyword #{method.inspect} for Indocker configuration file"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
class Option
|
97
|
-
attr_reader :value, :required, :type, :group
|
98
|
-
|
99
|
-
def initialize(name:, value:, required: nil, type: nil, group: nil)
|
100
|
-
@name = name
|
101
|
-
@value = value
|
102
|
-
@required = required || false
|
103
|
-
@type = type || :string
|
104
|
-
@group = group || :default
|
105
|
-
end
|
106
|
-
|
107
|
-
def validate!
|
108
|
-
check_required
|
109
|
-
check_type
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def check_required
|
115
|
-
if @required && @value.nil?
|
116
|
-
raise Indocker::Errors::ConfigInitializationError,
|
117
|
-
"Configuration option :#{option} is required"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def check_type
|
122
|
-
value_type = cast_class_to_type(@value)
|
123
|
-
|
124
|
-
if @type != value_type
|
125
|
-
raise Indocker::Errors::ConfigOptionTypeMismatch,
|
126
|
-
"Expected option #{@name.inspect} => #{@value.inspect} to be a #{@type.inspect}, not a #{value_type.inspect}"
|
127
|
-
end
|
128
|
-
|
129
|
-
nil
|
130
|
-
end
|
131
|
-
|
132
|
-
def cast_class_to_type(value)
|
133
|
-
case value
|
134
|
-
when Proc
|
135
|
-
cast_class_to_type(value.call)
|
136
|
-
when TrueClass
|
137
|
-
:boolean
|
138
|
-
when FalseClass
|
139
|
-
:boolean
|
140
|
-
when Indocker::Configs::Config
|
141
|
-
:config
|
142
|
-
else
|
143
|
-
Indocker::StringUtils.underscore(value.class.name).to_sym
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class Indocker::Configs::ConfigFactory
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :config, factory_method: :build
|
5
|
-
|
6
|
-
CONFIG_STRUCTURE = Proc.new do
|
7
|
-
option :namespace, group: :common, type: :symbol
|
8
|
-
option :build_dir, group: :common, type: :pathname
|
9
|
-
|
10
|
-
option :load_env_file, group: :load, type: :array
|
11
|
-
option :load_docker_items, group: :load, type: :array
|
12
|
-
|
13
|
-
config :git, group: :git do
|
14
|
-
option :cache_dir, group: :common, type: :pathname
|
15
|
-
|
16
|
-
hash_config :repo do
|
17
|
-
option :repository
|
18
|
-
option :tag
|
19
|
-
option :branch
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
config :docker, group: :docker do
|
24
|
-
hash_config :registry do
|
25
|
-
option :serveraddress, required: true
|
26
|
-
option :email
|
27
|
-
option :password
|
28
|
-
option :username
|
29
|
-
option :skip_push, type: :boolean
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def build(&block)
|
35
|
-
@configuration ||= Indocker::Configs::Config.new.set(&CONFIG_STRUCTURE)
|
36
|
-
end
|
37
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class Indocker::Configs::Locator
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :config_locator
|
5
|
-
|
6
|
-
ROOT = '/'
|
7
|
-
|
8
|
-
def locate(path)
|
9
|
-
expand_path = potential_config_file File.expand_path(path)
|
10
|
-
|
11
|
-
return expand_path if File.exists?(expand_path)
|
12
|
-
|
13
|
-
raise Indocker::Errors::ConfigFilesDoesNotFound if path == ROOT
|
14
|
-
|
15
|
-
locate(File.dirname(path))
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def potential_config_file(path)
|
21
|
-
File.join(path, '.indocker', 'config.rb')
|
22
|
-
end
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class Indocker::ContainerBuilder
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :container_builder
|
5
|
-
|
6
|
-
inject :container_metadata_repository
|
7
|
-
inject :envs_loader
|
8
|
-
inject :config
|
9
|
-
|
10
|
-
def build(name)
|
11
|
-
container_metadata = container_metadata_repository.get_by_name(name)
|
12
|
-
|
13
|
-
env_metadata = container_metadata.env_files.inject(Indocker::Envs::EnvMetadata.new) do |all, path|
|
14
|
-
all += envs_loader.parse(path)
|
15
|
-
end
|
16
|
-
|
17
|
-
Indocker::DockerAPI::ContainerConfig.new(
|
18
|
-
name: name,
|
19
|
-
repo: container_metadata.repo,
|
20
|
-
tag: container_metadata.tag,
|
21
|
-
exposed_ports: container_metadata.exposed_ports,
|
22
|
-
port_bindings: container_metadata.port_bindings,
|
23
|
-
cmd: container_metadata.command,
|
24
|
-
volumes: container_metadata.volumes,
|
25
|
-
binds: container_metadata.binds,
|
26
|
-
env: env_metadata.to_array + container_metadata.envs
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
|
3
|
-
class Indocker::ContainerDirectivesRunner
|
4
|
-
include SmartIoC::Iocify
|
5
|
-
|
6
|
-
bean :container_directives_runner
|
7
|
-
|
8
|
-
inject :docker_api
|
9
|
-
inject :config
|
10
|
-
|
11
|
-
def run_all(directives)
|
12
|
-
directives.each {|c| run(c)}
|
13
|
-
end
|
14
|
-
|
15
|
-
def run(directive)
|
16
|
-
case directive
|
17
|
-
when Indocker::ContainerDirectives::Network
|
18
|
-
run_network(directive)
|
19
|
-
when Indocker::ContainerDirectives::Ready
|
20
|
-
run_ready(directive)
|
21
|
-
when Indocker::ContainerDirectives::Volume
|
22
|
-
run_volume(directive)
|
23
|
-
else
|
24
|
-
# do nothing
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def run_network(directive)
|
29
|
-
if !docker_api.network_exists?(directive.network_name)
|
30
|
-
docker_api.create_network(directive.network_name)
|
31
|
-
end
|
32
|
-
|
33
|
-
docker_api.add_container_to_network(
|
34
|
-
container_name: directive.container_name,
|
35
|
-
network_name: directive.network_name
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
def run_ready(directive)
|
40
|
-
Timeout::timeout(directive.timeout) do
|
41
|
-
while (!directive.ready_block.call)
|
42
|
-
sleep directive.sleep
|
43
|
-
end
|
44
|
-
end
|
45
|
-
rescue Timeout::Error
|
46
|
-
raise Indocker::Errors::ContainerTimeoutError
|
47
|
-
end
|
48
|
-
|
49
|
-
def run_volume(directive)
|
50
|
-
if !docker_api.volume_exists?(directive.name)
|
51
|
-
docker_api.create_volume(directive.name)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
class Indocker::ContainerDSL
|
2
|
-
attr_reader :directives
|
3
|
-
|
4
|
-
def initialize(context)
|
5
|
-
@context = context
|
6
|
-
@directives = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def method_missing(method, *args)
|
10
|
-
@context.send(method)
|
11
|
-
rescue
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def use(item)
|
18
|
-
case item
|
19
|
-
when Indocker::ImageMetadata
|
20
|
-
from_directive = @directives.detect {|d| d.instance_of?(Indocker::ContainerDirectives::From)}
|
21
|
-
raise Indocker::Errors::ContainerImageAlreadyDefined, from_directive.image if from_directive
|
22
|
-
|
23
|
-
@directives << Indocker::ContainerDirectives::From.new(item.repo, tag: item.tag)
|
24
|
-
when Indocker::Networks::NetworkMetadata
|
25
|
-
@directives << Indocker::ContainerDirectives::Network.new(
|
26
|
-
container_name: @context.container_name,
|
27
|
-
network_name: item.name
|
28
|
-
)
|
29
|
-
when Indocker::Volumes::VolumeMetadata
|
30
|
-
@directives << Indocker::ContainerDirectives::Volume.new(
|
31
|
-
volume_name: item.name
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# TODO: Add contract
|
37
|
-
def mount(volume, to:)
|
38
|
-
@directives << Indocker::ContainerDirectives::Volume.new(
|
39
|
-
name: volume.name,
|
40
|
-
to: to
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
def cmd(command)
|
45
|
-
first_cmd_directive = @directives.detect {|c| c.instance_of?(Indocker::ContainerDirectives::Cmd)}
|
46
|
-
raise Indocker::Errors::DirectiveAlreadyInUse, first_cmd_directive if first_cmd_directive
|
47
|
-
|
48
|
-
@directives << Indocker::ContainerDirectives::Cmd.new(command)
|
49
|
-
end
|
50
|
-
|
51
|
-
def env_file(path)
|
52
|
-
@directives << Indocker::ContainerDirectives::EnvFile.new(path)
|
53
|
-
end
|
54
|
-
|
55
|
-
def env(env_string)
|
56
|
-
@directives << Indocker::ContainerDirectives::Env.new(env_string)
|
57
|
-
end
|
58
|
-
|
59
|
-
def expose(port)
|
60
|
-
@directives << Indocker::ContainerDirectives::Expose.new(path)
|
61
|
-
end
|
62
|
-
|
63
|
-
def ports(ports)
|
64
|
-
container_port, host_port = ports.split(':').map(&:strip)
|
65
|
-
|
66
|
-
@directives << Indocker::ContainerDirectives::Ports.new(
|
67
|
-
container_port: container_port,
|
68
|
-
host_port: host_port
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
|
-
def depends_on(container_metadata)
|
73
|
-
@directives << Indocker::ContainerDirectives::DependsOn.new(container_metadata.name)
|
74
|
-
end
|
75
|
-
|
76
|
-
def ready(sleep:, timeout:, &ready_block)
|
77
|
-
@directives << Indocker::ContainerDirectives::Ready.new(
|
78
|
-
sleep: sleep,
|
79
|
-
timeout: timeout,
|
80
|
-
ready_block: ready_block
|
81
|
-
)
|
82
|
-
end
|
83
|
-
end
|