indocker 0.0.6 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +10 -2
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +5 -2
  6. data/Gemfile.lock +19 -49
  7. data/LICENSE.txt +17 -18
  8. data/README.md +20 -1
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/example/indocker/bin/deploy +120 -0
  13. data/example/indocker/bin/remote/compile +72 -0
  14. data/example/indocker/bin/remote/run +66 -0
  15. data/example/indocker/bin/utils/configurations.rb +3 -0
  16. data/example/indocker/bounded_contexts/shared/ruby/Dockerfile +10 -0
  17. data/example/indocker/bounded_contexts/shared/ruby/container.rb +5 -0
  18. data/example/indocker/bounded_contexts/shared/ruby/image.rb +3 -0
  19. data/example/indocker/configurations/dev.rb +9 -0
  20. data/example/indocker/infrastructure/build_servers.rb +8 -0
  21. data/example/indocker/infrastructure/networks.rb +1 -0
  22. data/example/indocker/infrastructure/registries.rb +3 -0
  23. data/example/indocker/infrastructure/servers.rb +8 -0
  24. data/example/indocker/setup.rb +24 -0
  25. data/indocker.gemspec +27 -25
  26. data/lib/indocker.rb +437 -130
  27. data/lib/indocker/artifacts/git.rb +25 -0
  28. data/lib/indocker/build_context.rb +87 -0
  29. data/lib/indocker/build_context_helper.rb +109 -0
  30. data/lib/indocker/build_context_pool.rb +36 -0
  31. data/lib/indocker/build_server.rb +2 -0
  32. data/lib/indocker/colored_string.rb +33 -0
  33. data/lib/indocker/concerns/inspectable.rb +12 -0
  34. data/lib/indocker/configuration_deployer.rb +525 -0
  35. data/lib/indocker/configurations/configuration.rb +122 -0
  36. data/lib/indocker/configurations/configuration_builder.rb +250 -0
  37. data/lib/indocker/configurations/formatters/stdout.rb +36 -0
  38. data/lib/indocker/container_deployer.rb +73 -0
  39. data/lib/indocker/container_helper.rb +13 -0
  40. data/lib/indocker/container_runner.rb +23 -0
  41. data/lib/indocker/containers/container.rb +118 -0
  42. data/lib/indocker/containers/container_builder.rb +186 -0
  43. data/lib/indocker/containers/restart_policy.rb +36 -0
  44. data/lib/indocker/context_args.rb +43 -0
  45. data/lib/indocker/crontab_redeploy_rules_builder.rb +54 -0
  46. data/lib/indocker/deploy_context.rb +126 -0
  47. data/lib/indocker/deployment_checker.rb +121 -0
  48. data/lib/indocker/deployment_progress.rb +495 -0
  49. data/lib/indocker/docker.rb +87 -0
  50. data/lib/indocker/docker_run_args.rb +183 -0
  51. data/lib/indocker/env_file_helper.rb +13 -0
  52. data/lib/indocker/env_files/local.rb +8 -0
  53. data/lib/indocker/env_files/remote.rb +8 -0
  54. data/lib/indocker/hash_merger.rb +9 -0
  55. data/lib/indocker/images/image.rb +86 -0
  56. data/lib/indocker/images/image_builder.rb +98 -0
  57. data/lib/indocker/images/image_compiler.rb +68 -0
  58. data/lib/indocker/images/template_compiler.rb +15 -0
  59. data/lib/indocker/images/templates_compiler.rb +28 -0
  60. data/lib/indocker/images_compiler.rb +38 -0
  61. data/lib/indocker/indocker_helper.rb +9 -0
  62. data/lib/indocker/network.rb +12 -0
  63. data/lib/indocker/network_helper.rb +7 -0
  64. data/lib/indocker/registries/abstract.rb +17 -0
  65. data/lib/indocker/registries/local.rb +5 -0
  66. data/lib/indocker/registries/remote.rb +12 -0
  67. data/lib/indocker/repositories/abstract.rb +25 -0
  68. data/lib/indocker/repositories/clonner.rb +17 -0
  69. data/lib/indocker/repositories/git.rb +24 -0
  70. data/lib/indocker/repositories/local.rb +20 -0
  71. data/lib/indocker/repositories/no_sync.rb +20 -0
  72. data/lib/indocker/rsync.rb +52 -0
  73. data/lib/indocker/server.rb +20 -0
  74. data/lib/indocker/server_pool.rb +30 -0
  75. data/lib/indocker/shell.rb +60 -0
  76. data/lib/indocker/ssh_result_logger.rb +18 -0
  77. data/lib/indocker/ssh_session.rb +92 -0
  78. data/lib/indocker/version.rb +1 -1
  79. data/lib/indocker/volume_helper.rb +7 -0
  80. data/lib/indocker/volumes/external.rb +8 -0
  81. data/lib/indocker/volumes/local.rb +9 -0
  82. data/lib/indocker/volumes/repository.rb +9 -0
  83. metadata +107 -222
  84. data/bin/indocker +0 -9
  85. data/lib/indocker/application_initializer.rb +0 -19
  86. data/lib/indocker/cli.rb +0 -27
  87. data/lib/indocker/configs/config.rb +0 -147
  88. data/lib/indocker/configs/config_factory.rb +0 -37
  89. data/lib/indocker/configs/config_initializer.rb +0 -9
  90. data/lib/indocker/configs/locator.rb +0 -23
  91. data/lib/indocker/container/container_builder.rb +0 -29
  92. data/lib/indocker/container/container_directives_runner.rb +0 -54
  93. data/lib/indocker/container/container_dsl.rb +0 -83
  94. data/lib/indocker/container/container_evaluator.rb +0 -13
  95. data/lib/indocker/container/container_inspector.rb +0 -26
  96. data/lib/indocker/container/container_manager.rb +0 -122
  97. data/lib/indocker/container/container_metadata.rb +0 -112
  98. data/lib/indocker/container/container_metadata_factory.rb +0 -30
  99. data/lib/indocker/container/container_metadata_repository.rb +0 -27
  100. data/lib/indocker/directives/base.rb +0 -17
  101. data/lib/indocker/directives/container_directives/base.rb +0 -23
  102. data/lib/indocker/directives/container_directives/cmd.rb +0 -7
  103. data/lib/indocker/directives/container_directives/depends_on.rb +0 -7
  104. data/lib/indocker/directives/container_directives/env.rb +0 -7
  105. data/lib/indocker/directives/container_directives/env_file.rb +0 -7
  106. data/lib/indocker/directives/container_directives/expose.rb +0 -7
  107. data/lib/indocker/directives/container_directives/from.rb +0 -14
  108. data/lib/indocker/directives/container_directives/network.rb +0 -12
  109. data/lib/indocker/directives/container_directives/ports.rb +0 -15
  110. data/lib/indocker/directives/container_directives/ready.rb +0 -16
  111. data/lib/indocker/directives/container_directives/volume.rb +0 -23
  112. data/lib/indocker/directives/image_directives/base.rb +0 -27
  113. data/lib/indocker/directives/image_directives/cmd.rb +0 -19
  114. data/lib/indocker/directives/image_directives/copy.rb +0 -32
  115. data/lib/indocker/directives/image_directives/docker_cp.rb +0 -20
  116. data/lib/indocker/directives/image_directives/entrypoint.rb +0 -19
  117. data/lib/indocker/directives/image_directives/env.rb +0 -9
  118. data/lib/indocker/directives/image_directives/env_file.rb +0 -19
  119. data/lib/indocker/directives/image_directives/expose.rb +0 -9
  120. data/lib/indocker/directives/image_directives/from.rb +0 -36
  121. data/lib/indocker/directives/image_directives/registry.rb +0 -30
  122. data/lib/indocker/directives/image_directives/run.rb +0 -17
  123. data/lib/indocker/directives/image_directives/workdir.rb +0 -9
  124. data/lib/indocker/directives/partial.rb +0 -21
  125. data/lib/indocker/docker_api/container_config.rb +0 -121
  126. data/lib/indocker/docker_api/docker_api.rb +0 -207
  127. data/lib/indocker/dsl_context.rb +0 -21
  128. data/lib/indocker/envs/env_metadata.rb +0 -39
  129. data/lib/indocker/envs/loader.rb +0 -19
  130. data/lib/indocker/errors.rb +0 -21
  131. data/lib/indocker/git/git_api.rb +0 -32
  132. data/lib/indocker/git/git_helper.rb +0 -34
  133. data/lib/indocker/git/git_service.rb +0 -21
  134. data/lib/indocker/handlers/container_run.rb +0 -20
  135. data/lib/indocker/handlers/container_stop.rb +0 -17
  136. data/lib/indocker/handlers/performable.rb +0 -22
  137. data/lib/indocker/image/image_builder.rb +0 -54
  138. data/lib/indocker/image/image_dependencies_manager.rb +0 -47
  139. data/lib/indocker/image/image_directives_runner.rb +0 -99
  140. data/lib/indocker/image/image_dockerfile_builder.rb +0 -24
  141. data/lib/indocker/image/image_dsl.rb +0 -89
  142. data/lib/indocker/image/image_evaluator.rb +0 -21
  143. data/lib/indocker/image/image_helper.rb +0 -9
  144. data/lib/indocker/image/image_metadata.rb +0 -50
  145. data/lib/indocker/image/image_metadata_factory.rb +0 -31
  146. data/lib/indocker/image/image_metadata_repository.rb +0 -29
  147. data/lib/indocker/networks/network_metadata.rb +0 -9
  148. data/lib/indocker/networks/network_metadata_factory.rb +0 -9
  149. data/lib/indocker/networks/network_metadata_repository.rb +0 -34
  150. data/lib/indocker/partial/partial_metadata.rb +0 -8
  151. data/lib/indocker/partial/partial_metadata_repository.rb +0 -26
  152. data/lib/indocker/registry/registry_api.rb +0 -46
  153. data/lib/indocker/registry/registry_helper.rb +0 -20
  154. data/lib/indocker/registry/registry_service.rb +0 -28
  155. data/lib/indocker/utils/ioc_container.rb +0 -17
  156. data/lib/indocker/utils/logger.rb +0 -62
  157. data/lib/indocker/utils/logger_factory.rb +0 -13
  158. data/lib/indocker/utils/registry_authenticator.rb +0 -19
  159. data/lib/indocker/utils/render_namespace.rb +0 -11
  160. data/lib/indocker/utils/render_util.rb +0 -15
  161. data/lib/indocker/utils/string_utils.rb +0 -11
  162. data/lib/indocker/utils/tar_helper.rb +0 -40
  163. data/lib/indocker/utils/test_logger_factory.rb +0 -9
  164. data/lib/indocker/volumes/volume_metadata.rb +0 -9
  165. data/lib/indocker/volumes/volume_metadata_factory.rb +0 -9
  166. data/lib/indocker/volumes/volume_metadata_repository.rb +0 -34
  167. data/spec/example/.indocker/config.rb +0 -30
  168. data/spec/example/.indocker/images_and_containers.rb +0 -25
  169. data/spec/example/assets/index.css +0 -1
  170. data/spec/example/assets/index.js +0 -1
  171. data/spec/fixtures/spec.env +0 -2
  172. data/spec/indocker/configs/config_factory_spec.rb +0 -18
  173. data/spec/indocker/configs/config_spec.rb +0 -88
  174. data/spec/indocker/container/container_builder_spec.rb +0 -67
  175. data/spec/indocker/container/container_manager_spec.rb +0 -278
  176. data/spec/indocker/docker_api/container_config_spec.rb +0 -64
  177. data/spec/indocker/docker_api/docker_api_spec.rb +0 -112
  178. data/spec/indocker/handlers/container_run_spec.rb +0 -60
  179. data/spec/indocker/image/image_builder_spec.rb +0 -153
  180. data/spec/indocker/image/image_directives_runner_spec.rb +0 -141
  181. data/spec/indocker/image/image_dockerfile_builder_spec.rb +0 -25
  182. data/spec/indocker/image/image_evaluator_spec.rb +0 -85
  183. data/spec/spec_helper.rb +0 -68
@@ -1,64 +0,0 @@
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
@@ -1,112 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Indocker::DockerAPI do
4
- let(:docker_api) { ioc.docker_api }
5
-
6
- describe '#create_network' do
7
- context 'simple network' do
8
- let!(:id) { docker_api.create_network('indocker') }
9
-
10
- after { docker_api.delete_network(id) }
11
-
12
- it 'creates network' do
13
- expect(
14
- docker_api.get_network_id('indocker')
15
- ).to eq(id)
16
- end
17
- end
18
- end
19
-
20
- describe '#add_container_to_network' do
21
- let(:container_id) {
22
- docker_api.create_container(
23
- Indocker::DockerAPI::ContainerConfig.new(
24
- image: 'alpine:latest',
25
- name: 'sample_container'
26
- )
27
- )
28
- }
29
-
30
- let(:network_id) { docker_api.create_network('indocker') }
31
-
32
- after do
33
- docker_api.stop_container(container_id)
34
- docker_api.delete_container(container_id)
35
- docker_api.delete_network(network_id)
36
- end
37
-
38
- it 'do something' do
39
- docker_api.add_container_to_network(
40
- network_name: network_id,
41
- container_name: container_id
42
- )
43
-
44
- docker_api.start_container(container_id)
45
-
46
- expect(
47
- docker_api.inspect_network(network_id)['Containers'].keys
48
- ).to include(container_id)
49
- end
50
- end
51
-
52
- describe '#get_image_id' do
53
- context 'if image presents' do
54
- it 'returns instance of Docker::Image class' do
55
- expect(docker_api.get_image_id('alpine')).to be_a(String)
56
- end
57
- end
58
-
59
- context 'if image does not present' do
60
- it 'returns nil ' do
61
- expect(docker_api.get_image_id('some-invalid-image')).to eq(nil)
62
- end
63
- end
64
- end
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
-
95
- describe '#get_container_id' do
96
- context 'if container presents' do
97
- let!(:container) { Docker::Container.create('Image' => 'alpine:latest', 'name': 'alpine') }
98
- after { container.delete(force: true) }
99
-
100
- it 'returns container_id string' do
101
- expect(docker_api.get_container_id('alpine')).to be_a(String)
102
- expect(docker_api.get_container_id('alpine').size).to eq(64)
103
- end
104
- end
105
-
106
- context 'if container does not present' do
107
- it 'returns nil' do
108
- expect(docker_api.get_container_id('invalid-container-name')).to eq(nil)
109
- end
110
- end
111
- end
112
- end
@@ -1,60 +0,0 @@
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,153 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Indocker::ImageBuilder' do
4
- context 'for image without dependencies' do
5
- before(:all) do
6
- Indocker.define_image('indocker_image') do
7
- from 'hello-world'
8
- workdir '/'
9
- end
10
-
11
- ioc.image_builder.build('indocker_image')
12
- end
13
-
14
- after(:all) { truncate_docker_items }
15
-
16
- it 'builds image without dependencies' do
17
- expect(
18
- ioc.docker_api.image_exists?('indocker_image')
19
- ).to be true
20
- end
21
-
22
- it 'deletes build_path after image building' do
23
- image_metadata = ioc.image_metadata_repository.find_by_repo('indocker_image')
24
-
25
- expect(
26
- File.exists?(image_metadata.build_dir)
27
- ).to be false
28
- end
29
- end
30
-
31
- context 'for image with dependencies' do
32
- context 'circular docker_cp dependency' do
33
- before do
34
- Indocker.define_image('indocker_image') do
35
- before_build do
36
- docker_cp 'indocker_container'
37
- end
38
-
39
- from 'hello-world'
40
- workdir '/'
41
- end
42
-
43
- Indocker.define_container 'indocker_container' do
44
- use images.find_by_repo(:indocker_image)
45
- end
46
- end
47
-
48
- after(:all) { truncate_docker_items }
49
-
50
- it 'raises Indocker::Errors::CircularImageDependency' do
51
- expect{
52
- ioc.image_builder.build('indocker_image')
53
- }.to raise_error(Indocker::Errors::CircularImageDependency)
54
- end
55
- end
56
-
57
- context 'for non circular docker_cp dependency' do
58
- before do
59
- Indocker.define_image('indocker_dependency_image') do
60
- from 'alpine:latest'
61
- workdir '/'
62
- run 'echo "Hello World" > test.txt'
63
- end
64
-
65
- Indocker.define_image('indocker_image') do
66
- before_build do
67
- docker_cp 'indocker_container' do
68
- copy 'test.txt' => '/copy'
69
- end
70
- end
71
-
72
- from :indocker_dependency_image, tag: :latest
73
- workdir '/'
74
- copy '/copy/test.txt' => '/'
75
- end
76
-
77
- Indocker.define_container 'indocker_container' do
78
- use images.find_by_repo(:indocker_dependency_image)
79
- end
80
-
81
- ioc.image_builder.build('indocker_image')
82
- end
83
-
84
- after(:all) { truncate_docker_items }
85
-
86
- it 'builds image with dependency' do
87
- expect(
88
- ioc.docker_api.image_exists?('indocker_image')
89
- ).to be true
90
- end
91
- end
92
- end
93
-
94
- context 'for not existing image' do
95
- it 'raises Indocker::Errors::ImageIsNotDefined' do
96
- expect{
97
- ioc.image_builder.build('indocker_image')
98
- }.to raise_error(Indocker::Errors::ImageIsNotDefined)
99
- end
100
- end
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
-
136
- context 'with coping files from project_root' do
137
- before do
138
- Indocker.define_image('indocker_image') do
139
- from 'alpine:latest'
140
-
141
- copy File.join(__dir__, '../../example/assets/.') => 'assets'
142
- end
143
- end
144
-
145
- after(:all) { truncate_docker_items }
146
-
147
- it 'does not raise error' do
148
- expect{
149
- ioc.image_builder.build('indocker_image')
150
- }.to_not raise_error
151
- end
152
- end
153
- end
@@ -1,141 +0,0 @@
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