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
|
@@ -3,6 +3,26 @@ require 'spec_helper'
|
|
|
3
3
|
describe Indocker::Configs::Config do
|
|
4
4
|
subject { described_class.new }
|
|
5
5
|
|
|
6
|
+
context 'restricts to use reserved keywords' do
|
|
7
|
+
it 'raise Indocker::Errors::ReservedKeywordUsed "option" name' do
|
|
8
|
+
expect{
|
|
9
|
+
subject.option(:config)
|
|
10
|
+
}.to raise_error(Indocker::Errors::ReservedKeywordUsed)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'restrict to use "config" name' do
|
|
14
|
+
expect{
|
|
15
|
+
subject.config('hash_config')
|
|
16
|
+
}.to raise_error(Indocker::Errors::ReservedKeywordUsed)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'restrict to use "hash_config" name' do
|
|
20
|
+
expect{
|
|
21
|
+
subject.hash_config(:option)
|
|
22
|
+
}.to raise_error(Indocker::Errors::ReservedKeywordUsed)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
6
26
|
describe '#option' do
|
|
7
27
|
it 'creates setter and getter methods with the same name' do
|
|
8
28
|
subject.option(:some_key, group: :default, type: :string)
|
|
@@ -21,7 +41,7 @@ describe Indocker::Configs::Config do
|
|
|
21
41
|
end
|
|
22
42
|
|
|
23
43
|
describe '#config' do
|
|
24
|
-
it 'creates getter and subconfiguration object' do
|
|
44
|
+
it 'creates getter and subconfiguration object for single option' do
|
|
25
45
|
subject.config(:example_config) do
|
|
26
46
|
option(:key1)
|
|
27
47
|
option(:key2, type: :array)
|
|
@@ -33,5 +53,36 @@ describe Indocker::Configs::Config do
|
|
|
33
53
|
expect(subject.example_config.key1).to eq('value1')
|
|
34
54
|
expect(subject.example_config.key2).to match(['value2'])
|
|
35
55
|
end
|
|
56
|
+
|
|
57
|
+
it 'creates getter and subconfig for subconfiguration' do
|
|
58
|
+
subject.config(:parent_config) do
|
|
59
|
+
config(:child_config) do
|
|
60
|
+
option(:child_option)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
subject.parent_config.child_config.child_option('Hello World')
|
|
65
|
+
|
|
66
|
+
expect(subject.parent_config.child_config.child_option).to eq('Hello World')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#hash_config' do
|
|
71
|
+
it 'create subconfiguration for each hash_config key' do
|
|
72
|
+
subject.hash_config(:multi) do
|
|
73
|
+
option(:key1)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
subject.multi(:config1) do
|
|
77
|
+
key1('value 1')
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
subject.multi(:config2) do
|
|
81
|
+
key1('value 2')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
expect(subject.config1.key1).to eq('value 1')
|
|
85
|
+
expect(subject.config2.key1).to eq('value 2')
|
|
86
|
+
end
|
|
36
87
|
end
|
|
37
88
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# TODO: rename to ContainerConfigBuilder
|
|
4
|
+
describe Indocker::ContainerBuilder do
|
|
5
|
+
describe '#build' do
|
|
6
|
+
subject { ioc.container_builder }
|
|
7
|
+
|
|
8
|
+
before(:all) do
|
|
9
|
+
Indocker.define_image :indocker_image do
|
|
10
|
+
from 'ruby:2.3.1'
|
|
11
|
+
workdir '/app'
|
|
12
|
+
cmd 'ls'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Indocker.define_network :indocker_network
|
|
16
|
+
Indocker.define_volume :indocker_volume
|
|
17
|
+
|
|
18
|
+
Indocker.define_container :indocker_container do
|
|
19
|
+
use images.find_by_repo(:indocker_image, tag: :latest)
|
|
20
|
+
use networks.find_by_name(:indocker_network)
|
|
21
|
+
|
|
22
|
+
mount volumes.find_by_name(:indocker_volume), to: '/tmp'
|
|
23
|
+
|
|
24
|
+
env_file File.join(__dir__, '../../fixtures/spec.env')
|
|
25
|
+
ports '2000:3000'
|
|
26
|
+
cmd '/bin/bash'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
after(:all) { truncate_docker_items }
|
|
31
|
+
|
|
32
|
+
it 'returns instance of Indocker::DockerAPI::ContainerConfig' do
|
|
33
|
+
expect(
|
|
34
|
+
subject.build(:indocker_container)
|
|
35
|
+
).to be_a(Indocker::DockerAPI::ContainerConfig)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'returns config with valid params' do
|
|
39
|
+
result = subject.build(:indocker_container)
|
|
40
|
+
|
|
41
|
+
expect(result.image).to eq('indocker_image:latest')
|
|
42
|
+
expect(result.name).to eq(:indocker_container)
|
|
43
|
+
expect(result.cmd).to eq('/bin/bash')
|
|
44
|
+
expect(result.env).to match(['RUBY_ENV=development', 'RAILS_ENV=development'])
|
|
45
|
+
|
|
46
|
+
expect(result.exposed_ports).to be_a(Indocker::DockerAPI::ContainerConfig::ExposedPortsConfig)
|
|
47
|
+
expect(result.exposed_ports.ports).to eq(['2000'])
|
|
48
|
+
|
|
49
|
+
expect(result.host_config).to be_a(Indocker::DockerAPI::ContainerConfig::HostConfig)
|
|
50
|
+
expect(result.host_config.port_bindings).to match([
|
|
51
|
+
{
|
|
52
|
+
container_port: '2000',
|
|
53
|
+
host_port: '3000'
|
|
54
|
+
}
|
|
55
|
+
])
|
|
56
|
+
expect(result.host_config.binds).to match([
|
|
57
|
+
{
|
|
58
|
+
name: 'indocker_volume',
|
|
59
|
+
to: '/tmp'
|
|
60
|
+
}
|
|
61
|
+
])
|
|
62
|
+
|
|
63
|
+
expect(result.volumes_config).to be_a(Indocker::DockerAPI::ContainerConfig::VolumesConfig)
|
|
64
|
+
expect(result.volumes_config.volumes).to eq(['/indocker_volume'])
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -1,230 +1,278 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Indocker::ContainerManager do
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
before(:all) do
|
|
5
|
+
Indocker.define_image 'indocker_image' do
|
|
6
|
+
from 'alpine:latest'
|
|
7
|
+
cmd %w(ls)
|
|
8
|
+
end
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
Indocker.define_image 'indocker_image' do
|
|
10
|
-
from 'alpine:latest'
|
|
11
|
-
workdir '.'
|
|
12
|
-
cmd %w(tail -F -n0 /etc/hosts)
|
|
13
|
-
end
|
|
10
|
+
ioc.image_builder.build('indocker_image')
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
Indocker.define_container 'indocker_container' do
|
|
13
|
+
use images.find_by_repo(:indocker_image)
|
|
16
14
|
end
|
|
15
|
+
end
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
before do
|
|
20
|
-
Indocker.define_container 'indocker_simple_container' do
|
|
21
|
-
use images.indocker_image
|
|
22
|
-
end
|
|
23
|
-
end
|
|
17
|
+
after(:all) { truncate_docker_items }
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
describe '#run' do
|
|
20
|
+
before(:all) { ioc.container_manager.run('indocker_container') }
|
|
21
|
+
after(:all) { ioc.docker_api.delete_container('indocker_container') }
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
23
|
+
it 'creates container' do
|
|
24
|
+
expect(
|
|
25
|
+
ioc.docker_api.container_exists?('indocker_container')
|
|
26
|
+
).to be true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'starts container' do
|
|
30
|
+
sleep 1 # wait when container stops
|
|
31
|
+
|
|
32
|
+
expect(
|
|
33
|
+
ioc.docker_api.get_container_state('indocker_container')
|
|
34
|
+
).to eq(Indocker::ContainerMetadata::States::EXITED)
|
|
32
35
|
end
|
|
33
36
|
end
|
|
34
37
|
|
|
35
|
-
describe '#
|
|
36
|
-
before
|
|
37
|
-
|
|
38
|
-
from 'alpine:latest'
|
|
39
|
-
workdir '.'
|
|
40
|
-
cmd %w(tail -F -n0 /etc/hosts)
|
|
41
|
-
end
|
|
38
|
+
describe '#create' do
|
|
39
|
+
before(:all) { ioc.container_manager.create('indocker_container') }
|
|
40
|
+
after(:all) { ioc.docker_api.delete_container('indocker_container') }
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
it 'creates container' do
|
|
43
|
+
expect(
|
|
44
|
+
ioc.docker_api.container_exists?('indocker_container')
|
|
45
|
+
).to be true
|
|
44
46
|
end
|
|
45
|
-
|
|
46
|
-
context 'with ready timeout' do
|
|
47
|
-
before do
|
|
48
|
-
Indocker.define_container 'indocker_timeout_container' do
|
|
49
|
-
use images.indocker_image
|
|
47
|
+
end
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
describe '#start' do
|
|
50
|
+
context 'with ready timeout' do
|
|
51
|
+
context 'if ready returns true' do
|
|
52
|
+
before(:all) do
|
|
53
|
+
Indocker.define_container 'indocker_timeout_container' do
|
|
54
|
+
use images.find_by_repo(:indocker_image)
|
|
55
|
+
|
|
56
|
+
ready sleep: 0.1, timeout: 1 do
|
|
57
|
+
sleep 0.5
|
|
58
|
+
true
|
|
59
|
+
end
|
|
54
60
|
end
|
|
61
|
+
|
|
62
|
+
ioc.container_manager.create('indocker_timeout_container')
|
|
55
63
|
end
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
it 'starts container if ready_block returns true' do
|
|
66
|
+
ioc.container_manager.start('indocker_timeout_container')
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
sleep 1 # wait when container stops
|
|
69
|
+
|
|
70
|
+
expect(
|
|
71
|
+
ioc.docker_api.get_container_state('indocker_timeout_container')
|
|
72
|
+
).to eq(Indocker::ContainerMetadata::States::EXITED)
|
|
63
73
|
end
|
|
74
|
+
end
|
|
64
75
|
|
|
76
|
+
context 'if ready returns false' do
|
|
77
|
+
before(:all) do
|
|
78
|
+
Indocker.define_container 'indocker_timeout_error_container' do
|
|
79
|
+
use images.find_by_repo(:indocker_image)
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
ready sleep: 0.1, timeout: 1 do
|
|
82
|
+
false
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
ioc.container_manager.create('indocker_timeout_error_container')
|
|
87
|
+
end
|
|
69
88
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
it 'raises Indocker::Errors::ContainerTimeoutError error if ready_block returns false' do
|
|
90
|
+
expect{
|
|
91
|
+
ioc.container_manager.start('indocker_timeout_error_container')
|
|
92
|
+
}.to raise_error(Indocker::Errors::ContainerTimeoutError)
|
|
93
|
+
end
|
|
75
94
|
end
|
|
76
95
|
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
context 'if ready reaches timeout' do
|
|
97
|
+
before(:all) do
|
|
98
|
+
Indocker.define_container 'indocker_timeout_reached_container' do
|
|
99
|
+
use images.find_by_repo(:indocker_image)
|
|
79
100
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
ready sleep: 0.1, timeout: 1 do
|
|
102
|
+
sleep 2
|
|
103
|
+
|
|
104
|
+
true
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
ioc.container_manager.create('indocker_timeout_reached_container')
|
|
109
|
+
end
|
|
84
110
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
111
|
+
it 'raises Indocker::Errors::ContainerTimeoutError error if ready_block returns false' do
|
|
112
|
+
expect{
|
|
113
|
+
ioc.container_manager.start('indocker_timeout_reached_container')
|
|
114
|
+
}.to raise_error(Indocker::Errors::ContainerTimeoutError)
|
|
115
|
+
end
|
|
89
116
|
end
|
|
90
117
|
end
|
|
91
118
|
|
|
92
119
|
context 'with container dependencies' do
|
|
93
|
-
|
|
94
|
-
|
|
120
|
+
before(:all) do
|
|
121
|
+
Indocker.define_container 'indocker_container_depends_on' do
|
|
122
|
+
use images.find_by_repo(:indocker_image)
|
|
95
123
|
|
|
96
|
-
|
|
97
|
-
Indocker.define_container 'indocker_dependency_container' do
|
|
98
|
-
use images.indocker_image
|
|
124
|
+
depends_on containers.get_by_name('indocker_container')
|
|
99
125
|
end
|
|
100
126
|
|
|
101
|
-
|
|
102
|
-
|
|
127
|
+
ioc.container_manager.create('indocker_container_depends_on')
|
|
128
|
+
end
|
|
103
129
|
|
|
104
|
-
|
|
105
|
-
|
|
130
|
+
after(:all) { ioc.docker_api.delete_container('indocker_container') }
|
|
131
|
+
|
|
132
|
+
it 'starts dependency container before' do
|
|
133
|
+
ioc.container_manager.start('indocker_container_depends_on')
|
|
134
|
+
|
|
135
|
+
sleep 1 # wait when container stops
|
|
136
|
+
|
|
137
|
+
expect(
|
|
138
|
+
ioc.docker_api.get_container_state('indocker_container')
|
|
139
|
+
).to eq(Indocker::ContainerMetadata::States::EXITED)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
106
142
|
|
|
107
|
-
|
|
108
|
-
|
|
143
|
+
context 'with specified volume' do
|
|
144
|
+
before(:all) do
|
|
145
|
+
Indocker.define_volume 'indocker_volume'
|
|
146
|
+
|
|
147
|
+
Indocker.define_container 'indocker_volume_container' do
|
|
148
|
+
use images.find_by_repo(:indocker_image)
|
|
149
|
+
mount volumes.find_by_name('indocker_volume'), to: '/app'
|
|
150
|
+
end
|
|
109
151
|
|
|
110
|
-
container_manager.
|
|
152
|
+
ioc.container_manager.create('indocker_volume_container')
|
|
153
|
+
ioc.container_manager.start('indocker_volume_container')
|
|
111
154
|
end
|
|
112
155
|
|
|
113
|
-
after do
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
container_manager.stop('indocker_dependency_container')
|
|
117
|
-
container_manager.delete('indocker_dependency_container')
|
|
156
|
+
after(:all) do
|
|
157
|
+
ioc.docker_api.delete_container('indocker_volume_container')
|
|
158
|
+
ioc.docker_api.delete_volume('indocker_volume')
|
|
118
159
|
end
|
|
119
160
|
|
|
120
|
-
it '
|
|
161
|
+
it 'creates volume before start' do
|
|
121
162
|
expect(
|
|
122
|
-
docker_api.
|
|
123
|
-
).to
|
|
163
|
+
ioc.docker_api.volume_exists?('indocker_volume')
|
|
164
|
+
).to be true
|
|
124
165
|
end
|
|
125
166
|
end
|
|
126
167
|
|
|
127
168
|
context 'with specified network' do
|
|
128
|
-
|
|
129
|
-
let(:network_id) { docker_api.get_network_id('indocker_network') }
|
|
130
|
-
|
|
131
|
-
before do
|
|
169
|
+
before(:all) do
|
|
132
170
|
Indocker.define_network 'indocker_network'
|
|
133
171
|
|
|
134
|
-
Indocker.define_container '
|
|
135
|
-
use images.indocker_image
|
|
172
|
+
Indocker.define_container 'indocker_network_container' do
|
|
173
|
+
use images.find_by_repo(:indocker_image)
|
|
136
174
|
use networks.indocker_network
|
|
137
175
|
end
|
|
138
176
|
|
|
139
|
-
ioc.container_manager.create('
|
|
140
|
-
|
|
141
|
-
container_manager.start('indocker_simple_container')
|
|
177
|
+
ioc.container_manager.create('indocker_network_container')
|
|
178
|
+
ioc.container_manager.start('indocker_network_container')
|
|
142
179
|
end
|
|
143
180
|
|
|
144
|
-
after do
|
|
145
|
-
container_manager.
|
|
146
|
-
|
|
147
|
-
docker_api.remove_network('indocker_network')
|
|
181
|
+
after(:all) do
|
|
182
|
+
ioc.container_manager.delete('indocker_network_container')
|
|
183
|
+
ioc.docker_api.delete_network('indocker_network')
|
|
148
184
|
end
|
|
149
185
|
|
|
150
186
|
context 'creates network before start' do
|
|
151
187
|
it 'for new network' do
|
|
152
|
-
expect(
|
|
153
|
-
|
|
188
|
+
expect(
|
|
189
|
+
ioc.docker_api.get_network_id('indocker_network')
|
|
190
|
+
).to match(/[\w\d]{64}/)
|
|
191
|
+
|
|
192
|
+
expect(ioc.docker_api.network_exists?('indocker_network')).to be true
|
|
154
193
|
end
|
|
155
194
|
|
|
156
195
|
it 'if network already exists' do
|
|
157
|
-
container_manager.stop('
|
|
158
|
-
container_manager.start('
|
|
196
|
+
ioc.container_manager.stop('indocker_network_container')
|
|
197
|
+
ioc.container_manager.start('indocker_network_container')
|
|
159
198
|
|
|
160
|
-
expect(
|
|
161
|
-
|
|
199
|
+
expect(
|
|
200
|
+
ioc.docker_api.get_network_id('indocker_network')
|
|
201
|
+
).to match(/[\w\d]{64}/)
|
|
202
|
+
|
|
203
|
+
expect(ioc.docker_api.network_exists?('indocker_network')).to be true
|
|
162
204
|
end
|
|
163
205
|
end
|
|
164
206
|
|
|
165
207
|
it 'connect container to specified network' do
|
|
166
208
|
expect(
|
|
167
|
-
docker_api.inspect_network(
|
|
168
|
-
).to include(
|
|
209
|
+
ioc.docker_api.inspect_network('indocker_network')['Containers'].keys
|
|
210
|
+
).to include(
|
|
211
|
+
ioc.docker_api.get_container_id('indocker_network_container')
|
|
212
|
+
)
|
|
169
213
|
end
|
|
170
214
|
|
|
171
215
|
it 'starts container' do
|
|
216
|
+
sleep 1 # wait when container stops
|
|
217
|
+
|
|
172
218
|
expect(
|
|
173
|
-
docker_api.get_container_state(
|
|
174
|
-
|
|
219
|
+
ioc.docker_api.get_container_state(
|
|
220
|
+
ioc.docker_api.get_container_id('indocker_network_container')
|
|
221
|
+
)
|
|
222
|
+
).to eq(Indocker::ContainerMetadata::States::EXITED)
|
|
175
223
|
end
|
|
176
224
|
end
|
|
177
225
|
end
|
|
178
226
|
|
|
179
227
|
describe '#copy' do
|
|
180
|
-
let(:copy_to_path) {
|
|
181
|
-
|
|
182
|
-
before do
|
|
228
|
+
let(:copy_to_path) { ioc.config.build_dir.join('indocker_list_container_files') }
|
|
229
|
+
|
|
230
|
+
before(:all) do
|
|
183
231
|
Indocker.define_image 'indocker_copy_image' do
|
|
184
232
|
from 'alpine'
|
|
185
233
|
|
|
186
|
-
run
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
run 'echo "example2.txt" > /sample/example2.txt'
|
|
190
|
-
run 'echo "example3.txt" > /sample/deeper/example3.txt'
|
|
191
|
-
run 'echo "example4.txt" > /sample/deeper/example4.txt'
|
|
192
|
-
|
|
193
|
-
cmd ['ls']
|
|
234
|
+
run "mkdir -p /sample/deeper &&
|
|
235
|
+
echo 'example1.txt' > /sample/example1.txt &&
|
|
236
|
+
echo 'example3.txt' > /sample/deeper/example2.txt"
|
|
194
237
|
end
|
|
195
|
-
|
|
196
|
-
|
|
238
|
+
|
|
197
239
|
Indocker.define_container :indocker_copy_container do
|
|
198
|
-
use images.indocker_copy_image
|
|
240
|
+
use images.find_by_repo('indocker_copy_image')
|
|
199
241
|
end
|
|
242
|
+
|
|
243
|
+
ioc.image_builder.build('indocker_copy_image')
|
|
244
|
+
ioc.container_manager.create('indocker_copy_container')
|
|
200
245
|
end
|
|
201
246
|
|
|
202
247
|
it 'returns files list' do
|
|
203
248
|
expect(
|
|
204
|
-
container_manager.copy(
|
|
249
|
+
ioc.container_manager.copy(
|
|
205
250
|
name: :indocker_copy_container,
|
|
206
251
|
copy_from: '/sample/deeper',
|
|
207
252
|
copy_to: copy_to_path
|
|
208
253
|
)
|
|
209
|
-
).to match(
|
|
210
|
-
[
|
|
211
|
-
'deeper/example3.txt',
|
|
212
|
-
'deeper/example4.txt'
|
|
213
|
-
]
|
|
214
|
-
)
|
|
254
|
+
).to match(['deeper/example2.txt'])
|
|
215
255
|
end
|
|
216
256
|
|
|
217
257
|
it 'copies files to output path' do
|
|
218
|
-
container_manager.copy(
|
|
258
|
+
ioc.container_manager.copy(
|
|
219
259
|
name: :indocker_copy_container,
|
|
220
260
|
copy_from: '/sample/.',
|
|
221
261
|
copy_to: copy_to_path
|
|
222
262
|
)
|
|
223
263
|
|
|
224
264
|
ensure_content(File.join(copy_to_path, 'example1.txt'), 'example1.txt')
|
|
225
|
-
ensure_content(File.join(copy_to_path, 'example2.txt'), '
|
|
226
|
-
|
|
227
|
-
|
|
265
|
+
ensure_content(File.join(copy_to_path, 'deeper/example2.txt'), 'example3.txt')
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it 'copies single file' do
|
|
269
|
+
ioc.container_manager.copy(
|
|
270
|
+
name: :indocker_copy_container,
|
|
271
|
+
copy_from: '/sample/example1.txt',
|
|
272
|
+
copy_to: copy_to_path
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
ensure_content(File.join(copy_to_path, 'example1.txt'), 'example1.txt')
|
|
228
276
|
end
|
|
229
277
|
end
|
|
230
278
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::DockerAPI::ContainerConfig do
|
|
4
|
+
let(:params_hash) {
|
|
5
|
+
{
|
|
6
|
+
repo: 'indocker_image',
|
|
7
|
+
tag: 'latest',
|
|
8
|
+
image: 'indocker_another_image:latest',
|
|
9
|
+
name: 'indocker_container',
|
|
10
|
+
cmd: ['/bin/bash'],
|
|
11
|
+
volumes: ['tmp', 'gems_volume'],
|
|
12
|
+
exposed_ports: ['2000', '4000'],
|
|
13
|
+
env: 'RUBY_ENV=development RAILS_ENV=development',
|
|
14
|
+
binds: [
|
|
15
|
+
{ name: 'tmp', to: '/tmp' },
|
|
16
|
+
{ name: 'gems_volume', to: '/bundle' }
|
|
17
|
+
],
|
|
18
|
+
port_bindings: [{
|
|
19
|
+
container_port: '2000',
|
|
20
|
+
host_port: '3000'
|
|
21
|
+
}]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
describe '#to_hash' do
|
|
28
|
+
it 'returns hash with valid params' do
|
|
29
|
+
expect(
|
|
30
|
+
described_class.new(params_hash).to_hash
|
|
31
|
+
).to match(
|
|
32
|
+
{
|
|
33
|
+
'Image' => 'indocker_another_image:latest',
|
|
34
|
+
'name' => 'indocker_container',
|
|
35
|
+
'Cmd' => ['/bin/bash'],
|
|
36
|
+
'Env' => 'RUBY_ENV=development RAILS_ENV=development',
|
|
37
|
+
'Tty' => true,
|
|
38
|
+
'OpenStdin' => true,
|
|
39
|
+
'StdinOnce' => true,
|
|
40
|
+
'AttachStdin' => true,
|
|
41
|
+
'AttachStdout' => true,
|
|
42
|
+
'ExposedPorts' => {
|
|
43
|
+
'2000' => {},
|
|
44
|
+
'4000' => {}
|
|
45
|
+
},
|
|
46
|
+
'Volumes' => {
|
|
47
|
+
'tmp' => {},
|
|
48
|
+
'gems_volume' => {}
|
|
49
|
+
},
|
|
50
|
+
'HostConfig' => {
|
|
51
|
+
'Binds' => ['tmp:/tmp', 'gems_volume:/bundle'],
|
|
52
|
+
'PortBindings' => {
|
|
53
|
+
'2000' => [
|
|
54
|
+
{
|
|
55
|
+
'HostPort' => '3000'
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|