indocker 0.0.0 → 0.0.1
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/.gitignore +2 -1
- data/.rspec +1 -0
- data/Gemfile.lock +12 -0
- data/bin/indocker +9 -0
- data/indocker.gemspec +7 -2
- data/lib/indocker/application_initializer.rb +30 -0
- data/lib/indocker/cli.rb +17 -0
- data/lib/indocker/configs/config.rb +76 -0
- data/lib/indocker/configs/config_factory.rb +36 -0
- data/lib/indocker/configs/locator.rb +23 -0
- data/lib/indocker/container/container_dsl.rb +60 -0
- data/lib/indocker/container/container_evaluator.rb +13 -0
- data/lib/indocker/container/container_manager.rb +111 -0
- data/lib/indocker/container/container_metadata.rb +107 -0
- data/lib/indocker/container/container_metadata_factory.rb +27 -0
- data/lib/indocker/container/container_metadata_repository.rb +27 -0
- data/lib/indocker/directives/base.rb +21 -0
- data/lib/indocker/directives/container_directives/base.rb +19 -0
- data/lib/indocker/directives/container_directives/depends_on.rb +7 -0
- data/lib/indocker/directives/container_directives/env_file.rb +7 -0
- data/lib/indocker/directives/container_directives/expose.rb +7 -0
- data/lib/indocker/directives/container_directives/from.rb +12 -0
- data/lib/indocker/directives/container_directives/network.rb +12 -0
- data/lib/indocker/directives/container_directives/ports.rb +8 -0
- data/lib/indocker/directives/container_directives/ready.rb +16 -0
- data/lib/indocker/directives/container_directives_runner.rb +46 -0
- data/lib/indocker/directives/docker_directives/base.rb +15 -0
- data/lib/indocker/directives/docker_directives/cmd.rb +15 -0
- data/lib/indocker/directives/docker_directives/copy.rb +27 -0
- data/lib/indocker/directives/docker_directives/entrypoint.rb +15 -0
- data/lib/indocker/directives/docker_directives/env.rb +5 -0
- data/lib/indocker/directives/docker_directives/from.rb +30 -0
- data/lib/indocker/directives/docker_directives/run.rb +5 -0
- data/lib/indocker/directives/docker_directives/workdir.rb +5 -0
- data/lib/indocker/directives/image_directives_runner.rb +120 -0
- data/lib/indocker/directives/partial.rb +13 -0
- data/lib/indocker/directives/prepare_directives/base.rb +6 -0
- data/lib/indocker/directives/prepare_directives/docker_cp.rb +16 -0
- data/lib/indocker/docker_api.rb +180 -0
- data/lib/indocker/dsl_context.rb +17 -0
- data/lib/indocker/envs/env_metadata.rb +35 -0
- data/lib/indocker/envs/loader.rb +19 -0
- data/lib/indocker/envs/manager.rb +30 -0
- data/lib/indocker/errors.rb +17 -0
- data/lib/indocker/handlers/base.rb +13 -0
- data/lib/indocker/handlers/run_container.rb +29 -0
- data/lib/indocker/image/image_builder.rb +39 -0
- data/lib/indocker/image/image_dependencies_manager.rb +43 -0
- data/lib/indocker/image/image_dsl.rb +69 -0
- data/lib/indocker/image/image_evaluator.rb +21 -0
- data/lib/indocker/image/image_metadata.rb +50 -0
- data/lib/indocker/image/image_metadata_factory.rb +30 -0
- data/lib/indocker/image/image_metadata_repository.rb +30 -0
- data/lib/indocker/networks/network_metadata.rb +9 -0
- data/lib/indocker/networks/network_metadata_factory.rb +9 -0
- data/lib/indocker/networks/network_metadata_repository.rb +34 -0
- data/lib/indocker/partial/partial_metadata.rb +8 -0
- data/lib/indocker/partial/partial_metadata_repository.rb +26 -0
- data/lib/indocker/utils/ioc_container.rb +17 -0
- data/lib/indocker/utils/logger.rb +62 -0
- data/lib/indocker/utils/logger_factory.rb +12 -0
- data/lib/indocker/utils/registry_authenticator.rb +19 -0
- data/lib/indocker/utils/render_namespace.rb +11 -0
- data/lib/indocker/utils/render_util.rb +15 -0
- data/lib/indocker/utils/string_utils.rb +11 -0
- data/lib/indocker/utils/tar_helper.rb +40 -0
- data/lib/indocker/utils/test_logger_factory.rb +9 -0
- data/lib/indocker/version.rb +2 -2
- data/lib/indocker.rb +123 -1
- data/spec/example/.indocker/config.rb +23 -0
- data/spec/example/.indocker/images_and_containers.rb +25 -0
- data/spec/example/assets/index.css +1 -0
- data/spec/example/assets/index.js +1 -0
- data/spec/indocker/configs/config_factory_spec.rb +18 -0
- data/spec/indocker/configs/config_spec.rb +37 -0
- data/spec/indocker/container/container_manager_spec.rb +230 -0
- data/spec/indocker/directives/image_directives_runner_spec.rb +121 -0
- data/spec/indocker/handlers/run_container_spec.rb +107 -0
- data/spec/indocker/image/image_builder_spec.rb +115 -0
- data/spec/indocker/image/image_evaluator_spec.rb +65 -0
- data/spec/indocker/utils/docker_api_spec.rb +87 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/tmp/indocker_list_container_files/deeper/example3.txt +1 -0
- data/spec/tmp/indocker_list_container_files/deeper/example4.txt +1 -0
- data/spec/tmp/indocker_list_container_files/example1.txt +1 -0
- data/spec/tmp/indocker_list_container_files/example2.txt +1 -0
- metadata +159 -6
- data/spec/.gitkeep +0 -0
data/lib/indocker.rb
CHANGED
|
@@ -1,2 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
require 'smart_ioc'
|
|
2
|
+
require 'docker-api'
|
|
3
|
+
require 'logger'
|
|
4
|
+
|
|
5
|
+
SmartIoC.find_package_beans(:indocker, __dir__)
|
|
6
|
+
SmartIoC.set_load_proc do |location|
|
|
7
|
+
require(location)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
Docker.options = { read_timeout: 600, write_timeout: 600 }
|
|
11
|
+
|
|
12
|
+
require 'indocker/errors'
|
|
13
|
+
require 'indocker/cli'
|
|
14
|
+
require 'indocker/docker_api'
|
|
15
|
+
require 'indocker/dsl_context'
|
|
16
|
+
|
|
17
|
+
require 'indocker/configs/config'
|
|
18
|
+
require 'indocker/configs/config_factory'
|
|
19
|
+
require 'indocker/configs/locator'
|
|
20
|
+
|
|
21
|
+
require 'indocker/utils/logger'
|
|
22
|
+
require 'indocker/utils/logger_factory'
|
|
23
|
+
require 'indocker/utils/test_logger_factory'
|
|
24
|
+
require 'indocker/utils/tar_helper'
|
|
25
|
+
require 'indocker/utils/string_utils'
|
|
26
|
+
require 'indocker/utils/registry_authenticator'
|
|
27
|
+
require 'indocker/utils/render_util'
|
|
28
|
+
require 'indocker/utils/render_namespace'
|
|
29
|
+
|
|
30
|
+
require 'indocker/handlers/base'
|
|
31
|
+
require 'indocker/handlers/run_container'
|
|
32
|
+
|
|
33
|
+
require 'indocker/utils/ioc_container'
|
|
34
|
+
|
|
35
|
+
require 'indocker/envs/env_metadata'
|
|
36
|
+
require 'indocker/envs/manager'
|
|
37
|
+
require 'indocker/envs/loader'
|
|
38
|
+
|
|
39
|
+
require 'indocker/image/image_metadata'
|
|
40
|
+
require 'indocker/image/image_metadata_factory'
|
|
41
|
+
require 'indocker/image/image_dsl'
|
|
42
|
+
require 'indocker/image/image_metadata_repository'
|
|
43
|
+
require 'indocker/image/image_builder'
|
|
44
|
+
require 'indocker/image/image_dependencies_manager'
|
|
45
|
+
require 'indocker/image/image_evaluator'
|
|
46
|
+
|
|
47
|
+
require 'indocker/container/container_metadata'
|
|
48
|
+
require 'indocker/container/container_metadata_repository'
|
|
49
|
+
require 'indocker/container/container_metadata_factory'
|
|
50
|
+
require 'indocker/container/container_manager'
|
|
51
|
+
require 'indocker/container/container_evaluator'
|
|
52
|
+
require 'indocker/container/container_dsl'
|
|
53
|
+
|
|
54
|
+
require 'indocker/partial/partial_metadata'
|
|
55
|
+
require 'indocker/partial/partial_metadata_repository'
|
|
56
|
+
|
|
57
|
+
require 'indocker/directives/image_directives_runner'
|
|
58
|
+
require 'indocker/directives/container_directives_runner'
|
|
59
|
+
require 'indocker/directives/base'
|
|
60
|
+
require 'indocker/directives/partial'
|
|
61
|
+
|
|
62
|
+
require 'indocker/networks/network_metadata'
|
|
63
|
+
require 'indocker/networks/network_metadata_factory'
|
|
64
|
+
require 'indocker/networks/network_metadata_repository'
|
|
65
|
+
|
|
66
|
+
require 'indocker/directives/docker_directives/base'
|
|
67
|
+
require 'indocker/directives/docker_directives/cmd'
|
|
68
|
+
require 'indocker/directives/docker_directives/entrypoint'
|
|
69
|
+
require 'indocker/directives/docker_directives/env'
|
|
70
|
+
require 'indocker/directives/docker_directives/copy'
|
|
71
|
+
require 'indocker/directives/docker_directives/from'
|
|
72
|
+
require 'indocker/directives/docker_directives/run'
|
|
73
|
+
require 'indocker/directives/docker_directives/workdir'
|
|
74
|
+
|
|
75
|
+
require 'indocker/directives/prepare_directives/base'
|
|
76
|
+
require 'indocker/directives/prepare_directives/docker_cp'
|
|
77
|
+
|
|
78
|
+
require 'indocker/directives/container_directives/base'
|
|
79
|
+
require 'indocker/directives/container_directives/from'
|
|
80
|
+
require 'indocker/directives/container_directives/network'
|
|
81
|
+
require 'indocker/directives/container_directives/env_file'
|
|
82
|
+
require 'indocker/directives/container_directives/ports'
|
|
83
|
+
require 'indocker/directives/container_directives/expose'
|
|
84
|
+
require 'indocker/directives/container_directives/depends_on'
|
|
85
|
+
require 'indocker/directives/container_directives/ready'
|
|
86
|
+
|
|
87
|
+
module Indocker
|
|
88
|
+
DOCKERFILE_NAME = 'Dockerfile'
|
|
89
|
+
BUILD_DIR = 'tmp/build'
|
|
90
|
+
|
|
91
|
+
class << self
|
|
92
|
+
def define_image(name, &definition)
|
|
93
|
+
ioc.image_metadata_repository.put(
|
|
94
|
+
ioc.image_metadata_factory.create(name, &definition)
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def define_container(name, &definition)
|
|
99
|
+
ioc.container_metadata_repository.put(
|
|
100
|
+
ioc.container_metadata_factory.create(name, &definition)
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def define_partial(name, &definition)
|
|
105
|
+
ioc.partial_metadata_repository.put(
|
|
106
|
+
Indocker::PartialMetadata.new(name, &definition)
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def define_network(name)
|
|
111
|
+
ioc.network_metadata_repository.put(
|
|
112
|
+
ioc.network_metadata_factory.create(name)
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def setup(&block)
|
|
117
|
+
ioc.config.set(&block)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def root(dir = nil)
|
|
121
|
+
ioc.config.root(dir)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
2
124
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Idocker.setup do
|
|
2
|
+
namespace 'indocker_example'
|
|
3
|
+
root File.dirname(__dir__)
|
|
4
|
+
|
|
5
|
+
load_env_file '.indocker/env_files'
|
|
6
|
+
load_docker_items [
|
|
7
|
+
'.indocker/images_and_containers.rb'
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
git do
|
|
11
|
+
repository 'https://github.com/droidlabs/indocker'
|
|
12
|
+
tag 'latest'
|
|
13
|
+
branch 'master'
|
|
14
|
+
workdir 'some/path'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
docker do
|
|
18
|
+
registry 'localhost:5000'
|
|
19
|
+
skip_push true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
build_server :build_server
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Indocker.define_image 'sample_package' do
|
|
2
|
+
before_build do
|
|
3
|
+
docker_cp 'assets_compiler' do
|
|
4
|
+
copy 'assets' => 'assets'
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
from 'ubuntu'
|
|
9
|
+
|
|
10
|
+
run 'mkdir /app'
|
|
11
|
+
workdir 'app'
|
|
12
|
+
entrypoint 'ls > ls.txt'
|
|
13
|
+
|
|
14
|
+
cmd 'pwd'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Indocker.define_container 'assets_compiler' do
|
|
18
|
+
use images.assets_compiler
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Indocker.define_image 'assets_compiler' do
|
|
22
|
+
from 'ubuntu'
|
|
23
|
+
|
|
24
|
+
copy 'assets/.', '/assets'
|
|
25
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* { display: <%= display %>; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<% if use_strict %>'use strict';<% end %>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::Configs::ConfigFactory do
|
|
4
|
+
subject { ioc.config }
|
|
5
|
+
|
|
6
|
+
it 'returns Indocker::Configs::Config object' do
|
|
7
|
+
expect(subject).to be_a(Indocker::Configs::Config)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context '#option' do
|
|
11
|
+
it 'pass method to Indocker::Configs::Config object' do
|
|
12
|
+
subject.option(:example_method)
|
|
13
|
+
subject.example_method('example_value')
|
|
14
|
+
|
|
15
|
+
expect(subject.example_method).to eq('example_value')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::Configs::Config do
|
|
4
|
+
subject { described_class.new }
|
|
5
|
+
|
|
6
|
+
describe '#option' do
|
|
7
|
+
it 'creates setter and getter methods with the same name' do
|
|
8
|
+
subject.option(:some_key, group: :default, type: :string)
|
|
9
|
+
subject.some_key('some_value')
|
|
10
|
+
|
|
11
|
+
expect(subject.some_key).to eq('some_value')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'validates setter value with :type attribute' do
|
|
15
|
+
subject.option(:some_key, group: :default, type: :boolean)
|
|
16
|
+
|
|
17
|
+
expect{
|
|
18
|
+
subject.some_key('test')
|
|
19
|
+
}.to raise_error(Indocker::Errors::ConfigOptionTypeMismatch, 'Expected option :some_key => "test" to be a :boolean, not a :string')
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#config' do
|
|
24
|
+
it 'creates getter and subconfiguration object' do
|
|
25
|
+
subject.config(:example_config) do
|
|
26
|
+
option(:key1)
|
|
27
|
+
option(:key2, type: :array)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
subject.example_config.key1('value1')
|
|
31
|
+
subject.example_config.key2(['value2'])
|
|
32
|
+
|
|
33
|
+
expect(subject.example_config.key1).to eq('value1')
|
|
34
|
+
expect(subject.example_config.key2).to match(['value2'])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::ContainerManager do
|
|
4
|
+
let(:container_manager) { ioc.container_manager }
|
|
5
|
+
let(:docker_api) { ioc.docker_api }
|
|
6
|
+
|
|
7
|
+
describe '#create' do
|
|
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
|
|
14
|
+
|
|
15
|
+
ioc.image_builder.build('indocker_image')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'for existing image' do
|
|
19
|
+
before do
|
|
20
|
+
Indocker.define_container 'indocker_simple_container' do
|
|
21
|
+
use images.indocker_image
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'runs container' do
|
|
26
|
+
container_manager.create('indocker_simple_container')
|
|
27
|
+
|
|
28
|
+
expect(
|
|
29
|
+
ioc.docker_api.container_exists?('indocker_simple_container')
|
|
30
|
+
).to be true
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#start' do
|
|
36
|
+
before do
|
|
37
|
+
Indocker.define_image 'indocker_image' do
|
|
38
|
+
from 'alpine:latest'
|
|
39
|
+
workdir '.'
|
|
40
|
+
cmd %w(tail -F -n0 /etc/hosts)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
ioc.image_builder.build('indocker_image')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'with ready timeout' do
|
|
47
|
+
before do
|
|
48
|
+
Indocker.define_container 'indocker_timeout_container' do
|
|
49
|
+
use images.indocker_image
|
|
50
|
+
|
|
51
|
+
ready sleep: 0.1, timeout: 1 do
|
|
52
|
+
sleep 0.5
|
|
53
|
+
true
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
Indocker.define_container 'indocker_timeout_error_container' do
|
|
58
|
+
use images.indocker_image
|
|
59
|
+
|
|
60
|
+
ready sleep: 0.1, timeout: 1 do
|
|
61
|
+
false
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
ioc.container_manager.create('indocker_timeout_container')
|
|
67
|
+
ioc.container_manager.create('indocker_timeout_error_container')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
after do
|
|
71
|
+
container_manager.stop('indocker_timeout_container')
|
|
72
|
+
container_manager.delete('indocker_timeout_container')
|
|
73
|
+
container_manager.stop('indocker_timeout_error_container')
|
|
74
|
+
container_manager.delete('indocker_timeout_error_container')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'starts container if ready_block returns true' do
|
|
78
|
+
container_manager.start('indocker_timeout_container')
|
|
79
|
+
|
|
80
|
+
expect(
|
|
81
|
+
docker_api.get_container_state('indocker_timeout_container')
|
|
82
|
+
).to eq(Indocker::ContainerMetadata::States::RUNNING)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'raises Indocker::Errors::ContainerTimeoutError error if ready_block returns false' do
|
|
86
|
+
expect{
|
|
87
|
+
container_manager.start('indocker_timeout_error_container')
|
|
88
|
+
}.to raise_error(Indocker::Errors::ContainerTimeoutError)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context 'with container dependencies' do
|
|
93
|
+
let(:main_container_id) { docker_api.get_container_id('indocker_main_container') }
|
|
94
|
+
let(:dependecy_container_id) { docker_api.get_container_id('indocker_dependency_container') }
|
|
95
|
+
|
|
96
|
+
before do
|
|
97
|
+
Indocker.define_container 'indocker_dependency_container' do
|
|
98
|
+
use images.indocker_image
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
Indocker.define_container 'indocker_main_container' do
|
|
102
|
+
use images.indocker_image
|
|
103
|
+
|
|
104
|
+
depends_on containers.get_by_name('indocker_dependency_container')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
ioc.container_manager.create('indocker_main_container')
|
|
108
|
+
ioc.container_manager.create('indocker_dependency_container')
|
|
109
|
+
|
|
110
|
+
container_manager.start('indocker_main_container')
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
after do
|
|
114
|
+
container_manager.stop('indocker_main_container')
|
|
115
|
+
container_manager.delete('indocker_main_container')
|
|
116
|
+
container_manager.stop('indocker_dependency_container')
|
|
117
|
+
container_manager.delete('indocker_dependency_container')
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'runs dependency container before' do
|
|
121
|
+
expect(
|
|
122
|
+
docker_api.get_container_state('indocker_dependency_container')
|
|
123
|
+
).to eq(Indocker::ContainerMetadata::States::RUNNING)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context 'with specified network' do
|
|
128
|
+
let(:container_id) { docker_api.get_container_id('indocker_simple_container') }
|
|
129
|
+
let(:network_id) { docker_api.get_network_id('indocker_network') }
|
|
130
|
+
|
|
131
|
+
before do
|
|
132
|
+
Indocker.define_network 'indocker_network'
|
|
133
|
+
|
|
134
|
+
Indocker.define_container 'indocker_simple_container' do
|
|
135
|
+
use images.indocker_image
|
|
136
|
+
use networks.indocker_network
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
ioc.container_manager.create('indocker_simple_container')
|
|
140
|
+
|
|
141
|
+
container_manager.start('indocker_simple_container')
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
after do
|
|
145
|
+
container_manager.stop('indocker_simple_container')
|
|
146
|
+
container_manager.delete('indocker_simple_container')
|
|
147
|
+
docker_api.remove_network('indocker_network')
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context 'creates network before start' do
|
|
151
|
+
it 'for new network' do
|
|
152
|
+
expect(network_id).to match(/[\w\d]{64}/)
|
|
153
|
+
expect(docker_api.network_exists?('indocker_network')).to be true
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'if network already exists' do
|
|
157
|
+
container_manager.stop('indocker_simple_container')
|
|
158
|
+
container_manager.start('indocker_simple_container')
|
|
159
|
+
|
|
160
|
+
expect(network_id).to match(/[\w\d]{64}/)
|
|
161
|
+
expect(docker_api.network_exists?('indocker_network')).to be true
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it 'connect container to specified network' do
|
|
166
|
+
expect(
|
|
167
|
+
docker_api.inspect_network(network_id)['Containers'].keys
|
|
168
|
+
).to include(container_id)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'starts container' do
|
|
172
|
+
expect(
|
|
173
|
+
docker_api.get_container_state(container_id)
|
|
174
|
+
).to eq(Indocker::ContainerMetadata::States::RUNNING)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
describe '#copy' do
|
|
180
|
+
let(:copy_to_path) { File.expand_path File.join(__dir__, '../../tmp/indocker_list_container_files') }
|
|
181
|
+
|
|
182
|
+
before do
|
|
183
|
+
Indocker.define_image 'indocker_copy_image' do
|
|
184
|
+
from 'alpine'
|
|
185
|
+
|
|
186
|
+
run 'mkdir -p /sample'
|
|
187
|
+
run 'mkdir -p /sample/deeper'
|
|
188
|
+
run 'echo "example1.txt" > /sample/example1.txt'
|
|
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']
|
|
194
|
+
end
|
|
195
|
+
ioc.image_builder.build('indocker_copy_image')
|
|
196
|
+
|
|
197
|
+
Indocker.define_container :indocker_copy_container do
|
|
198
|
+
use images.indocker_copy_image
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'returns files list' do
|
|
203
|
+
expect(
|
|
204
|
+
container_manager.copy(
|
|
205
|
+
name: :indocker_copy_container,
|
|
206
|
+
copy_from: '/sample/deeper',
|
|
207
|
+
copy_to: copy_to_path
|
|
208
|
+
)
|
|
209
|
+
).to match(
|
|
210
|
+
[
|
|
211
|
+
'deeper/example3.txt',
|
|
212
|
+
'deeper/example4.txt'
|
|
213
|
+
]
|
|
214
|
+
)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it 'copies files to output path' do
|
|
218
|
+
container_manager.copy(
|
|
219
|
+
name: :indocker_copy_container,
|
|
220
|
+
copy_from: '/sample/.',
|
|
221
|
+
copy_to: copy_to_path
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
ensure_content(File.join(copy_to_path, 'example1.txt'), 'example1.txt')
|
|
225
|
+
ensure_content(File.join(copy_to_path, 'example2.txt'), 'example2.txt')
|
|
226
|
+
ensure_content(File.join(copy_to_path, 'deeper/example3.txt'), 'example3.txt')
|
|
227
|
+
ensure_content(File.join(copy_to_path, 'deeper/example4.txt'), 'example4.txt')
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Indocker::ImageDirectivesRunner do
|
|
4
|
+
let(:image_directives_runner) { ioc.image_directives_runner }
|
|
5
|
+
|
|
6
|
+
let(:context) {
|
|
7
|
+
Indocker::DSLContext.new(
|
|
8
|
+
display: 'none',
|
|
9
|
+
use_strict: true,
|
|
10
|
+
build_dir: build_dir
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let(:directive) {
|
|
15
|
+
Indocker::DockerDirectives::Copy.new(
|
|
16
|
+
context: context,
|
|
17
|
+
copy_actions: {
|
|
18
|
+
from_path => to_path
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let(:from_path) { 'assets/.' }
|
|
24
|
+
let(:to_path) { '/assets' }
|
|
25
|
+
|
|
26
|
+
describe "#run_copy" do
|
|
27
|
+
let(:build_dir) { ioc.config.root.join('../../tmp/build_dir') }
|
|
28
|
+
|
|
29
|
+
context 'for :from as directory path' do
|
|
30
|
+
context "when directory exists in build directory" do
|
|
31
|
+
before do
|
|
32
|
+
FileUtils.mkdir_p(File.join(build_dir, 'assets'))
|
|
33
|
+
File.open(build_dir.join('assets', 'index.css'), 'w') {|f| f.write("/* located at build directory */")}
|
|
34
|
+
File.open(build_dir.join('assets', 'index.js'), 'w') {|f| f.write("// located at build directory")}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'copy files from root to build directory' do
|
|
38
|
+
image_directives_runner.run(directive)
|
|
39
|
+
|
|
40
|
+
ensure_content(build_dir.join('assets', 'index.css'), "/* located at build directory */")
|
|
41
|
+
ensure_content(build_dir.join('assets', 'index.js'), "// located at build directory")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when directory exists in project root directory" do
|
|
46
|
+
it 'copy files from root to build directory' do
|
|
47
|
+
image_directives_runner.run(directive)
|
|
48
|
+
|
|
49
|
+
ensure_content(build_dir.join('assets', 'index.css'), "* { display: <%= display %>; }")
|
|
50
|
+
ensure_content(build_dir.join('assets', 'index.js'), "<% if use_strict %>'use strict';<% end %>")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "when directory does not exists" do
|
|
55
|
+
let(:from_path) { 'invalid/dir/.' }
|
|
56
|
+
let(:to_path) { '/invalid/dir' }
|
|
57
|
+
|
|
58
|
+
it "raises error Indocker::Errors::FileDoesNotExists" do
|
|
59
|
+
expect{
|
|
60
|
+
image_directives_runner.run(directive)
|
|
61
|
+
}.to raise_error(Indocker::Errors::FileDoesNotExists)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'with compile: true option' do
|
|
66
|
+
let(:directive) {
|
|
67
|
+
Indocker::DockerDirectives::Copy.new(
|
|
68
|
+
context: context,
|
|
69
|
+
copy_actions: {
|
|
70
|
+
from_path => to_path
|
|
71
|
+
},
|
|
72
|
+
compile: true
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
it 'copy compiles files from root to build directory' do
|
|
77
|
+
image_directives_runner.run(directive)
|
|
78
|
+
|
|
79
|
+
ensure_content(build_dir.join('assets', 'index.css'), "* { display: none; }")
|
|
80
|
+
ensure_content(build_dir.join('assets', 'index.js'), "'use strict';")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "for :from as single file path" do
|
|
86
|
+
let(:from_path) { 'assets/index.css' }
|
|
87
|
+
let(:to_path) { '/assets' }
|
|
88
|
+
|
|
89
|
+
context 'without compilation' do
|
|
90
|
+
it 'copy files from root to build directory if no file in build directory' do
|
|
91
|
+
image_directives_runner.run(directive)
|
|
92
|
+
|
|
93
|
+
ensure_content(build_dir.join('assets', 'index.css'), "* { display: <%= display %>; }")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context 'with compilaton' do
|
|
98
|
+
let(:directive) {
|
|
99
|
+
Indocker::DockerDirectives::Copy.new(
|
|
100
|
+
context: context,
|
|
101
|
+
copy_actions: {
|
|
102
|
+
from_path => to_path
|
|
103
|
+
},
|
|
104
|
+
compile: true
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
before do
|
|
109
|
+
FileUtils.mkdir_p(File.join(build_dir, 'assets'))
|
|
110
|
+
File.open(build_dir.join('assets', 'index.css'), 'w') {|f| f.write("/* <%= display %>; */")}
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'compiles and overwrites file is present in build directory' do
|
|
114
|
+
image_directives_runner.run(directive)
|
|
115
|
+
|
|
116
|
+
ensure_content(build_dir.join('assets', 'index.css'), "/* none; */")
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Indocker::Handlers::RunContainer' do
|
|
4
|
+
subject { ioc.run_container_handler }
|
|
5
|
+
|
|
6
|
+
describe '#handle' do
|
|
7
|
+
context 'for valid cmd process in container' do
|
|
8
|
+
let(:container) { ioc.container_metadata_repository.get_by_name(:indocker_correct_container) }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
Indocker.define_image :indocker_correct_image do
|
|
12
|
+
from 'alpine:latest'
|
|
13
|
+
|
|
14
|
+
cmd ['/bin/sh']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Indocker.define_container :indocker_correct_container do
|
|
18
|
+
use images.indocker_correct_image
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'for new container' do
|
|
23
|
+
before do
|
|
24
|
+
subject.handle(name: :indocker_correct_container, current_path: nil)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'creates container' do
|
|
28
|
+
expect(
|
|
29
|
+
ioc.docker_api.container_exists?(:indocker_correct_container)
|
|
30
|
+
).to be true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'runs container' do
|
|
34
|
+
expect(
|
|
35
|
+
ioc.docker_api.get_container_state(:indocker_correct_container)
|
|
36
|
+
).to eq(Indocker::ContainerMetadata::States::RUNNING)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'logs successfull result' do
|
|
40
|
+
expect(
|
|
41
|
+
ioc.logger.messages.last
|
|
42
|
+
).to eq("INFO".colorize(:green) + ": Successfully started container :indocker_correct_container")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'for existing container' do
|
|
47
|
+
before do
|
|
48
|
+
subject.handle(name: :indocker_correct_container, current_path: nil)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'stops, destroy and create container again' do
|
|
52
|
+
old_container_id = ioc.docker_api.get_container_id(:indocker_correct_container)
|
|
53
|
+
|
|
54
|
+
subject.handle(name: :indocker_correct_container, current_path: nil)
|
|
55
|
+
|
|
56
|
+
new_container_id = ioc.docker_api.get_container_id(:indocker_correct_container)
|
|
57
|
+
|
|
58
|
+
expect(new_container_id).not_to eq(old_container_id)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'runs container again' do
|
|
62
|
+
subject.handle(name: :indocker_correct_container, current_path: nil)
|
|
63
|
+
|
|
64
|
+
expect(
|
|
65
|
+
ioc.docker_api.get_container_state(:indocker_correct_container)
|
|
66
|
+
).to eq(Indocker::ContainerMetadata::States::RUNNING)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'logs successfull result' do
|
|
70
|
+
expect(
|
|
71
|
+
ioc.logger.messages.last
|
|
72
|
+
).to eq("INFO".colorize(:green) + ": Successfully started container :indocker_correct_container")
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'for falling cmd process in container' do
|
|
78
|
+
let(:container) { ioc.container_metadata_repository.get_by_name(:container_with_falling_cmd) }
|
|
79
|
+
|
|
80
|
+
before do
|
|
81
|
+
Indocker.define_image :indocker_image_with_falling_cmd do
|
|
82
|
+
from 'alpine:latest'
|
|
83
|
+
|
|
84
|
+
cmd ['invalid/process']
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
Indocker.define_container :container_with_falling_cmd do
|
|
88
|
+
use images.indocker_image_with_falling_cmd
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
subject.handle(name: :container_with_falling_cmd, current_path: nil)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'logs error text' do
|
|
95
|
+
expect(
|
|
96
|
+
ioc.logger.messages.last
|
|
97
|
+
).to eq("ERROR".colorize(:red) + ": oci runtime error: container_linux.go:265: starting container process caused \"exec: \\\"invalid/process\\\": stat invalid/process: no such file or directory\"")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'does not run container' do
|
|
101
|
+
expect(
|
|
102
|
+
ioc.docker_api.get_container_state(:container_with_falling_cmd)
|
|
103
|
+
).to eq(Indocker::ContainerMetadata::States::CREATED)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|