indocker 0.0.6 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +10 -2
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +19 -49
- data/LICENSE.txt +17 -18
- data/README.md +20 -1
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/indocker/bin/deploy +120 -0
- data/example/indocker/bin/remote/compile +72 -0
- data/example/indocker/bin/remote/run +66 -0
- data/example/indocker/bin/utils/configurations.rb +3 -0
- data/example/indocker/bounded_contexts/shared/ruby/Dockerfile +10 -0
- data/example/indocker/bounded_contexts/shared/ruby/container.rb +5 -0
- data/example/indocker/bounded_contexts/shared/ruby/image.rb +3 -0
- data/example/indocker/configurations/dev.rb +9 -0
- data/example/indocker/infrastructure/build_servers.rb +8 -0
- data/example/indocker/infrastructure/networks.rb +1 -0
- data/example/indocker/infrastructure/registries.rb +3 -0
- data/example/indocker/infrastructure/servers.rb +8 -0
- data/example/indocker/setup.rb +24 -0
- data/indocker.gemspec +27 -25
- data/lib/indocker.rb +437 -130
- data/lib/indocker/artifacts/git.rb +25 -0
- data/lib/indocker/build_context.rb +87 -0
- data/lib/indocker/build_context_helper.rb +109 -0
- data/lib/indocker/build_context_pool.rb +36 -0
- data/lib/indocker/build_server.rb +2 -0
- data/lib/indocker/colored_string.rb +33 -0
- data/lib/indocker/concerns/inspectable.rb +12 -0
- data/lib/indocker/configuration_deployer.rb +525 -0
- data/lib/indocker/configurations/configuration.rb +122 -0
- data/lib/indocker/configurations/configuration_builder.rb +250 -0
- data/lib/indocker/configurations/formatters/stdout.rb +36 -0
- data/lib/indocker/container_deployer.rb +73 -0
- data/lib/indocker/container_helper.rb +13 -0
- data/lib/indocker/container_runner.rb +23 -0
- data/lib/indocker/containers/container.rb +118 -0
- data/lib/indocker/containers/container_builder.rb +186 -0
- data/lib/indocker/containers/restart_policy.rb +36 -0
- data/lib/indocker/context_args.rb +43 -0
- data/lib/indocker/crontab_redeploy_rules_builder.rb +54 -0
- data/lib/indocker/deploy_context.rb +126 -0
- data/lib/indocker/deployment_checker.rb +121 -0
- data/lib/indocker/deployment_progress.rb +495 -0
- data/lib/indocker/docker.rb +87 -0
- data/lib/indocker/docker_run_args.rb +183 -0
- data/lib/indocker/env_file_helper.rb +13 -0
- data/lib/indocker/env_files/local.rb +8 -0
- data/lib/indocker/env_files/remote.rb +8 -0
- data/lib/indocker/hash_merger.rb +9 -0
- data/lib/indocker/images/image.rb +86 -0
- data/lib/indocker/images/image_builder.rb +98 -0
- data/lib/indocker/images/image_compiler.rb +68 -0
- data/lib/indocker/images/template_compiler.rb +15 -0
- data/lib/indocker/images/templates_compiler.rb +28 -0
- data/lib/indocker/images_compiler.rb +38 -0
- data/lib/indocker/indocker_helper.rb +9 -0
- data/lib/indocker/network.rb +12 -0
- data/lib/indocker/network_helper.rb +7 -0
- data/lib/indocker/registries/abstract.rb +17 -0
- data/lib/indocker/registries/local.rb +5 -0
- data/lib/indocker/registries/remote.rb +12 -0
- data/lib/indocker/repositories/abstract.rb +25 -0
- data/lib/indocker/repositories/clonner.rb +17 -0
- data/lib/indocker/repositories/git.rb +24 -0
- data/lib/indocker/repositories/local.rb +20 -0
- data/lib/indocker/repositories/no_sync.rb +20 -0
- data/lib/indocker/rsync.rb +52 -0
- data/lib/indocker/server.rb +20 -0
- data/lib/indocker/server_pool.rb +30 -0
- data/lib/indocker/shell.rb +60 -0
- data/lib/indocker/ssh_result_logger.rb +18 -0
- data/lib/indocker/ssh_session.rb +92 -0
- data/lib/indocker/version.rb +1 -1
- data/lib/indocker/volume_helper.rb +7 -0
- data/lib/indocker/volumes/external.rb +8 -0
- data/lib/indocker/volumes/local.rb +9 -0
- data/lib/indocker/volumes/repository.rb +9 -0
- metadata +107 -222
- data/bin/indocker +0 -9
- data/lib/indocker/application_initializer.rb +0 -19
- data/lib/indocker/cli.rb +0 -27
- data/lib/indocker/configs/config.rb +0 -147
- data/lib/indocker/configs/config_factory.rb +0 -37
- data/lib/indocker/configs/config_initializer.rb +0 -9
- data/lib/indocker/configs/locator.rb +0 -23
- data/lib/indocker/container/container_builder.rb +0 -29
- data/lib/indocker/container/container_directives_runner.rb +0 -54
- data/lib/indocker/container/container_dsl.rb +0 -83
- data/lib/indocker/container/container_evaluator.rb +0 -13
- data/lib/indocker/container/container_inspector.rb +0 -26
- data/lib/indocker/container/container_manager.rb +0 -122
- data/lib/indocker/container/container_metadata.rb +0 -112
- data/lib/indocker/container/container_metadata_factory.rb +0 -30
- data/lib/indocker/container/container_metadata_repository.rb +0 -27
- data/lib/indocker/directives/base.rb +0 -17
- data/lib/indocker/directives/container_directives/base.rb +0 -23
- data/lib/indocker/directives/container_directives/cmd.rb +0 -7
- data/lib/indocker/directives/container_directives/depends_on.rb +0 -7
- data/lib/indocker/directives/container_directives/env.rb +0 -7
- data/lib/indocker/directives/container_directives/env_file.rb +0 -7
- data/lib/indocker/directives/container_directives/expose.rb +0 -7
- data/lib/indocker/directives/container_directives/from.rb +0 -14
- data/lib/indocker/directives/container_directives/network.rb +0 -12
- data/lib/indocker/directives/container_directives/ports.rb +0 -15
- data/lib/indocker/directives/container_directives/ready.rb +0 -16
- data/lib/indocker/directives/container_directives/volume.rb +0 -23
- data/lib/indocker/directives/image_directives/base.rb +0 -27
- data/lib/indocker/directives/image_directives/cmd.rb +0 -19
- data/lib/indocker/directives/image_directives/copy.rb +0 -32
- data/lib/indocker/directives/image_directives/docker_cp.rb +0 -20
- data/lib/indocker/directives/image_directives/entrypoint.rb +0 -19
- data/lib/indocker/directives/image_directives/env.rb +0 -9
- data/lib/indocker/directives/image_directives/env_file.rb +0 -19
- data/lib/indocker/directives/image_directives/expose.rb +0 -9
- data/lib/indocker/directives/image_directives/from.rb +0 -36
- data/lib/indocker/directives/image_directives/registry.rb +0 -30
- data/lib/indocker/directives/image_directives/run.rb +0 -17
- data/lib/indocker/directives/image_directives/workdir.rb +0 -9
- data/lib/indocker/directives/partial.rb +0 -21
- data/lib/indocker/docker_api/container_config.rb +0 -121
- data/lib/indocker/docker_api/docker_api.rb +0 -207
- data/lib/indocker/dsl_context.rb +0 -21
- data/lib/indocker/envs/env_metadata.rb +0 -39
- data/lib/indocker/envs/loader.rb +0 -19
- data/lib/indocker/errors.rb +0 -21
- data/lib/indocker/git/git_api.rb +0 -32
- data/lib/indocker/git/git_helper.rb +0 -34
- data/lib/indocker/git/git_service.rb +0 -21
- data/lib/indocker/handlers/container_run.rb +0 -20
- data/lib/indocker/handlers/container_stop.rb +0 -17
- data/lib/indocker/handlers/performable.rb +0 -22
- data/lib/indocker/image/image_builder.rb +0 -54
- data/lib/indocker/image/image_dependencies_manager.rb +0 -47
- data/lib/indocker/image/image_directives_runner.rb +0 -99
- data/lib/indocker/image/image_dockerfile_builder.rb +0 -24
- data/lib/indocker/image/image_dsl.rb +0 -89
- data/lib/indocker/image/image_evaluator.rb +0 -21
- data/lib/indocker/image/image_helper.rb +0 -9
- data/lib/indocker/image/image_metadata.rb +0 -50
- data/lib/indocker/image/image_metadata_factory.rb +0 -31
- data/lib/indocker/image/image_metadata_repository.rb +0 -29
- data/lib/indocker/networks/network_metadata.rb +0 -9
- data/lib/indocker/networks/network_metadata_factory.rb +0 -9
- data/lib/indocker/networks/network_metadata_repository.rb +0 -34
- data/lib/indocker/partial/partial_metadata.rb +0 -8
- data/lib/indocker/partial/partial_metadata_repository.rb +0 -26
- data/lib/indocker/registry/registry_api.rb +0 -46
- data/lib/indocker/registry/registry_helper.rb +0 -20
- data/lib/indocker/registry/registry_service.rb +0 -28
- data/lib/indocker/utils/ioc_container.rb +0 -17
- data/lib/indocker/utils/logger.rb +0 -62
- data/lib/indocker/utils/logger_factory.rb +0 -13
- data/lib/indocker/utils/registry_authenticator.rb +0 -19
- data/lib/indocker/utils/render_namespace.rb +0 -11
- data/lib/indocker/utils/render_util.rb +0 -15
- data/lib/indocker/utils/string_utils.rb +0 -11
- data/lib/indocker/utils/tar_helper.rb +0 -40
- data/lib/indocker/utils/test_logger_factory.rb +0 -9
- data/lib/indocker/volumes/volume_metadata.rb +0 -9
- data/lib/indocker/volumes/volume_metadata_factory.rb +0 -9
- data/lib/indocker/volumes/volume_metadata_repository.rb +0 -34
- data/spec/example/.indocker/config.rb +0 -30
- data/spec/example/.indocker/images_and_containers.rb +0 -25
- data/spec/example/assets/index.css +0 -1
- data/spec/example/assets/index.js +0 -1
- data/spec/fixtures/spec.env +0 -2
- data/spec/indocker/configs/config_factory_spec.rb +0 -18
- data/spec/indocker/configs/config_spec.rb +0 -88
- data/spec/indocker/container/container_builder_spec.rb +0 -67
- data/spec/indocker/container/container_manager_spec.rb +0 -278
- data/spec/indocker/docker_api/container_config_spec.rb +0 -64
- data/spec/indocker/docker_api/docker_api_spec.rb +0 -112
- data/spec/indocker/handlers/container_run_spec.rb +0 -60
- data/spec/indocker/image/image_builder_spec.rb +0 -153
- data/spec/indocker/image/image_directives_runner_spec.rb +0 -141
- data/spec/indocker/image/image_dockerfile_builder_spec.rb +0 -25
- data/spec/indocker/image/image_evaluator_spec.rb +0 -85
- data/spec/spec_helper.rb +0 -68
@@ -1,30 +0,0 @@
|
|
1
|
-
Idocker.setup do
|
2
|
-
namespace 'indocker_example'
|
3
|
-
|
4
|
-
load_env_file '.indocker/env_files'
|
5
|
-
load_docker_items [
|
6
|
-
'.indocker/images_and_containers.rb'
|
7
|
-
]
|
8
|
-
|
9
|
-
docker do
|
10
|
-
registry :indocker do
|
11
|
-
serveraddress: 'localhost:1000'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
git do
|
16
|
-
cache_dir '/tmp/indocker'
|
17
|
-
|
18
|
-
repo :indocker do
|
19
|
-
repository 'https://github.com/droidlabs/indocker'
|
20
|
-
branch 'master'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
docker do
|
25
|
-
registry 'localhost:1000'
|
26
|
-
skip_push true
|
27
|
-
end
|
28
|
-
|
29
|
-
build_server :build_server
|
30
|
-
end
|
@@ -1,25 +0,0 @@
|
|
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
|
@@ -1 +0,0 @@
|
|
1
|
-
* { display: <%= display %>; }
|
@@ -1 +0,0 @@
|
|
1
|
-
<% if use_strict %>'use strict';<% end %>
|
data/spec/fixtures/spec.env
DELETED
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Indocker::Configs::Config do
|
4
|
-
subject { described_class.new }
|
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
|
-
|
26
|
-
describe '#option' do
|
27
|
-
it 'creates setter and getter methods with the same name' do
|
28
|
-
subject.option(:some_key, group: :default, type: :string)
|
29
|
-
subject.some_key('some_value')
|
30
|
-
|
31
|
-
expect(subject.some_key).to eq('some_value')
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'validates setter value with :type attribute' do
|
35
|
-
subject.option(:some_key, group: :default, type: :boolean)
|
36
|
-
|
37
|
-
expect{
|
38
|
-
subject.some_key('test')
|
39
|
-
}.to raise_error(Indocker::Errors::ConfigOptionTypeMismatch, 'Expected option :some_key => "test" to be a :boolean, not a :string')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#config' do
|
44
|
-
it 'creates getter and subconfiguration object for single option' do
|
45
|
-
subject.config(:example_config) do
|
46
|
-
option(:key1)
|
47
|
-
option(:key2, type: :array)
|
48
|
-
end
|
49
|
-
|
50
|
-
subject.example_config.key1('value1')
|
51
|
-
subject.example_config.key2(['value2'])
|
52
|
-
|
53
|
-
expect(subject.example_config.key1).to eq('value1')
|
54
|
-
expect(subject.example_config.key2).to match(['value2'])
|
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
|
87
|
-
end
|
88
|
-
end
|
@@ -1,67 +0,0 @@
|
|
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,278 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Indocker::ContainerManager do
|
4
|
-
before(:all) do
|
5
|
-
Indocker.define_image 'indocker_image' do
|
6
|
-
from 'alpine:latest'
|
7
|
-
cmd %w(ls)
|
8
|
-
end
|
9
|
-
|
10
|
-
ioc.image_builder.build('indocker_image')
|
11
|
-
|
12
|
-
Indocker.define_container 'indocker_container' do
|
13
|
-
use images.find_by_repo(:indocker_image)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
after(:all) { truncate_docker_items }
|
18
|
-
|
19
|
-
describe '#run' do
|
20
|
-
before(:all) { ioc.container_manager.run('indocker_container') }
|
21
|
-
after(:all) { ioc.docker_api.delete_container('indocker_container') }
|
22
|
-
|
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)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#create' do
|
39
|
-
before(:all) { ioc.container_manager.create('indocker_container') }
|
40
|
-
after(:all) { ioc.docker_api.delete_container('indocker_container') }
|
41
|
-
|
42
|
-
it 'creates container' do
|
43
|
-
expect(
|
44
|
-
ioc.docker_api.container_exists?('indocker_container')
|
45
|
-
).to be true
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
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
|
60
|
-
end
|
61
|
-
|
62
|
-
ioc.container_manager.create('indocker_timeout_container')
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'starts container if ready_block returns true' do
|
66
|
-
ioc.container_manager.start('indocker_timeout_container')
|
67
|
-
|
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)
|
73
|
-
end
|
74
|
-
end
|
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)
|
80
|
-
|
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
|
88
|
-
|
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
|
94
|
-
end
|
95
|
-
|
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)
|
100
|
-
|
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
|
110
|
-
|
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
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'with container dependencies' do
|
120
|
-
before(:all) do
|
121
|
-
Indocker.define_container 'indocker_container_depends_on' do
|
122
|
-
use images.find_by_repo(:indocker_image)
|
123
|
-
|
124
|
-
depends_on containers.get_by_name('indocker_container')
|
125
|
-
end
|
126
|
-
|
127
|
-
ioc.container_manager.create('indocker_container_depends_on')
|
128
|
-
end
|
129
|
-
|
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
|
142
|
-
|
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
|
151
|
-
|
152
|
-
ioc.container_manager.create('indocker_volume_container')
|
153
|
-
ioc.container_manager.start('indocker_volume_container')
|
154
|
-
end
|
155
|
-
|
156
|
-
after(:all) do
|
157
|
-
ioc.docker_api.delete_container('indocker_volume_container')
|
158
|
-
ioc.docker_api.delete_volume('indocker_volume')
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'creates volume before start' do
|
162
|
-
expect(
|
163
|
-
ioc.docker_api.volume_exists?('indocker_volume')
|
164
|
-
).to be true
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'with specified network' do
|
169
|
-
before(:all) do
|
170
|
-
Indocker.define_network 'indocker_network'
|
171
|
-
|
172
|
-
Indocker.define_container 'indocker_network_container' do
|
173
|
-
use images.find_by_repo(:indocker_image)
|
174
|
-
use networks.indocker_network
|
175
|
-
end
|
176
|
-
|
177
|
-
ioc.container_manager.create('indocker_network_container')
|
178
|
-
ioc.container_manager.start('indocker_network_container')
|
179
|
-
end
|
180
|
-
|
181
|
-
after(:all) do
|
182
|
-
ioc.container_manager.delete('indocker_network_container')
|
183
|
-
ioc.docker_api.delete_network('indocker_network')
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'creates network before start' do
|
187
|
-
it 'for new network' do
|
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
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'if network already exists' do
|
196
|
-
ioc.container_manager.stop('indocker_network_container')
|
197
|
-
ioc.container_manager.start('indocker_network_container')
|
198
|
-
|
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
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'connect container to specified network' do
|
208
|
-
expect(
|
209
|
-
ioc.docker_api.inspect_network('indocker_network')['Containers'].keys
|
210
|
-
).to include(
|
211
|
-
ioc.docker_api.get_container_id('indocker_network_container')
|
212
|
-
)
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'starts container' do
|
216
|
-
sleep 1 # wait when container stops
|
217
|
-
|
218
|
-
expect(
|
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)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
describe '#copy' do
|
228
|
-
let(:copy_to_path) { ioc.config.build_dir.join('indocker_list_container_files') }
|
229
|
-
|
230
|
-
before(:all) do
|
231
|
-
Indocker.define_image 'indocker_copy_image' do
|
232
|
-
from 'alpine'
|
233
|
-
|
234
|
-
run "mkdir -p /sample/deeper &&
|
235
|
-
echo 'example1.txt' > /sample/example1.txt &&
|
236
|
-
echo 'example3.txt' > /sample/deeper/example2.txt"
|
237
|
-
end
|
238
|
-
|
239
|
-
Indocker.define_container :indocker_copy_container do
|
240
|
-
use images.find_by_repo('indocker_copy_image')
|
241
|
-
end
|
242
|
-
|
243
|
-
ioc.image_builder.build('indocker_copy_image')
|
244
|
-
ioc.container_manager.create('indocker_copy_container')
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'returns files list' do
|
248
|
-
expect(
|
249
|
-
ioc.container_manager.copy(
|
250
|
-
name: :indocker_copy_container,
|
251
|
-
copy_from: '/sample/deeper',
|
252
|
-
copy_to: copy_to_path
|
253
|
-
)
|
254
|
-
).to match(['deeper/example2.txt'])
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'copies files to output path' do
|
258
|
-
ioc.container_manager.copy(
|
259
|
-
name: :indocker_copy_container,
|
260
|
-
copy_from: '/sample/.',
|
261
|
-
copy_to: copy_to_path
|
262
|
-
)
|
263
|
-
|
264
|
-
ensure_content(File.join(copy_to_path, 'example1.txt'), 'example1.txt')
|
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')
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|