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,13 +1,13 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Indocker::
|
|
3
|
+
describe Indocker::DockerAPI do
|
|
4
4
|
let(:docker_api) { ioc.docker_api }
|
|
5
5
|
|
|
6
6
|
describe '#create_network' do
|
|
7
7
|
context 'simple network' do
|
|
8
8
|
let!(:id) { docker_api.create_network('indocker') }
|
|
9
9
|
|
|
10
|
-
after { docker_api.
|
|
10
|
+
after { docker_api.delete_network(id) }
|
|
11
11
|
|
|
12
12
|
it 'creates network' do
|
|
13
13
|
expect(
|
|
@@ -20,10 +20,10 @@ describe Indocker::DockerApi do
|
|
|
20
20
|
describe '#add_container_to_network' do
|
|
21
21
|
let(:container_id) {
|
|
22
22
|
docker_api.create_container(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
Indocker::DockerAPI::ContainerConfig.new(
|
|
24
|
+
image: 'alpine:latest',
|
|
25
|
+
name: 'sample_container'
|
|
26
|
+
)
|
|
27
27
|
)
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ describe Indocker::DockerApi do
|
|
|
32
32
|
after do
|
|
33
33
|
docker_api.stop_container(container_id)
|
|
34
34
|
docker_api.delete_container(container_id)
|
|
35
|
-
docker_api.
|
|
35
|
+
docker_api.delete_network(network_id)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it 'do something' do
|
|
@@ -58,13 +58,40 @@ describe Indocker::DockerApi do
|
|
|
58
58
|
|
|
59
59
|
context 'if image does not present' do
|
|
60
60
|
it 'returns nil ' do
|
|
61
|
-
expect
|
|
62
|
-
docker_api.get_image_id('some-invalid-image')
|
|
63
|
-
}.to raise_error(Docker::Error::NotFoundError)
|
|
61
|
+
expect(docker_api.get_image_id('some-invalid-image')).to eq(nil)
|
|
64
62
|
end
|
|
65
63
|
end
|
|
66
64
|
end
|
|
67
65
|
|
|
66
|
+
describe '#create_volume' do
|
|
67
|
+
context 'simple volume' do
|
|
68
|
+
let!(:id) { docker_api.create_volume('volume') }
|
|
69
|
+
|
|
70
|
+
after { docker_api.delete_volume(id) }
|
|
71
|
+
|
|
72
|
+
it 'creates volume' do
|
|
73
|
+
expect(
|
|
74
|
+
docker_api.get_volume_id('volume')
|
|
75
|
+
).to eq(id)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#create_volume' do
|
|
81
|
+
context 'simple volume' do
|
|
82
|
+
let!(:id) { docker_api.create_volume('volume') }
|
|
83
|
+
|
|
84
|
+
after { docker_api.delete_volume(id) }
|
|
85
|
+
|
|
86
|
+
it 'creates volume' do
|
|
87
|
+
expect(
|
|
88
|
+
docker_api.get_volume_id('volume')
|
|
89
|
+
).to eq(id)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
68
95
|
describe '#get_container_id' do
|
|
69
96
|
context 'if container presents' do
|
|
70
97
|
let!(:container) { Docker::Container.create('Image' => 'alpine:latest', 'name': 'alpine') }
|
|
@@ -78,9 +105,7 @@ describe Indocker::DockerApi do
|
|
|
78
105
|
|
|
79
106
|
context 'if container does not present' do
|
|
80
107
|
it 'returns nil' do
|
|
81
|
-
expect
|
|
82
|
-
docker_api.get_container_id('invalid-container-name')
|
|
83
|
-
}.to raise_error(Docker::Error::NotFoundError)
|
|
108
|
+
expect(docker_api.get_container_id('invalid-container-name')).to eq(nil)
|
|
84
109
|
end
|
|
85
110
|
end
|
|
86
111
|
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Indocker::Handlers::ContainerRun' do
|
|
4
|
+
describe '#handle' do
|
|
5
|
+
after(:all) { truncate_docker_items }
|
|
6
|
+
|
|
7
|
+
before(:all) do
|
|
8
|
+
Indocker.define_image :indocker_image do
|
|
9
|
+
from 'alpine:latest'
|
|
10
|
+
|
|
11
|
+
cmd ['/bin/sh']
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
context 'for valid cmd process in container' do
|
|
15
|
+
context 'for new container' do
|
|
16
|
+
before(:all) do
|
|
17
|
+
Indocker.define_container :indocker_correct_container do
|
|
18
|
+
use images.find_by_repo(:indocker_image)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
ioc.run_container_handler.handle(name: :indocker_correct_container, current_path: nil)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'creates container' do
|
|
25
|
+
expect(
|
|
26
|
+
ioc.docker_api.container_exists?(:indocker_correct_container)
|
|
27
|
+
).to be true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'runs container' do
|
|
31
|
+
expect(
|
|
32
|
+
ioc.docker_api.get_container_state(:indocker_correct_container)
|
|
33
|
+
).to eq(Indocker::ContainerMetadata::States::RUNNING)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'logs successfull result' do
|
|
37
|
+
expect(
|
|
38
|
+
ioc.logger.messages.last
|
|
39
|
+
).to eq("INFO".colorize(:green) + ": Successfully started container :indocker_correct_container")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'for falling cmd process in container' do
|
|
45
|
+
before(:all) do
|
|
46
|
+
Indocker.define_container :container_with_falling_cmd do
|
|
47
|
+
use images.find_by_repo(:indocker_image)
|
|
48
|
+
|
|
49
|
+
cmd ['invalid_command']
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'raises Docker::Error::ClientError error' do
|
|
54
|
+
expect{
|
|
55
|
+
ioc.run_container_handler.handle(name: :container_with_falling_cmd, current_path: nil)
|
|
56
|
+
}.to raise_error(Docker::Error::ClientError)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe 'Indocker::ImageBuilder' do
|
|
4
|
-
subject { ioc.image_builder }
|
|
5
|
-
|
|
6
4
|
context 'for image without dependencies' do
|
|
7
|
-
before do
|
|
5
|
+
before(:all) do
|
|
8
6
|
Indocker.define_image('indocker_image') do
|
|
9
|
-
before_build { 'test' }
|
|
10
|
-
|
|
11
7
|
from 'hello-world'
|
|
12
8
|
workdir '/'
|
|
13
9
|
end
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
ioc.image_builder.build('indocker_image')
|
|
16
12
|
end
|
|
17
13
|
|
|
14
|
+
after(:all) { truncate_docker_items }
|
|
15
|
+
|
|
18
16
|
it 'builds image without dependencies' do
|
|
19
17
|
expect(
|
|
20
18
|
ioc.docker_api.image_exists?('indocker_image')
|
|
@@ -31,59 +29,63 @@ describe 'Indocker::ImageBuilder' do
|
|
|
31
29
|
end
|
|
32
30
|
|
|
33
31
|
context 'for image with dependencies' do
|
|
34
|
-
context 'circular
|
|
32
|
+
context 'circular docker_cp dependency' do
|
|
35
33
|
before do
|
|
36
|
-
Indocker.define_image('
|
|
34
|
+
Indocker.define_image('indocker_image') do
|
|
37
35
|
before_build do
|
|
38
|
-
docker_cp '
|
|
36
|
+
docker_cp 'indocker_container'
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
from 'hello-world'
|
|
42
40
|
workdir '/'
|
|
43
41
|
end
|
|
44
42
|
|
|
45
|
-
Indocker.define_container '
|
|
46
|
-
use images.
|
|
43
|
+
Indocker.define_container 'indocker_container' do
|
|
44
|
+
use images.find_by_repo(:indocker_image)
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
47
|
|
|
48
|
+
after(:all) { truncate_docker_items }
|
|
49
|
+
|
|
50
50
|
it 'raises Indocker::Errors::CircularImageDependency' do
|
|
51
51
|
expect{
|
|
52
|
-
|
|
52
|
+
ioc.image_builder.build('indocker_image')
|
|
53
53
|
}.to raise_error(Indocker::Errors::CircularImageDependency)
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
context 'for non circular
|
|
57
|
+
context 'for non circular docker_cp dependency' do
|
|
58
58
|
before do
|
|
59
|
-
Indocker.define_image('
|
|
59
|
+
Indocker.define_image('indocker_dependency_image') do
|
|
60
60
|
from 'alpine:latest'
|
|
61
61
|
workdir '/'
|
|
62
62
|
run 'echo "Hello World" > test.txt'
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
Indocker.define_image('
|
|
65
|
+
Indocker.define_image('indocker_image') do
|
|
66
66
|
before_build do
|
|
67
67
|
docker_cp 'indocker_container' do
|
|
68
|
-
copy 'test.txt' =>
|
|
68
|
+
copy 'test.txt' => '/copy'
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
from
|
|
72
|
+
from :indocker_dependency_image, tag: :latest
|
|
73
73
|
workdir '/'
|
|
74
|
-
copy 'test.txt' => '/'
|
|
74
|
+
copy '/copy/test.txt' => '/'
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
Indocker.define_container 'indocker_container' do
|
|
78
|
-
use images.
|
|
78
|
+
use images.find_by_repo(:indocker_dependency_image)
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
ioc.image_builder.build('indocker_image')
|
|
80
82
|
end
|
|
81
83
|
|
|
84
|
+
after(:all) { truncate_docker_items }
|
|
85
|
+
|
|
82
86
|
it 'builds image with dependency' do
|
|
83
|
-
subject.build('indocker_image_with_dependency')
|
|
84
|
-
|
|
85
87
|
expect(
|
|
86
|
-
ioc.docker_api.image_exists?('
|
|
88
|
+
ioc.docker_api.image_exists?('indocker_image')
|
|
87
89
|
).to be true
|
|
88
90
|
end
|
|
89
91
|
end
|
|
@@ -92,23 +94,59 @@ describe 'Indocker::ImageBuilder' do
|
|
|
92
94
|
context 'for not existing image' do
|
|
93
95
|
it 'raises Indocker::Errors::ImageIsNotDefined' do
|
|
94
96
|
expect{
|
|
95
|
-
|
|
97
|
+
ioc.image_builder.build('indocker_image')
|
|
96
98
|
}.to raise_error(Indocker::Errors::ImageIsNotDefined)
|
|
97
99
|
end
|
|
98
100
|
end
|
|
99
101
|
|
|
102
|
+
context 'when push image to registry' do
|
|
103
|
+
before(:all) do
|
|
104
|
+
Indocker.define_image('indocker_image') do
|
|
105
|
+
from 'alpine:latest'
|
|
106
|
+
|
|
107
|
+
use registry.localhost(push: true)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
set_local_registry
|
|
111
|
+
ioc.image_builder.build('indocker_image')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'tags image with specified registry_repo_tag' do
|
|
115
|
+
expect(
|
|
116
|
+
ioc.docker_api.image_exists?('localhost:1000/indocker_image')
|
|
117
|
+
).to be true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'pushes image to registry' do
|
|
121
|
+
ioc.docker_api.delete_image('indocker_image')
|
|
122
|
+
|
|
123
|
+
ioc.docker_api.pull('fromImage' => 'localhost:1000/indocker_image:latest')
|
|
124
|
+
|
|
125
|
+
expect(
|
|
126
|
+
ioc.docker_api.image_exists?('localhost:1000/indocker_image')
|
|
127
|
+
).to be true
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
after(:all) do
|
|
131
|
+
ioc.registry_api.get(:localhost).rmtag('indocker_image')
|
|
132
|
+
truncate_docker_items
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
100
136
|
context 'with coping files from project_root' do
|
|
101
137
|
before do
|
|
102
|
-
Indocker.define_image('
|
|
138
|
+
Indocker.define_image('indocker_image') do
|
|
103
139
|
from 'alpine:latest'
|
|
104
140
|
|
|
105
|
-
copy 'assets/.' => 'assets'
|
|
141
|
+
copy File.join(__dir__, '../../example/assets/.') => 'assets'
|
|
106
142
|
end
|
|
107
143
|
end
|
|
108
144
|
|
|
145
|
+
after(:all) { truncate_docker_items }
|
|
146
|
+
|
|
109
147
|
it 'does not raise error' do
|
|
110
148
|
expect{
|
|
111
|
-
|
|
149
|
+
ioc.image_builder.build('indocker_image')
|
|
112
150
|
}.to_not raise_error
|
|
113
151
|
end
|
|
114
152
|
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::ImageDirectivesRunner do
|
|
4
|
+
let(:image_directives_runner) { ioc.image_directives_runner }
|
|
5
|
+
let(:project_dir) { Pathname.new File.expand_path(File.join(__dir__, '../../example')) }
|
|
6
|
+
|
|
7
|
+
let(:context) {
|
|
8
|
+
Indocker::DSLContext.new(
|
|
9
|
+
display: 'none',
|
|
10
|
+
use_strict: true,
|
|
11
|
+
build_dir: build_dir,
|
|
12
|
+
repo: 'indocker_image',
|
|
13
|
+
tag: 'latest'
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let(:build_dir) { ioc.config.build_dir }
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
describe '#run_registry' do
|
|
21
|
+
let(:registry_directive) do
|
|
22
|
+
Indocker::ImageDirectives::Registry.new(
|
|
23
|
+
repo: 'indocker_image',
|
|
24
|
+
tag: 'latest',
|
|
25
|
+
registry: 'http://localhost:5000',
|
|
26
|
+
push: true
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class DockerImageStub
|
|
31
|
+
def tag(*args)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def push(*args)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'tags image with registry_repotag' do
|
|
39
|
+
allow(Docker::Image).to receive(:get).and_return(DockerImageStub.new)
|
|
40
|
+
expect_any_instance_of(DockerImageStub).to receive(:tag)
|
|
41
|
+
|
|
42
|
+
image_directives_runner.run(registry_directive)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'pushes registry_repotag' do
|
|
46
|
+
allow(Docker::Image).to receive(:get).and_return(DockerImageStub.new)
|
|
47
|
+
expect_any_instance_of(DockerImageStub).to receive(:push)
|
|
48
|
+
|
|
49
|
+
image_directives_runner.run(registry_directive)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe "#run_copy" do
|
|
54
|
+
let(:from_path) { project_dir.join 'assets/.' }
|
|
55
|
+
let(:to_path) { '/assets' }
|
|
56
|
+
let(:copy_directive) {
|
|
57
|
+
Indocker::ImageDirectives::Copy.new(
|
|
58
|
+
locals: context.storage,
|
|
59
|
+
build_dir: context.build_dir,
|
|
60
|
+
compile: false,
|
|
61
|
+
copy_actions: {
|
|
62
|
+
from_path => to_path
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
context 'for :from as directory path' do
|
|
68
|
+
context "when directory exists" do
|
|
69
|
+
it 'copy files from passed to build directory' do
|
|
70
|
+
image_directives_runner.run(copy_directive)
|
|
71
|
+
|
|
72
|
+
ensure_content(File.join(build_dir, project_dir, 'assets', 'index.css'), "* { display: <%= display %>; }")
|
|
73
|
+
ensure_content(File.join(build_dir, project_dir, 'assets', 'index.js'), "<% if use_strict %>'use strict';<% end %>")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "when directory does not exists" do
|
|
78
|
+
let(:from_path) { 'invalid/dir/.' }
|
|
79
|
+
let(:to_path) { '/invalid/dir' }
|
|
80
|
+
|
|
81
|
+
it "raises error ArgumentError" do
|
|
82
|
+
expect{
|
|
83
|
+
image_directives_runner.run(copy_directive)
|
|
84
|
+
}.to raise_error(ArgumentError)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context 'with compile: true option' do
|
|
89
|
+
let(:copy_directive) {
|
|
90
|
+
Indocker::ImageDirectives::Copy.new(
|
|
91
|
+
locals: context.storage,
|
|
92
|
+
build_dir: context.build_dir,
|
|
93
|
+
compile: true,
|
|
94
|
+
copy_actions: {
|
|
95
|
+
from_path => to_path
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
it 'copy compiles files from root to build directory' do
|
|
101
|
+
image_directives_runner.run(copy_directive)
|
|
102
|
+
|
|
103
|
+
ensure_content(File.join(build_dir, project_dir, 'assets', 'index.css'), "* { display: none; }")
|
|
104
|
+
ensure_content(File.join(build_dir, project_dir, 'assets', 'index.js'), "'use strict';")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context "for :from as single file path" do
|
|
110
|
+
let(:from_path) { project_dir.join 'assets/index.css' }
|
|
111
|
+
let(:to_path) { '/assets' }
|
|
112
|
+
|
|
113
|
+
context 'without compilation' do
|
|
114
|
+
it 'copy files from root to build directory if no file in build directory' do
|
|
115
|
+
image_directives_runner.run(copy_directive)
|
|
116
|
+
|
|
117
|
+
ensure_content(File.join(build_dir, project_dir, 'assets', 'index.css'), "* { display: <%= display %>; }")
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context 'with compilaton' do
|
|
122
|
+
let(:copy_directive) {
|
|
123
|
+
Indocker::ImageDirectives::Copy.new(
|
|
124
|
+
locals: context.storage,
|
|
125
|
+
build_dir: context.build_dir,
|
|
126
|
+
compile: true,
|
|
127
|
+
copy_actions: {
|
|
128
|
+
from_path => to_path
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
it 'compiles and overwrites file is present in build directory' do
|
|
134
|
+
image_directives_runner.run(copy_directive)
|
|
135
|
+
|
|
136
|
+
ensure_content(File.join(build_dir, project_dir, 'assets', 'index.css'), "* { display: none; }")
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::ImageDockerfileBuilder do
|
|
4
|
+
subject { ioc.image_dockerfile_builder }
|
|
5
|
+
|
|
6
|
+
describe '#build' do
|
|
7
|
+
let(:from_directive) { Indocker::ImageDirectives::From.new('ruby-alpine:latest') }
|
|
8
|
+
let(:workdir_directive) { Indocker::ImageDirectives::Workdir.new('/app') }
|
|
9
|
+
let(:env_file_directive) {
|
|
10
|
+
Indocker::ImageDirectives::EnvFile.new(
|
|
11
|
+
File.expand_path(File.join(__dir__, '../../fixtures/spec.env'))
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
it 'generates valid dockerfile' do
|
|
16
|
+
expect(
|
|
17
|
+
subject.build(from_directive, workdir_directive, env_file_directive)
|
|
18
|
+
).to eq(
|
|
19
|
+
"FROM ruby-alpine:latest\n" <<
|
|
20
|
+
"WORKDIR /app\n" <<
|
|
21
|
+
"ENV RUBY_ENV=development RAILS_ENV=development"
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe 'Indocker::ImageEvaluator' do
|
|
4
|
-
subject
|
|
4
|
+
subject { ioc.image_evaluator }
|
|
5
|
+
let(:context) { Indocker::DSLContext.new(build_dir: 'some/path') }
|
|
5
6
|
|
|
6
7
|
before do
|
|
7
8
|
Indocker.define_partial 'example_partial' do
|
|
@@ -41,7 +42,6 @@ describe 'Indocker::ImageEvaluator' do
|
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
|
44
|
-
let(:context) { Indocker::DSLContext.new(build_dir: 'some/path') }
|
|
45
45
|
let(:directives) { subject.evaluate(context, &example_image_definition) }
|
|
46
46
|
|
|
47
47
|
it 'returns array of directives' do
|
|
@@ -53,13 +53,33 @@ describe 'Indocker::ImageEvaluator' do
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it 'rerurns proper directives classes' do
|
|
56
|
-
expect(directives[0]).to be_a(Indocker::
|
|
57
|
-
expect(directives[1]).to be_a(Indocker::
|
|
58
|
-
expect(directives[2]).to be_a(Indocker::
|
|
59
|
-
expect(directives[3]).to be_a(Indocker::
|
|
60
|
-
expect(directives[4]).to be_a(Indocker::
|
|
61
|
-
expect(directives[5]).to be_a(Indocker::
|
|
62
|
-
expect(directives[6]).to be_a(Indocker::
|
|
56
|
+
expect(directives[0]).to be_a(Indocker::ImageDirectives::DockerCp)
|
|
57
|
+
expect(directives[1]).to be_a(Indocker::ImageDirectives::From)
|
|
58
|
+
expect(directives[2]).to be_a(Indocker::ImageDirectives::DockerCp)
|
|
59
|
+
expect(directives[3]).to be_a(Indocker::ImageDirectives::Run)
|
|
60
|
+
expect(directives[4]).to be_a(Indocker::ImageDirectives::Run)
|
|
61
|
+
expect(directives[5]).to be_a(Indocker::ImageDirectives::Workdir)
|
|
62
|
+
expect(directives[6]).to be_a(Indocker::ImageDirectives::Run)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'with partial with options' do
|
|
67
|
+
let(:image_with_partial_definition) {
|
|
68
|
+
Proc.new do
|
|
69
|
+
partial :partial_directive, some_arg: 'some_arg_value'
|
|
70
|
+
end
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
before(:all) do
|
|
74
|
+
Indocker.define_partial :partial_directive do
|
|
75
|
+
run "echo #{some_arg}"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'generates valid dockerfile' do
|
|
80
|
+
partial_directive = subject.evaluate(context, &image_with_partial_definition).first
|
|
81
|
+
|
|
82
|
+
expect(partial_directive.to_s).to eq(%q(RUN echo some_arg_value))
|
|
63
83
|
end
|
|
64
84
|
end
|
|
65
85
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -10,7 +10,10 @@ SmartIoC.set_load_proc do |location|
|
|
|
10
10
|
require(location)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
ioc.config.build_dir Pathname.new File.expand_path(File.join(__dir__, '../tmp/build'))
|
|
14
|
+
ioc.config.git.cache_dir Pathname.new File.expand_path(File.join(__dir__, '../tmp/cache'))
|
|
15
|
+
|
|
16
|
+
ioc.config.docker.registry(:localhost) { serveraddress 'http://localhost:1000' }
|
|
14
17
|
|
|
15
18
|
RSpec.configure do |config|
|
|
16
19
|
config.expect_with :rspec do |expectations|
|
|
@@ -20,21 +23,7 @@ RSpec.configure do |config|
|
|
|
20
23
|
config.mock_with :rspec
|
|
21
24
|
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
22
25
|
|
|
23
|
-
config.after(:
|
|
24
|
-
ioc.docker_api.delete_containers_where { |container| container.refresh!.info['Config']['Image'] =~ /^indocker/ }
|
|
25
|
-
ioc.docker_api.delete_containers_where { |container| container.refresh!.info['Names'].grep(/^\/indocker/).any? }
|
|
26
|
-
ioc.docker_api.delete_images_where { |image| image.info['RepoTags'].grep(/^indocker/).any? }
|
|
27
|
-
ioc.docker_api.delete_networks_where { |network| network.info['Name'] =~ /^indocker/ }
|
|
28
|
-
|
|
29
|
-
ioc.image_metadata_repository.clear
|
|
30
|
-
ioc.container_metadata_repository.clear
|
|
31
|
-
ioc.partial_metadata_repository.clear
|
|
32
|
-
ioc.network_metadata_repository.clear
|
|
33
|
-
|
|
34
|
-
ioc.logger.clear
|
|
35
|
-
|
|
36
|
-
FileUtils.rm_rf(Dir.glob(File.join(__dir__, '../tmp/*')))
|
|
37
|
-
end
|
|
26
|
+
config.after(:all) { truncate_docker_items }
|
|
38
27
|
end
|
|
39
28
|
|
|
40
29
|
def ensure_exists(file)
|
|
@@ -43,4 +32,37 @@ end
|
|
|
43
32
|
|
|
44
33
|
def ensure_content(file, content)
|
|
45
34
|
expect(File.read(file)).to match(content)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def truncate_docker_items
|
|
38
|
+
ioc.docker_api.delete_containers_where { |container| container.refresh!.info['Config']['Image'] =~ /^indocker/ }
|
|
39
|
+
ioc.docker_api.delete_containers_where { |container| container.refresh!.info['Names'].grep(/^\/indocker/).any? }
|
|
40
|
+
ioc.docker_api.delete_images_where { |image| image.info['RepoTags'].grep(/^indocker/).any? }
|
|
41
|
+
ioc.docker_api.delete_networks_where { |network| network.info['Name'] =~ /^indocker/ }
|
|
42
|
+
ioc.docker_api.delete_volumes_where { |volume| volume.info['Name'] =~ /^indocker/ }
|
|
43
|
+
|
|
44
|
+
ioc.image_metadata_repository.clear
|
|
45
|
+
ioc.container_metadata_repository.clear
|
|
46
|
+
ioc.partial_metadata_repository.clear
|
|
47
|
+
ioc.network_metadata_repository.clear
|
|
48
|
+
ioc.volume_metadata_repository.clear
|
|
49
|
+
|
|
50
|
+
ioc.logger.clear
|
|
51
|
+
|
|
52
|
+
FileUtils.rm_rf(Dir.glob(File.join(__dir__, '../tmp/*')))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def set_local_registry
|
|
56
|
+
Indocker.define_image :registry do
|
|
57
|
+
from 'registry:latest'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
Indocker.define_container :indocker_registry do
|
|
61
|
+
use images.find_by_repo(:registry)
|
|
62
|
+
env 'REGISTRY_STORAGE_DELETE_ENABLED=true'
|
|
63
|
+
ports '5000:1000'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
ioc.image_builder.build('registry')
|
|
67
|
+
ioc.container_manager.run('indocker_registry')
|
|
46
68
|
end
|