indocker 0.0.2 → 0.0.5
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +42 -6
- data/bin/indocker +1 -1
- data/indocker.gemspec +4 -0
- data/lib/indocker/application_initializer.rb +1 -12
- data/lib/indocker/cli.rb +10 -0
- data/lib/indocker/configs/config.rb +93 -22
- data/lib/indocker/configs/config_factory.rb +17 -16
- data/lib/indocker/configs/config_initializer.rb +9 -0
- data/lib/indocker/container/container_builder.rb +29 -0
- data/lib/indocker/{directives → container}/container_directives_runner.rb +8 -0
- data/lib/indocker/container/container_dsl.rb +26 -3
- data/lib/indocker/container/container_inspector.rb +26 -0
- data/lib/indocker/container/container_manager.rb +43 -32
- data/lib/indocker/container/container_metadata.rb +31 -26
- data/lib/indocker/container/container_metadata_factory.rb +5 -2
- data/lib/indocker/directives/base.rb +6 -10
- data/lib/indocker/directives/container_directives/base.rb +4 -0
- data/lib/indocker/directives/container_directives/cmd.rb +7 -0
- data/lib/indocker/directives/container_directives/env.rb +7 -0
- data/lib/indocker/directives/container_directives/env_file.rb +3 -3
- data/lib/indocker/directives/container_directives/from.rb +4 -2
- data/lib/indocker/directives/container_directives/ports.rb +11 -4
- data/lib/indocker/directives/container_directives/volume.rb +23 -0
- data/lib/indocker/directives/{docker_directives → image_directives}/base.rb +13 -1
- data/lib/indocker/directives/{docker_directives → image_directives}/cmd.rb +5 -1
- data/lib/indocker/directives/image_directives/copy.rb +32 -0
- data/lib/indocker/directives/{prepare_directives → image_directives}/docker_cp.rb +5 -1
- data/lib/indocker/directives/{docker_directives → image_directives}/entrypoint.rb +5 -1
- data/lib/indocker/directives/image_directives/env.rb +9 -0
- data/lib/indocker/directives/image_directives/env_file.rb +19 -0
- data/lib/indocker/directives/image_directives/expose.rb +9 -0
- data/lib/indocker/directives/image_directives/from.rb +36 -0
- data/lib/indocker/directives/image_directives/registry.rb +30 -0
- data/lib/indocker/directives/image_directives/run.rb +17 -0
- data/lib/indocker/directives/image_directives/workdir.rb +9 -0
- data/lib/indocker/directives/partial.rb +9 -1
- data/lib/indocker/docker_api/container_config.rb +121 -0
- data/lib/indocker/{docker_api.rb → docker_api/docker_api.rb} +79 -52
- data/lib/indocker/dsl_context.rb +4 -0
- data/lib/indocker/envs/env_metadata.rb +4 -0
- data/lib/indocker/errors.rb +5 -1
- data/lib/indocker/git/git_api.rb +32 -0
- data/lib/indocker/git/git_helper.rb +34 -0
- data/lib/indocker/git/git_service.rb +21 -0
- data/lib/indocker/handlers/{run_container.rb → container_run.rb} +4 -13
- data/lib/indocker/handlers/container_stop.rb +17 -0
- data/lib/indocker/handlers/performable.rb +22 -0
- data/lib/indocker/image/image_builder.rb +22 -7
- data/lib/indocker/image/image_dependencies_manager.rb +13 -9
- data/lib/indocker/image/image_directives_runner.rb +99 -0
- data/lib/indocker/image/image_dockerfile_builder.rb +24 -0
- data/lib/indocker/image/image_dsl.rb +38 -18
- data/lib/indocker/image/image_evaluator.rb +1 -1
- data/lib/indocker/image/image_helper.rb +9 -0
- data/lib/indocker/image/image_metadata.rb +9 -9
- data/lib/indocker/image/image_metadata_factory.rb +11 -10
- data/lib/indocker/image/image_metadata_repository.rb +8 -9
- data/lib/indocker/registry/registry_api.rb +46 -0
- data/lib/indocker/registry/registry_helper.rb +20 -0
- data/lib/indocker/registry/registry_service.rb +28 -0
- data/lib/indocker/utils/logger_factory.rb +1 -0
- data/lib/indocker/utils/registry_authenticator.rb +5 -5
- data/lib/indocker/utils/tar_helper.rb +5 -5
- data/lib/indocker/version.rb +1 -1
- data/lib/indocker/volumes/volume_metadata.rb +9 -0
- data/lib/indocker/volumes/volume_metadata_factory.rb +9 -0
- data/lib/indocker/volumes/volume_metadata_repository.rb +34 -0
- data/lib/indocker.rb +56 -27
- data/spec/example/.indocker/config.rb +14 -7
- data/spec/fixtures/spec.env +2 -0
- data/spec/indocker/configs/config_spec.rb +52 -1
- data/spec/indocker/container/container_builder_spec.rb +67 -0
- data/spec/indocker/container/container_manager_spec.rb +177 -129
- data/spec/indocker/docker_api/container_config_spec.rb +64 -0
- data/spec/indocker/{utils → docker_api}/docker_api_spec.rb +38 -13
- data/spec/indocker/handlers/container_run_spec.rb +60 -0
- data/spec/indocker/image/image_builder_spec.rb +64 -26
- data/spec/indocker/image/image_directives_runner_spec.rb +141 -0
- data/spec/indocker/image/image_dockerfile_builder_spec.rb +25 -0
- data/spec/indocker/image/image_evaluator_spec.rb +29 -9
- data/spec/spec_helper.rb +38 -16
- metadata +108 -32
- data/lib/indocker/directives/docker_directives/copy.rb +0 -27
- data/lib/indocker/directives/docker_directives/env.rb +0 -5
- data/lib/indocker/directives/docker_directives/from.rb +0 -30
- data/lib/indocker/directives/docker_directives/run.rb +0 -5
- data/lib/indocker/directives/docker_directives/workdir.rb +0 -5
- data/lib/indocker/directives/image_directives_runner.rb +0 -120
- data/lib/indocker/directives/prepare_directives/base.rb +0 -6
- data/lib/indocker/envs/manager.rb +0 -30
- data/lib/indocker/handlers/base.rb +0 -13
- data/spec/indocker/directives/image_directives_runner_spec.rb +0 -121
- data/spec/indocker/handlers/run_container_spec.rb +0 -107
- data/spec/tmp/indocker_list_container_files/deeper/example3.txt +0 -1
- data/spec/tmp/indocker_list_container_files/deeper/example4.txt +0 -1
- data/spec/tmp/indocker_list_container_files/example1.txt +0 -1
- data/spec/tmp/indocker_list_container_files/example2.txt +0 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
class Indocker::ContainerMetadata
|
|
2
|
-
attr_reader :name
|
|
3
|
-
|
|
4
|
-
HOSTPORT = 'HostPort'
|
|
2
|
+
attr_reader :name, :attach
|
|
5
3
|
|
|
6
4
|
module States
|
|
7
5
|
CREATED = 'created'
|
|
@@ -14,9 +12,10 @@ class Indocker::ContainerMetadata
|
|
|
14
12
|
ALL = [CREATED, RESTARTING, RUNNING, PAUSED, EXITED, DEAD]
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
def initialize(name:, directives:)
|
|
15
|
+
def initialize(name:, directives:, attach: false)
|
|
18
16
|
@name = name
|
|
19
17
|
@directives = directives
|
|
18
|
+
@attach = attach
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
def repo
|
|
@@ -35,36 +34,34 @@ class Indocker::ContainerMetadata
|
|
|
35
34
|
network_directives.map(&:name)
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
def
|
|
39
|
-
|
|
37
|
+
def volumes
|
|
38
|
+
volume_directives.map(&:docker_name)
|
|
40
39
|
end
|
|
41
40
|
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
result = Hash.new
|
|
46
|
-
|
|
47
|
-
expose_directives.each do |d|
|
|
48
|
-
result[d.port.to_s] = {}
|
|
49
|
-
end
|
|
41
|
+
def binds
|
|
42
|
+
volume_directives.map(&:to_hash)
|
|
43
|
+
end
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
def envs
|
|
46
|
+
envs_directives.inject([]) { |all, dir| all.concat dir.env_string }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def env_files
|
|
50
|
+
env_files_directives.map(&:path)
|
|
51
|
+
end
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
def exposed_ports
|
|
54
|
+
expose_directives.map(&:port) + ports_directives.map(&:container_port)
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
def port_bindings
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
result = Hash.new
|
|
58
|
+
ports_directives.map(&:to_hash)
|
|
59
|
+
end
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
end
|
|
61
|
+
def command
|
|
62
|
+
directive = @directives.detect {|c| c.instance_of?(Indocker::ContainerDirectives::Cmd)}
|
|
66
63
|
|
|
67
|
-
|
|
64
|
+
directive ? directive.cmd : nil
|
|
68
65
|
end
|
|
69
66
|
|
|
70
67
|
def container_dependencies
|
|
@@ -89,10 +86,14 @@ class Indocker::ContainerMetadata
|
|
|
89
86
|
@directives.select {|d| d.instance_of?(Indocker::ContainerDirectives::Network)}
|
|
90
87
|
end
|
|
91
88
|
|
|
92
|
-
def
|
|
89
|
+
def env_files_directives
|
|
93
90
|
@directives.select {|d| d.instance_of?(Indocker::ContainerDirectives::EnvFile)}
|
|
94
91
|
end
|
|
95
92
|
|
|
93
|
+
def envs_directives
|
|
94
|
+
@directives.select {|d| d.instance_of?(Indocker::ContainerDirectives::Env)}
|
|
95
|
+
end
|
|
96
|
+
|
|
96
97
|
def expose_directives
|
|
97
98
|
@directives.select {|d| d.instance_of?(Indocker::ContainerDirectives::Expose)}
|
|
98
99
|
end
|
|
@@ -104,4 +105,8 @@ class Indocker::ContainerMetadata
|
|
|
104
105
|
def depends_on_directives
|
|
105
106
|
@directives.select {|d| d.instance_of?(Indocker::ContainerDirectives::DependsOn)}
|
|
106
107
|
end
|
|
108
|
+
|
|
109
|
+
def volume_directives
|
|
110
|
+
@directives.select {|d| d.instance_of?(Indocker::ContainerDirectives::Volume)}
|
|
111
|
+
end
|
|
107
112
|
end
|
|
@@ -8,12 +8,14 @@ class Indocker::ContainerMetadataFactory
|
|
|
8
8
|
inject :image_metadata_repository
|
|
9
9
|
inject :network_metadata_repository
|
|
10
10
|
inject :container_metadata_repository
|
|
11
|
+
inject :volume_metadata_repository
|
|
11
12
|
|
|
12
|
-
def create(name, &definition)
|
|
13
|
+
def create(name, attach: false, &definition)
|
|
13
14
|
context = Indocker::DSLContext.new(
|
|
14
15
|
images: image_metadata_repository,
|
|
15
16
|
networks: network_metadata_repository,
|
|
16
17
|
containers: container_metadata_repository,
|
|
18
|
+
volumes: volume_metadata_repository,
|
|
17
19
|
container_name: name
|
|
18
20
|
)
|
|
19
21
|
|
|
@@ -21,7 +23,8 @@ class Indocker::ContainerMetadataFactory
|
|
|
21
23
|
|
|
22
24
|
Indocker::ContainerMetadata.new(
|
|
23
25
|
name: name.to_s,
|
|
24
|
-
directives: directives
|
|
26
|
+
directives: directives,
|
|
27
|
+
attach: attach
|
|
25
28
|
)
|
|
26
29
|
end
|
|
27
30
|
end
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
module Indocker
|
|
2
2
|
module Directives
|
|
3
3
|
class Base
|
|
4
|
-
def
|
|
5
|
-
|
|
4
|
+
def partial_directive?
|
|
5
|
+
false
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def build_directive?
|
|
13
|
-
self.is_a?(Indocker::DockerDirectives::Base)
|
|
8
|
+
def container_directive?
|
|
9
|
+
false
|
|
14
10
|
end
|
|
15
11
|
|
|
16
|
-
def
|
|
17
|
-
|
|
12
|
+
def image_directive?
|
|
13
|
+
false
|
|
18
14
|
end
|
|
19
15
|
end
|
|
20
16
|
end
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
class Indocker::ContainerDirectives::From < Indocker::ContainerDirectives::Base
|
|
2
|
+
include Indocker::ImageHelper
|
|
3
|
+
|
|
2
4
|
attr_accessor :repo, :tag
|
|
3
5
|
|
|
4
|
-
def initialize(repo, tag: Indocker::
|
|
6
|
+
def initialize(repo, tag: Indocker::ImageHelper::DEFAULT_TAG)
|
|
5
7
|
@repo = repo
|
|
6
8
|
@tag = tag
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
def image
|
|
10
|
-
|
|
12
|
+
full_name(@repo, @tag)
|
|
11
13
|
end
|
|
12
14
|
end
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
class Indocker::ContainerDirectives::Ports < Indocker::ContainerDirectives::Base
|
|
2
|
-
attr_accessor :
|
|
2
|
+
attr_accessor :container_port, :host_port
|
|
3
3
|
|
|
4
|
-
def initialize(
|
|
5
|
-
@
|
|
6
|
-
@host_port
|
|
4
|
+
def initialize(container_port:, host_port:)
|
|
5
|
+
@container_port = container_port
|
|
6
|
+
@host_port = host_port
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_hash
|
|
10
|
+
{
|
|
11
|
+
container_port: @container_port,
|
|
12
|
+
host_port: @host_port
|
|
13
|
+
}
|
|
7
14
|
end
|
|
8
15
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Indocker::ContainerDirectives::Volume < Indocker::ContainerDirectives::Base
|
|
2
|
+
attr_accessor :name, :to
|
|
3
|
+
|
|
4
|
+
def initialize(name:, to:)
|
|
5
|
+
@name = name
|
|
6
|
+
@to = to
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def before_start?
|
|
10
|
+
true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_hash
|
|
14
|
+
{
|
|
15
|
+
name: @name,
|
|
16
|
+
to: @to
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def docker_name
|
|
21
|
+
'/' + @name.to_s.gsub(/(\A\/)/, '')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Indocker
|
|
2
|
-
module
|
|
2
|
+
module ImageDirectives
|
|
3
3
|
class Base < Indocker::Directives::Base
|
|
4
4
|
attr_reader :args
|
|
5
5
|
|
|
@@ -10,6 +10,18 @@ module Indocker
|
|
|
10
10
|
def to_s
|
|
11
11
|
"#{type} #{@args.join(' ')}"
|
|
12
12
|
end
|
|
13
|
+
|
|
14
|
+
def prepare_directive?
|
|
15
|
+
false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build_directive?
|
|
19
|
+
false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def after_build_directive?
|
|
23
|
+
false
|
|
24
|
+
end
|
|
13
25
|
end
|
|
14
26
|
end
|
|
15
27
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Indocker::
|
|
1
|
+
class Indocker::ImageDirectives::Cmd < Indocker::ImageDirectives::Base
|
|
2
2
|
attr_reader :command
|
|
3
3
|
|
|
4
4
|
def initialize(command)
|
|
@@ -12,4 +12,8 @@ class Indocker::DockerDirectives::Cmd < Indocker::DockerDirectives::Base
|
|
|
12
12
|
def type
|
|
13
13
|
'CMD'
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
def build_directive?
|
|
17
|
+
true
|
|
18
|
+
end
|
|
15
19
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Indocker::ImageDirectives::Copy < Indocker::ImageDirectives::Base
|
|
2
|
+
attr_reader :copy_actions, :compile, :locals, :build_dir
|
|
3
|
+
|
|
4
|
+
def initialize(copy_actions:, compile:, locals:, build_dir:)
|
|
5
|
+
@copy_actions = copy_actions
|
|
6
|
+
@compile = compile
|
|
7
|
+
@locals = locals
|
|
8
|
+
@build_dir = build_dir
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def type
|
|
12
|
+
'COPY'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s
|
|
16
|
+
result = []
|
|
17
|
+
|
|
18
|
+
copy_actions.each do |from, to|
|
|
19
|
+
result.push "#{type} #{from} #{to}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
result.join("\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def prepare_directive?
|
|
26
|
+
true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def build_directive?
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Indocker::
|
|
1
|
+
class Indocker::ImageDirectives::DockerCp < Indocker::ImageDirectives::Base
|
|
2
2
|
attr_reader :container_name, :copy_actions, :build_dir
|
|
3
3
|
|
|
4
4
|
def initialize(container_name, build_dir, &block)
|
|
@@ -8,6 +8,10 @@ class Indocker::PrepareDirectives::DockerCp < Indocker::PrepareDirectives::Base
|
|
|
8
8
|
instance_exec &block if block_given?
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
def prepare_directive?
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
11
15
|
private
|
|
12
16
|
|
|
13
17
|
def copy(copy_actions)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Indocker::
|
|
1
|
+
class Indocker::ImageDirectives::Entrypoint < Indocker::ImageDirectives::Base
|
|
2
2
|
attr_reader :command
|
|
3
3
|
|
|
4
4
|
def initialize(command)
|
|
@@ -12,4 +12,8 @@ class Indocker::DockerDirectives::Entrypoint < Indocker::DockerDirectives::Base
|
|
|
12
12
|
def type
|
|
13
13
|
'ENTRYPOINT'
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
def build_directive?
|
|
17
|
+
true
|
|
18
|
+
end
|
|
15
19
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Indocker::ImageDirectives::EnvFile < Indocker::ImageDirectives::Base
|
|
2
|
+
attr_reader :path
|
|
3
|
+
|
|
4
|
+
def initialize(path)
|
|
5
|
+
@path = path
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def type
|
|
9
|
+
'ENV'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_s(env_string)
|
|
13
|
+
"#{type} #{env_string}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def build_directive?
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class Indocker::ImageDirectives::From < Indocker::ImageDirectives::Base
|
|
2
|
+
include Indocker::ImageHelper
|
|
3
|
+
|
|
4
|
+
attr_reader :repo, :tag
|
|
5
|
+
|
|
6
|
+
def initialize(repo_tag, tag: nil)
|
|
7
|
+
case repo_tag
|
|
8
|
+
when String
|
|
9
|
+
@repo = repo_tag.split(':')[0]
|
|
10
|
+
@tag = tag || repo_tag.split(':')[1] || Indocker::ImageHelper::DEFAULT_TAG
|
|
11
|
+
else
|
|
12
|
+
@repo = repo_tag
|
|
13
|
+
@tag = tag || Indocker::ImageHelper::DEFAULT_TAG
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def full_name
|
|
18
|
+
super(@repo, @tag)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def dockerhub_image?
|
|
22
|
+
repo.is_a?(String)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_s
|
|
26
|
+
"#{type} #{full_name}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def type
|
|
30
|
+
'FROM'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def build_directive?
|
|
34
|
+
true
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class Indocker::ImageDirectives::Registry < Indocker::ImageDirectives::Base
|
|
2
|
+
attr_reader :registry, :push, :repo, :tag
|
|
3
|
+
|
|
4
|
+
def initialize(repo:, tag:, registry:, push:)
|
|
5
|
+
@repo = repo.to_s
|
|
6
|
+
@tag = tag.to_s
|
|
7
|
+
@registry = format_registry(registry)
|
|
8
|
+
@push = push
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new_repo
|
|
12
|
+
"#{@registry}/#{@repo}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new_tag
|
|
16
|
+
@tag
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def after_build_directive?
|
|
20
|
+
true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def format_registry(serveraddress)
|
|
26
|
+
serveraddress
|
|
27
|
+
.gsub('http://', '')
|
|
28
|
+
.gsub(/\/\Z/, '')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Indocker::ImageDirectives::Run < Indocker::ImageDirectives::Base
|
|
2
|
+
def type
|
|
3
|
+
'RUN'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def initialize(command)
|
|
7
|
+
@command = command.split("\n").map(&:strip).join(' ')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_s
|
|
11
|
+
"#{type} #{@command}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def build_directive?
|
|
15
|
+
true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class Indocker::Directives::Partial < Indocker::Directives::Base
|
|
2
|
-
attr_reader :name
|
|
2
|
+
attr_reader :name
|
|
3
3
|
|
|
4
4
|
def initialize(name, context, opts = {})
|
|
5
5
|
@name = name
|
|
@@ -10,4 +10,12 @@ class Indocker::Directives::Partial < Indocker::Directives::Base
|
|
|
10
10
|
def to_s
|
|
11
11
|
inspect
|
|
12
12
|
end
|
|
13
|
+
|
|
14
|
+
def context
|
|
15
|
+
@context + Indocker::DSLContext.new(@opts)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def partial_directive?
|
|
19
|
+
true
|
|
20
|
+
end
|
|
13
21
|
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
class Indocker::DockerAPI::ContainerConfig
|
|
2
|
+
include Indocker::ImageHelper
|
|
3
|
+
|
|
4
|
+
attr_reader :image, :name, :cmd, :env, :exposed_ports, :host_config, :volumes_config
|
|
5
|
+
|
|
6
|
+
CONTAINER_DEFAULT_OPTIONS = {
|
|
7
|
+
'Tty' => true,
|
|
8
|
+
'OpenStdin' => true,
|
|
9
|
+
'StdinOnce' => true,
|
|
10
|
+
'AttachStdin' => true,
|
|
11
|
+
'AttachStdout' => true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def initialize(
|
|
15
|
+
name:,
|
|
16
|
+
repo: nil,
|
|
17
|
+
tag: nil,
|
|
18
|
+
image: nil,
|
|
19
|
+
cmd: nil,
|
|
20
|
+
env: '',
|
|
21
|
+
volumes: [],
|
|
22
|
+
binds: [],
|
|
23
|
+
exposed_ports: nil,
|
|
24
|
+
port_bindings: nil
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
@image = image_full_name(image, repo, tag)
|
|
28
|
+
@name = name
|
|
29
|
+
@cmd = cmd
|
|
30
|
+
@env = env
|
|
31
|
+
@exposed_ports = ExposedPortsConfig.new(exposed_ports)
|
|
32
|
+
@host_config = HostConfig.new(port_bindings, binds)
|
|
33
|
+
@volumes_config = VolumesConfig.new(volumes)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ==(other)
|
|
37
|
+
self.to_hash == other.to_hash
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def image_full_name(image = nil, repo = nil, tag = nil)
|
|
41
|
+
result = image || full_name(repo, tag)
|
|
42
|
+
raise ArgumentError if result.to_s.empty?
|
|
43
|
+
|
|
44
|
+
result
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_hash
|
|
48
|
+
state_config = {
|
|
49
|
+
'Image' => @image,
|
|
50
|
+
'name' => @name,
|
|
51
|
+
'Cmd' => @cmd,
|
|
52
|
+
'Env' => @env,
|
|
53
|
+
'ExposedPorts' => @exposed_ports.to_hash,
|
|
54
|
+
'Volumes' => @volumes_config.to_hash,
|
|
55
|
+
'HostConfig' => @host_config.to_hash
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
CONTAINER_DEFAULT_OPTIONS
|
|
59
|
+
.merge(state_config)
|
|
60
|
+
.delete_if {|_, value| value.to_s.empty?}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class ExposedPortsConfig
|
|
64
|
+
attr_reader :ports
|
|
65
|
+
|
|
66
|
+
def initialize(ports)
|
|
67
|
+
@ports = ports || []
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def to_hash
|
|
71
|
+
@ports.inject({}) do |result, value|
|
|
72
|
+
result[value] = {}
|
|
73
|
+
result
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class VolumesConfig
|
|
79
|
+
attr_reader :volumes
|
|
80
|
+
|
|
81
|
+
VOLUME_VALUE = {}
|
|
82
|
+
|
|
83
|
+
def initialize(volumes)
|
|
84
|
+
@volumes = volumes || []
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def to_hash
|
|
88
|
+
volumes.inject({}) do |config, volume|
|
|
89
|
+
config[volume] = {}
|
|
90
|
+
config
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class HostConfig
|
|
96
|
+
attr_reader :port_bindings, :binds
|
|
97
|
+
|
|
98
|
+
def initialize(port_bindings, binds)
|
|
99
|
+
@port_bindings = port_bindings || {}
|
|
100
|
+
@binds = binds || {}
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def to_hash
|
|
104
|
+
format_port_bindings = port_bindings.inject({}) do |result, value|
|
|
105
|
+
result[value[:container_port]] = [{ "HostPort" => value[:host_port] }]
|
|
106
|
+
result
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
format_binds = binds.inject([]) do |result, value|
|
|
110
|
+
result.push("#{value[:name]}:#{value[:to]}")
|
|
111
|
+
result
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
{
|
|
115
|
+
'Binds' => format_binds,
|
|
116
|
+
'PortBindings' => format_port_bindings
|
|
117
|
+
}
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|