indocker 0.0.6 → 0.1.0

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.
Files changed (170) 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 +17 -49
  7. data/LICENSE.txt +17 -18
  8. data/README.md +33 -1
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/indocker.gemspec +26 -25
  13. data/lib/indocker.rb +429 -130
  14. data/lib/indocker/artifacts/git.rb +25 -0
  15. data/lib/indocker/build_context.rb +87 -0
  16. data/lib/indocker/build_context_helper.rb +109 -0
  17. data/lib/indocker/build_context_pool.rb +36 -0
  18. data/lib/indocker/build_server.rb +2 -0
  19. data/lib/indocker/colored_string.rb +33 -0
  20. data/lib/indocker/concerns/inspectable.rb +12 -0
  21. data/lib/indocker/configuration_deployer.rb +525 -0
  22. data/lib/indocker/configurations/configuration.rb +122 -0
  23. data/lib/indocker/configurations/configuration_builder.rb +250 -0
  24. data/lib/indocker/configurations/formatters/stdout.rb +36 -0
  25. data/lib/indocker/container_deployer.rb +73 -0
  26. data/lib/indocker/container_helper.rb +13 -0
  27. data/lib/indocker/container_runner.rb +23 -0
  28. data/lib/indocker/containers/container.rb +118 -0
  29. data/lib/indocker/containers/container_builder.rb +186 -0
  30. data/lib/indocker/containers/restart_policy.rb +36 -0
  31. data/lib/indocker/context_args.rb +44 -0
  32. data/lib/indocker/crontab_redeploy_rules_builder.rb +54 -0
  33. data/lib/indocker/deploy_context.rb +126 -0
  34. data/lib/indocker/deployment_checker.rb +121 -0
  35. data/lib/indocker/deployment_progress.rb +495 -0
  36. data/lib/indocker/docker.rb +87 -0
  37. data/lib/indocker/docker_run_args.rb +175 -0
  38. data/lib/indocker/env_file_helper.rb +13 -0
  39. data/lib/indocker/env_files/local.rb +8 -0
  40. data/lib/indocker/env_files/remote.rb +8 -0
  41. data/lib/indocker/hash_merger.rb +9 -0
  42. data/lib/indocker/images/image.rb +86 -0
  43. data/lib/indocker/images/image_builder.rb +98 -0
  44. data/lib/indocker/images/image_compiler.rb +68 -0
  45. data/lib/indocker/images/template_compiler.rb +15 -0
  46. data/lib/indocker/images/templates_compiler.rb +28 -0
  47. data/lib/indocker/images_compiler.rb +38 -0
  48. data/lib/indocker/indocker_helper.rb +9 -0
  49. data/lib/indocker/network.rb +12 -0
  50. data/lib/indocker/network_helper.rb +7 -0
  51. data/lib/indocker/registries/abstract.rb +17 -0
  52. data/lib/indocker/registries/local.rb +5 -0
  53. data/lib/indocker/registries/remote.rb +12 -0
  54. data/lib/indocker/repositories/abstract.rb +25 -0
  55. data/lib/indocker/repositories/clonner.rb +15 -0
  56. data/lib/indocker/repositories/git.rb +21 -0
  57. data/lib/indocker/repositories/local.rb +20 -0
  58. data/lib/indocker/repositories/no_sync.rb +20 -0
  59. data/lib/indocker/rsync.rb +52 -0
  60. data/lib/indocker/server.rb +20 -0
  61. data/lib/indocker/server_pool.rb +30 -0
  62. data/lib/indocker/shell.rb +60 -0
  63. data/lib/indocker/ssh_result_logger.rb +18 -0
  64. data/lib/indocker/ssh_session.rb +92 -0
  65. data/lib/indocker/version.rb +1 -1
  66. data/lib/indocker/volume_helper.rb +7 -0
  67. data/lib/indocker/volumes/external.rb +8 -0
  68. data/lib/indocker/volumes/local.rb +9 -0
  69. data/lib/indocker/volumes/repository.rb +9 -0
  70. metadata +88 -230
  71. data/bin/indocker +0 -9
  72. data/lib/indocker/application_initializer.rb +0 -19
  73. data/lib/indocker/cli.rb +0 -27
  74. data/lib/indocker/configs/config.rb +0 -147
  75. data/lib/indocker/configs/config_factory.rb +0 -37
  76. data/lib/indocker/configs/config_initializer.rb +0 -9
  77. data/lib/indocker/configs/locator.rb +0 -23
  78. data/lib/indocker/container/container_builder.rb +0 -29
  79. data/lib/indocker/container/container_directives_runner.rb +0 -54
  80. data/lib/indocker/container/container_dsl.rb +0 -83
  81. data/lib/indocker/container/container_evaluator.rb +0 -13
  82. data/lib/indocker/container/container_inspector.rb +0 -26
  83. data/lib/indocker/container/container_manager.rb +0 -122
  84. data/lib/indocker/container/container_metadata.rb +0 -112
  85. data/lib/indocker/container/container_metadata_factory.rb +0 -30
  86. data/lib/indocker/container/container_metadata_repository.rb +0 -27
  87. data/lib/indocker/directives/base.rb +0 -17
  88. data/lib/indocker/directives/container_directives/base.rb +0 -23
  89. data/lib/indocker/directives/container_directives/cmd.rb +0 -7
  90. data/lib/indocker/directives/container_directives/depends_on.rb +0 -7
  91. data/lib/indocker/directives/container_directives/env.rb +0 -7
  92. data/lib/indocker/directives/container_directives/env_file.rb +0 -7
  93. data/lib/indocker/directives/container_directives/expose.rb +0 -7
  94. data/lib/indocker/directives/container_directives/from.rb +0 -14
  95. data/lib/indocker/directives/container_directives/network.rb +0 -12
  96. data/lib/indocker/directives/container_directives/ports.rb +0 -15
  97. data/lib/indocker/directives/container_directives/ready.rb +0 -16
  98. data/lib/indocker/directives/container_directives/volume.rb +0 -23
  99. data/lib/indocker/directives/image_directives/base.rb +0 -27
  100. data/lib/indocker/directives/image_directives/cmd.rb +0 -19
  101. data/lib/indocker/directives/image_directives/copy.rb +0 -32
  102. data/lib/indocker/directives/image_directives/docker_cp.rb +0 -20
  103. data/lib/indocker/directives/image_directives/entrypoint.rb +0 -19
  104. data/lib/indocker/directives/image_directives/env.rb +0 -9
  105. data/lib/indocker/directives/image_directives/env_file.rb +0 -19
  106. data/lib/indocker/directives/image_directives/expose.rb +0 -9
  107. data/lib/indocker/directives/image_directives/from.rb +0 -36
  108. data/lib/indocker/directives/image_directives/registry.rb +0 -30
  109. data/lib/indocker/directives/image_directives/run.rb +0 -17
  110. data/lib/indocker/directives/image_directives/workdir.rb +0 -9
  111. data/lib/indocker/directives/partial.rb +0 -21
  112. data/lib/indocker/docker_api/container_config.rb +0 -121
  113. data/lib/indocker/docker_api/docker_api.rb +0 -207
  114. data/lib/indocker/dsl_context.rb +0 -21
  115. data/lib/indocker/envs/env_metadata.rb +0 -39
  116. data/lib/indocker/envs/loader.rb +0 -19
  117. data/lib/indocker/errors.rb +0 -21
  118. data/lib/indocker/git/git_api.rb +0 -32
  119. data/lib/indocker/git/git_helper.rb +0 -34
  120. data/lib/indocker/git/git_service.rb +0 -21
  121. data/lib/indocker/handlers/container_run.rb +0 -20
  122. data/lib/indocker/handlers/container_stop.rb +0 -17
  123. data/lib/indocker/handlers/performable.rb +0 -22
  124. data/lib/indocker/image/image_builder.rb +0 -54
  125. data/lib/indocker/image/image_dependencies_manager.rb +0 -47
  126. data/lib/indocker/image/image_directives_runner.rb +0 -99
  127. data/lib/indocker/image/image_dockerfile_builder.rb +0 -24
  128. data/lib/indocker/image/image_dsl.rb +0 -89
  129. data/lib/indocker/image/image_evaluator.rb +0 -21
  130. data/lib/indocker/image/image_helper.rb +0 -9
  131. data/lib/indocker/image/image_metadata.rb +0 -50
  132. data/lib/indocker/image/image_metadata_factory.rb +0 -31
  133. data/lib/indocker/image/image_metadata_repository.rb +0 -29
  134. data/lib/indocker/networks/network_metadata.rb +0 -9
  135. data/lib/indocker/networks/network_metadata_factory.rb +0 -9
  136. data/lib/indocker/networks/network_metadata_repository.rb +0 -34
  137. data/lib/indocker/partial/partial_metadata.rb +0 -8
  138. data/lib/indocker/partial/partial_metadata_repository.rb +0 -26
  139. data/lib/indocker/registry/registry_api.rb +0 -46
  140. data/lib/indocker/registry/registry_helper.rb +0 -20
  141. data/lib/indocker/registry/registry_service.rb +0 -28
  142. data/lib/indocker/utils/ioc_container.rb +0 -17
  143. data/lib/indocker/utils/logger.rb +0 -62
  144. data/lib/indocker/utils/logger_factory.rb +0 -13
  145. data/lib/indocker/utils/registry_authenticator.rb +0 -19
  146. data/lib/indocker/utils/render_namespace.rb +0 -11
  147. data/lib/indocker/utils/render_util.rb +0 -15
  148. data/lib/indocker/utils/string_utils.rb +0 -11
  149. data/lib/indocker/utils/tar_helper.rb +0 -40
  150. data/lib/indocker/utils/test_logger_factory.rb +0 -9
  151. data/lib/indocker/volumes/volume_metadata.rb +0 -9
  152. data/lib/indocker/volumes/volume_metadata_factory.rb +0 -9
  153. data/lib/indocker/volumes/volume_metadata_repository.rb +0 -34
  154. data/spec/example/.indocker/config.rb +0 -30
  155. data/spec/example/.indocker/images_and_containers.rb +0 -25
  156. data/spec/example/assets/index.css +0 -1
  157. data/spec/example/assets/index.js +0 -1
  158. data/spec/fixtures/spec.env +0 -2
  159. data/spec/indocker/configs/config_factory_spec.rb +0 -18
  160. data/spec/indocker/configs/config_spec.rb +0 -88
  161. data/spec/indocker/container/container_builder_spec.rb +0 -67
  162. data/spec/indocker/container/container_manager_spec.rb +0 -278
  163. data/spec/indocker/docker_api/container_config_spec.rb +0 -64
  164. data/spec/indocker/docker_api/docker_api_spec.rb +0 -112
  165. data/spec/indocker/handlers/container_run_spec.rb +0 -60
  166. data/spec/indocker/image/image_builder_spec.rb +0 -153
  167. data/spec/indocker/image/image_directives_runner_spec.rb +0 -141
  168. data/spec/indocker/image/image_dockerfile_builder_spec.rb +0 -25
  169. data/spec/indocker/image/image_evaluator_spec.rb +0 -85
  170. data/spec/spec_helper.rb +0 -68
data/bin/indocker DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- encoding: utf-8 -*-
3
-
4
- require 'rubygems'
5
- require 'bundler/setup'
6
- require 'indocker'
7
-
8
- # $thor_runner = true
9
- Indocker::CLI::Application.start( ARGV )
@@ -1,19 +0,0 @@
1
- class Indocker::ApplicationInitializer
2
- include SmartIoC::Iocify
3
-
4
- bean :application_initializer
5
-
6
- inject :config_locator
7
- inject :docker_api
8
- inject :registry_authenticator
9
- inject :config
10
-
11
-
12
- def init_app(current_path, env: :development)
13
- docker_api.check_docker_installed!
14
-
15
- require(config_locator.locate(current_path))
16
-
17
- # registry_authenticator.authenticate!()
18
- end
19
- end
data/lib/indocker/cli.rb DELETED
@@ -1,27 +0,0 @@
1
- require 'thor'
2
-
3
- module Indocker
4
- module CLI
5
- class Application < Thor
6
- desc "container:run CONTAINER_NAME", "runs specified container"
7
- option :env
8
- define_method('container:run') do |name, env = :development|
9
- ioc.run_container_handler.perform(
10
- name: name,
11
- current_path: Dir.pwd,
12
- env: env
13
- )
14
- end
15
-
16
- desc "container:stop CONTAINER_NAME", "stops specified container"
17
- option :env
18
- define_method('container:stop') do |name, env = :development|
19
- ioc.stop_container_handler.perform(
20
- name: name,
21
- current_path: Dir.pwd,
22
- env: env
23
- )
24
- end
25
- end
26
- end
27
- end
@@ -1,147 +0,0 @@
1
- module Indocker::Configs
2
- class Config
3
- attr_reader :scope
4
-
5
- def scope
6
- @scope ||= Hash.new()
7
- end
8
-
9
- def options
10
- scope.reject {|_, opt| opt.is_a?(Indocker::Configs::Config)}.keys
11
- end
12
-
13
- def configs
14
- scope.select {|_, opt| opt.is_a?(Indocker::Configs::Config)}.keys
15
- end
16
-
17
- def set(&block)
18
- instance_exec(&block)
19
-
20
- self
21
- end
22
-
23
- def option(name, group: nil, type: nil, required: nil)
24
- raise Indocker::Errors::ReservedKeywordUsed, name if respond_to?(name.to_sym)
25
-
26
- define_singleton_method(name) do |value = nil, &block|
27
- if type == :config and options.include?(name) and block
28
- return read_setting(name).set(&block)
29
- end
30
-
31
- if block || value
32
- write_setting(
33
- name: name,
34
- value: block || value,
35
- group: group,
36
- type: type,
37
- required: required
38
- )
39
- else
40
- read_setting(name)
41
- end
42
- end
43
- end
44
-
45
- def config(name, group: :default, &block)
46
- raise Indocker::Errors::ReservedKeywordUsed, name if respond_to?(name.to_sym)
47
-
48
- subconfiguration = Indocker::Configs::Config.new
49
- subconfiguration.instance_exec(&block)
50
-
51
- option(name, group: group, type: :config)
52
- send(name, subconfiguration)
53
-
54
- subconfiguration
55
- end
56
-
57
- def hash_config(hash_config_name, group: :default, &hash_config_block)
58
- raise Indocker::Errors::ReservedKeywordUsed, hash_config_name if respond_to?(hash_config_name.to_sym)
59
-
60
- define_singleton_method(hash_config_name) do |name, &self_block|
61
- config = config(name, &hash_config_block)
62
- config.set(&self_block)
63
-
64
- config
65
- end
66
- end
67
-
68
- private
69
-
70
- def read_setting(name)
71
- read_value = scope.has_key?(name.intern) ? scope[name.intern].value : nil
72
-
73
- read_value.is_a?(Proc) ? read_value.call : read_value
74
- end
75
-
76
- def write_setting(name:, value:, group:, type:, required:)
77
- new_option = Option.new(
78
- name: name,
79
- value: value,
80
- group: group,
81
- required: required,
82
- type: type
83
- )
84
-
85
- new_option.validate!
86
-
87
- scope[name.intern] = new_option
88
- end
89
-
90
-
91
- def method_missing(method, *args, &block)
92
- raise "Undefined keyword #{method.inspect} for Indocker configuration file"
93
- end
94
- end
95
-
96
- class Option
97
- attr_reader :value, :required, :type, :group
98
-
99
- def initialize(name:, value:, required: nil, type: nil, group: nil)
100
- @name = name
101
- @value = value
102
- @required = required || false
103
- @type = type || :string
104
- @group = group || :default
105
- end
106
-
107
- def validate!
108
- check_required
109
- check_type
110
- end
111
-
112
- private
113
-
114
- def check_required
115
- if @required && @value.nil?
116
- raise Indocker::Errors::ConfigInitializationError,
117
- "Configuration option :#{option} is required"
118
- end
119
- end
120
-
121
- def check_type
122
- value_type = cast_class_to_type(@value)
123
-
124
- if @type != value_type
125
- raise Indocker::Errors::ConfigOptionTypeMismatch,
126
- "Expected option #{@name.inspect} => #{@value.inspect} to be a #{@type.inspect}, not a #{value_type.inspect}"
127
- end
128
-
129
- nil
130
- end
131
-
132
- def cast_class_to_type(value)
133
- case value
134
- when Proc
135
- cast_class_to_type(value.call)
136
- when TrueClass
137
- :boolean
138
- when FalseClass
139
- :boolean
140
- when Indocker::Configs::Config
141
- :config
142
- else
143
- Indocker::StringUtils.underscore(value.class.name).to_sym
144
- end
145
- end
146
- end
147
- end
@@ -1,37 +0,0 @@
1
- class Indocker::Configs::ConfigFactory
2
- include SmartIoC::Iocify
3
-
4
- bean :config, factory_method: :build
5
-
6
- CONFIG_STRUCTURE = Proc.new do
7
- option :namespace, group: :common, type: :symbol
8
- option :build_dir, group: :common, type: :pathname
9
-
10
- option :load_env_file, group: :load, type: :array
11
- option :load_docker_items, group: :load, type: :array
12
-
13
- config :git, group: :git do
14
- option :cache_dir, group: :common, type: :pathname
15
-
16
- hash_config :repo do
17
- option :repository
18
- option :tag
19
- option :branch
20
- end
21
- end
22
-
23
- config :docker, group: :docker do
24
- hash_config :registry do
25
- option :serveraddress, required: true
26
- option :email
27
- option :password
28
- option :username
29
- option :skip_push, type: :boolean
30
- end
31
- end
32
- end
33
-
34
- def build(&block)
35
- @configuration ||= Indocker::Configs::Config.new.set(&CONFIG_STRUCTURE)
36
- end
37
- end
@@ -1,9 +0,0 @@
1
- class Indocker::Configs::ConfigInitializer
2
- include SmartIoC::Iocify
3
-
4
- bean :config_initializer
5
-
6
- def initialize
7
-
8
- end
9
- end
@@ -1,23 +0,0 @@
1
- class Indocker::Configs::Locator
2
- include SmartIoC::Iocify
3
-
4
- bean :config_locator
5
-
6
- ROOT = '/'
7
-
8
- def locate(path)
9
- expand_path = potential_config_file File.expand_path(path)
10
-
11
- return expand_path if File.exists?(expand_path)
12
-
13
- raise Indocker::Errors::ConfigFilesDoesNotFound if path == ROOT
14
-
15
- locate(File.dirname(path))
16
- end
17
-
18
- private
19
-
20
- def potential_config_file(path)
21
- File.join(path, '.indocker', 'config.rb')
22
- end
23
- end
@@ -1,29 +0,0 @@
1
- class Indocker::ContainerBuilder
2
- include SmartIoC::Iocify
3
-
4
- bean :container_builder
5
-
6
- inject :container_metadata_repository
7
- inject :envs_loader
8
- inject :config
9
-
10
- def build(name)
11
- container_metadata = container_metadata_repository.get_by_name(name)
12
-
13
- env_metadata = container_metadata.env_files.inject(Indocker::Envs::EnvMetadata.new) do |all, path|
14
- all += envs_loader.parse(path)
15
- end
16
-
17
- Indocker::DockerAPI::ContainerConfig.new(
18
- name: name,
19
- repo: container_metadata.repo,
20
- tag: container_metadata.tag,
21
- exposed_ports: container_metadata.exposed_ports,
22
- port_bindings: container_metadata.port_bindings,
23
- cmd: container_metadata.command,
24
- volumes: container_metadata.volumes,
25
- binds: container_metadata.binds,
26
- env: env_metadata.to_array + container_metadata.envs
27
- )
28
- end
29
- end
@@ -1,54 +0,0 @@
1
- require 'timeout'
2
-
3
- class Indocker::ContainerDirectivesRunner
4
- include SmartIoC::Iocify
5
-
6
- bean :container_directives_runner
7
-
8
- inject :docker_api
9
- inject :config
10
-
11
- def run_all(directives)
12
- directives.each {|c| run(c)}
13
- end
14
-
15
- def run(directive)
16
- case directive
17
- when Indocker::ContainerDirectives::Network
18
- run_network(directive)
19
- when Indocker::ContainerDirectives::Ready
20
- run_ready(directive)
21
- when Indocker::ContainerDirectives::Volume
22
- run_volume(directive)
23
- else
24
- # do nothing
25
- end
26
- end
27
-
28
- def run_network(directive)
29
- if !docker_api.network_exists?(directive.network_name)
30
- docker_api.create_network(directive.network_name)
31
- end
32
-
33
- docker_api.add_container_to_network(
34
- container_name: directive.container_name,
35
- network_name: directive.network_name
36
- )
37
- end
38
-
39
- def run_ready(directive)
40
- Timeout::timeout(directive.timeout) do
41
- while (!directive.ready_block.call)
42
- sleep directive.sleep
43
- end
44
- end
45
- rescue Timeout::Error
46
- raise Indocker::Errors::ContainerTimeoutError
47
- end
48
-
49
- def run_volume(directive)
50
- if !docker_api.volume_exists?(directive.name)
51
- docker_api.create_volume(directive.name)
52
- end
53
- end
54
- end
@@ -1,83 +0,0 @@
1
- class Indocker::ContainerDSL
2
- attr_reader :directives
3
-
4
- def initialize(context)
5
- @context = context
6
- @directives = []
7
- end
8
-
9
- def method_missing(method, *args)
10
- @context.send(method)
11
- rescue
12
- super
13
- end
14
-
15
- private
16
-
17
- def use(item)
18
- case item
19
- when Indocker::ImageMetadata
20
- from_directive = @directives.detect {|d| d.instance_of?(Indocker::ContainerDirectives::From)}
21
- raise Indocker::Errors::ContainerImageAlreadyDefined, from_directive.image if from_directive
22
-
23
- @directives << Indocker::ContainerDirectives::From.new(item.repo, tag: item.tag)
24
- when Indocker::Networks::NetworkMetadata
25
- @directives << Indocker::ContainerDirectives::Network.new(
26
- container_name: @context.container_name,
27
- network_name: item.name
28
- )
29
- when Indocker::Volumes::VolumeMetadata
30
- @directives << Indocker::ContainerDirectives::Volume.new(
31
- volume_name: item.name
32
- )
33
- end
34
- end
35
-
36
- # TODO: Add contract
37
- def mount(volume, to:)
38
- @directives << Indocker::ContainerDirectives::Volume.new(
39
- name: volume.name,
40
- to: to
41
- )
42
- end
43
-
44
- def cmd(command)
45
- first_cmd_directive = @directives.detect {|c| c.instance_of?(Indocker::ContainerDirectives::Cmd)}
46
- raise Indocker::Errors::DirectiveAlreadyInUse, first_cmd_directive if first_cmd_directive
47
-
48
- @directives << Indocker::ContainerDirectives::Cmd.new(command)
49
- end
50
-
51
- def env_file(path)
52
- @directives << Indocker::ContainerDirectives::EnvFile.new(path)
53
- end
54
-
55
- def env(env_string)
56
- @directives << Indocker::ContainerDirectives::Env.new(env_string)
57
- end
58
-
59
- def expose(port)
60
- @directives << Indocker::ContainerDirectives::Expose.new(path)
61
- end
62
-
63
- def ports(ports)
64
- container_port, host_port = ports.split(':').map(&:strip)
65
-
66
- @directives << Indocker::ContainerDirectives::Ports.new(
67
- container_port: container_port,
68
- host_port: host_port
69
- )
70
- end
71
-
72
- def depends_on(container_metadata)
73
- @directives << Indocker::ContainerDirectives::DependsOn.new(container_metadata.name)
74
- end
75
-
76
- def ready(sleep:, timeout:, &ready_block)
77
- @directives << Indocker::ContainerDirectives::Ready.new(
78
- sleep: sleep,
79
- timeout: timeout,
80
- ready_block: ready_block
81
- )
82
- end
83
- end