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
@@ -0,0 +1 @@
|
|
1
|
+
Indocker.define_network(:app_net)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'indocker'
|
2
|
+
|
3
|
+
root_dir = File.join(__dir__, '..', '..')
|
4
|
+
|
5
|
+
Indocker.set_root_dir(__dir__)
|
6
|
+
Indocker.set_deploy_dir(File.join(root_dir, 'tmp', 'deployment'))
|
7
|
+
|
8
|
+
Indocker.set_dockerignore [
|
9
|
+
'Dockerfile',
|
10
|
+
'.DS_Store',
|
11
|
+
'**/.DS_Store',
|
12
|
+
'**/*.log',
|
13
|
+
'.vscode',
|
14
|
+
'tmp',
|
15
|
+
]
|
16
|
+
|
17
|
+
require_relative 'infrastructure/registries'
|
18
|
+
require_relative 'infrastructure/servers'
|
19
|
+
require_relative 'infrastructure/build_servers'
|
20
|
+
require_relative 'infrastructure/networks'
|
21
|
+
|
22
|
+
Indocker.set_bounded_contexts_dir(File.join(__dir__, 'bounded_contexts'))
|
23
|
+
|
24
|
+
require_relative "configurations/#{Indocker.configuration_name}"
|
data/indocker.gemspec
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
require_relative 'lib/indocker/version'
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
s.summary = "Indocker"
|
7
|
-
s.description = "DSL for build, run and deploy docker containers"
|
8
|
-
s.authors = ["Droid Labs"]
|
9
|
-
s.email = 'hello@droidlabs.pro'
|
10
|
-
|
11
|
-
s.files = `git ls-files`.split($/)
|
12
|
-
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
-
s.test_files = s.files.grep(%r{^(spec)/})
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "indocker/version"
|
14
5
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
s.add_dependency "docker_registry2"
|
21
|
-
s.add_dependency "thor"
|
22
|
-
s.add_dependency "colorize"
|
23
|
-
s.add_dependency "git"
|
24
|
-
s.add_dependency "byebug" # TODO: remove after release
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "indocker"
|
8
|
+
spec.version = Indocker::VERSION
|
9
|
+
spec.authors = ["Ruslan Gatiyatov", "Iskander Khaziev"]
|
10
|
+
spec.email = ["gvalmon@gmail.com"]
|
25
11
|
|
26
|
-
|
27
|
-
|
28
|
-
|
12
|
+
spec.summary = %q{Docker Containers Deployment}
|
13
|
+
spec.description = %q{Docker Containers Deployment}
|
14
|
+
spec.homepage = "https://github.com/ArtStation/indocker"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "net-ssh"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
data/lib/indocker.rb
CHANGED
@@ -1,155 +1,462 @@
|
|
1
|
-
require
|
1
|
+
require "indocker/version"
|
2
|
+
require 'logger'
|
3
|
+
$LOAD_PATH << File.join(__dir__, 'indocker')
|
2
4
|
|
3
|
-
|
5
|
+
require_relative 'indocker/colored_string'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
module Indocker
|
8
|
+
module Repositories
|
9
|
+
autoload :Abstract, 'repositories/abstract'
|
10
|
+
autoload :Git, 'repositories/git'
|
11
|
+
autoload :Local, 'repositories/local'
|
12
|
+
autoload :NoSync, 'repositories/no_sync'
|
13
|
+
autoload :Clonner, 'repositories/clonner'
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require 'indocker/errors'
|
15
|
-
require 'indocker/cli'
|
16
|
-
require 'indocker/dsl_context'
|
17
|
-
|
18
|
-
require 'indocker/docker_api/docker_api'
|
19
|
-
require 'indocker/docker_api/container_config'
|
20
|
-
|
21
|
-
require 'indocker/configs/config'
|
22
|
-
require 'indocker/configs/config_factory'
|
23
|
-
require 'indocker/configs/locator'
|
24
|
-
require 'indocker/configs/config_initializer'
|
25
|
-
|
26
|
-
require 'indocker/utils/logger'
|
27
|
-
require 'indocker/utils/logger_factory'
|
28
|
-
require 'indocker/utils/test_logger_factory'
|
29
|
-
require 'indocker/utils/tar_helper'
|
30
|
-
require 'indocker/utils/string_utils'
|
31
|
-
require 'indocker/utils/registry_authenticator'
|
32
|
-
require 'indocker/utils/render_util'
|
33
|
-
require 'indocker/utils/render_namespace'
|
34
|
-
|
35
|
-
require 'indocker/handlers/performable'
|
36
|
-
require 'indocker/handlers/container_run'
|
37
|
-
require 'indocker/handlers/container_stop'
|
38
|
-
|
39
|
-
require 'indocker/utils/ioc_container'
|
40
|
-
|
41
|
-
require 'indocker/envs/env_metadata'
|
42
|
-
require 'indocker/envs/loader'
|
43
|
-
|
44
|
-
require 'indocker/registry/registry_helper'
|
45
|
-
require 'indocker/registry/registry_service'
|
46
|
-
require 'indocker/registry/registry_api'
|
47
|
-
|
48
|
-
require 'indocker/image/image_metadata'
|
49
|
-
require 'indocker/image/image_metadata_factory'
|
50
|
-
require 'indocker/image/image_dsl'
|
51
|
-
require 'indocker/image/image_metadata_repository'
|
52
|
-
require 'indocker/image/image_builder'
|
53
|
-
require 'indocker/image/image_dependencies_manager'
|
54
|
-
require 'indocker/image/image_evaluator'
|
55
|
-
require 'indocker/image/image_dockerfile_builder'
|
56
|
-
require 'indocker/image/image_directives_runner'
|
57
|
-
|
58
|
-
require 'indocker/container/container_metadata'
|
59
|
-
require 'indocker/container/container_metadata_repository'
|
60
|
-
require 'indocker/container/container_metadata_factory'
|
61
|
-
require 'indocker/container/container_manager'
|
62
|
-
require 'indocker/container/container_evaluator'
|
63
|
-
require 'indocker/container/container_dsl'
|
64
|
-
require 'indocker/container/container_builder'
|
65
|
-
require 'indocker/container/container_directives_runner'
|
66
|
-
|
67
|
-
require 'indocker/partial/partial_metadata'
|
68
|
-
require 'indocker/partial/partial_metadata_repository'
|
69
|
-
|
70
|
-
require 'indocker/directives/base'
|
71
|
-
require 'indocker/directives/partial'
|
72
|
-
|
73
|
-
require 'indocker/networks/network_metadata'
|
74
|
-
require 'indocker/networks/network_metadata_factory'
|
75
|
-
require 'indocker/networks/network_metadata_repository'
|
76
|
-
|
77
|
-
require 'indocker/volumes/volume_metadata'
|
78
|
-
require 'indocker/volumes/volume_metadata_factory'
|
79
|
-
require 'indocker/volumes/volume_metadata_repository'
|
80
|
-
|
81
|
-
require 'indocker/directives/image_directives/base'
|
82
|
-
require 'indocker/directives/image_directives/cmd'
|
83
|
-
require 'indocker/directives/image_directives/entrypoint'
|
84
|
-
require 'indocker/directives/image_directives/env'
|
85
|
-
require 'indocker/directives/image_directives/copy'
|
86
|
-
require 'indocker/directives/image_directives/from'
|
87
|
-
require 'indocker/directives/image_directives/run'
|
88
|
-
require 'indocker/directives/image_directives/workdir'
|
89
|
-
require 'indocker/directives/image_directives/expose'
|
90
|
-
require 'indocker/directives/image_directives/env_file'
|
91
|
-
require 'indocker/directives/image_directives/docker_cp'
|
92
|
-
require 'indocker/directives/image_directives/registry'
|
93
|
-
|
94
|
-
require 'indocker/directives/container_directives/base'
|
95
|
-
require 'indocker/directives/container_directives/from'
|
96
|
-
require 'indocker/directives/container_directives/network'
|
97
|
-
require 'indocker/directives/container_directives/ports'
|
98
|
-
require 'indocker/directives/container_directives/expose'
|
99
|
-
require 'indocker/directives/container_directives/depends_on'
|
100
|
-
require 'indocker/directives/container_directives/ready'
|
101
|
-
require 'indocker/directives/container_directives/cmd'
|
102
|
-
require 'indocker/directives/container_directives/volume'
|
103
|
-
require 'indocker/directives/container_directives/env_file'
|
104
|
-
require 'indocker/directives/container_directives/env'
|
105
|
-
|
106
|
-
|
107
|
-
require 'indocker/git/git_helper'
|
16
|
+
module Configurations
|
17
|
+
autoload :Configuration, 'configurations/configuration'
|
18
|
+
autoload :ConfigurationBuilder, 'configurations/configuration_builder'
|
108
19
|
|
109
|
-
module
|
110
|
-
|
20
|
+
module Formatters
|
21
|
+
autoload :Stdout, 'configurations/formatters/stdout'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Registries
|
26
|
+
autoload :Abstract, 'registries/abstract'
|
27
|
+
autoload :Local, 'registries/local'
|
28
|
+
autoload :Remote, 'registries/remote'
|
29
|
+
end
|
30
|
+
|
31
|
+
module Concerns
|
32
|
+
autoload :Inspectable, 'concerns/inspectable'
|
33
|
+
end
|
34
|
+
|
35
|
+
module Images
|
36
|
+
autoload :Image, 'images/image'
|
37
|
+
autoload :ImageBuilder, 'images/image_builder'
|
38
|
+
autoload :ImageCompiler, 'images/image_compiler'
|
39
|
+
autoload :TemplateCompiler, 'images/template_compiler'
|
40
|
+
autoload :TemplatesCompiler, 'images/templates_compiler'
|
41
|
+
end
|
42
|
+
|
43
|
+
module Containers
|
44
|
+
autoload :Container, 'containers/container'
|
45
|
+
autoload :ContainerBuilder, 'containers/container_builder'
|
46
|
+
autoload :RestartPolicy, 'containers/restart_policy'
|
47
|
+
end
|
48
|
+
|
49
|
+
module Volumes
|
50
|
+
autoload :Local, 'volumes/local'
|
51
|
+
autoload :External, 'volumes/external'
|
52
|
+
autoload :Repository, 'volumes/repository'
|
53
|
+
end
|
54
|
+
|
55
|
+
module EnvFiles
|
56
|
+
autoload :Local, 'env_files/local'
|
57
|
+
autoload :Remote, 'env_files/remote'
|
58
|
+
end
|
59
|
+
|
60
|
+
module Artifacts
|
61
|
+
autoload :Git, 'artifacts/git'
|
62
|
+
end
|
63
|
+
|
64
|
+
autoload :HashMerger, 'hash_merger'
|
65
|
+
autoload :BuildServer, 'build_server'
|
66
|
+
autoload :Server, 'server'
|
67
|
+
autoload :ConfigurationDeployer, 'configuration_deployer'
|
68
|
+
autoload :SshSession, 'ssh_session'
|
69
|
+
autoload :BuildContextPool, 'build_context_pool'
|
70
|
+
autoload :BuildContext, 'build_context'
|
71
|
+
autoload :BuildContextHelper, 'build_context_helper'
|
72
|
+
autoload :Shell, 'shell'
|
73
|
+
autoload :Docker, 'docker'
|
74
|
+
autoload :ContextArgs, 'context_args'
|
75
|
+
autoload :Network, 'network'
|
76
|
+
autoload :ContainerDeployer, 'container_deployer'
|
77
|
+
autoload :ServerPool, 'server_pool'
|
78
|
+
autoload :DeployContext, 'deploy_context'
|
79
|
+
autoload :ContainerHelper, 'container_helper'
|
80
|
+
autoload :DockerRunArgs, 'docker_run_args'
|
81
|
+
autoload :VolumeHelper, 'volume_helper'
|
82
|
+
autoload :NetworkHelper, 'network_helper'
|
83
|
+
autoload :Rsync, 'rsync'
|
84
|
+
autoload :EnvFileHelper, 'env_file_helper'
|
85
|
+
autoload :IndockerHelper, 'indocker_helper'
|
86
|
+
autoload :ImagesCompiler, 'images_compiler'
|
87
|
+
autoload :ContainerRunner, 'container_runner'
|
88
|
+
autoload :SshResultLogger, 'ssh_result_logger'
|
89
|
+
autoload :DeploymentProgress, 'deployment_progress'
|
90
|
+
autoload :DeploymentChecker, 'deployment_checker'
|
91
|
+
autoload :CrontabRedeployRulesBuilder, 'crontab_redeploy_rules_builder'
|
111
92
|
|
112
93
|
class << self
|
113
|
-
def
|
114
|
-
|
115
|
-
ioc.image_metadata_factory.create(name, &definition)
|
116
|
-
)
|
94
|
+
def set_export_command(command)
|
95
|
+
@export_command = command
|
117
96
|
end
|
118
97
|
|
119
|
-
def
|
120
|
-
|
121
|
-
ioc.container_metadata_factory.create(name, attach: attach, &definition)
|
122
|
-
)
|
98
|
+
def export_command
|
99
|
+
@export_command
|
123
100
|
end
|
124
101
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
102
|
+
def set_deploy_dir(val)
|
103
|
+
@deploy_dir = val
|
104
|
+
end
|
105
|
+
|
106
|
+
def set_root_dir(val)
|
107
|
+
@root_dir = val
|
108
|
+
end
|
109
|
+
|
110
|
+
def set_redeploy_crontab_path(val)
|
111
|
+
@redeploy_crontab_path = val
|
112
|
+
end
|
113
|
+
|
114
|
+
def redeploy_crontab_path
|
115
|
+
@redeploy_crontab_path
|
116
|
+
end
|
117
|
+
|
118
|
+
def deploy_dir
|
119
|
+
if @deploy_dir
|
120
|
+
@deploy_dir
|
121
|
+
else
|
122
|
+
raise ArgumentError.new("deploy dir was not specified")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def root_dir
|
127
|
+
if @root_dir
|
128
|
+
File.expand_path(@root_dir)
|
129
|
+
else
|
130
|
+
raise ArgumentError.new("root dir was not specified")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_artifact(artifact)
|
135
|
+
artifacts.push(artifact)
|
136
|
+
end
|
137
|
+
|
138
|
+
def add_repository(repository)
|
139
|
+
if !repository.is_a?(Indocker::Repositories::Abstract)
|
140
|
+
raise ArgumentError.new("should be an instance of Indocker::Repositories::Abstract, got: #{repository.inspect}")
|
141
|
+
end
|
142
|
+
|
143
|
+
repositories.push(repository)
|
144
|
+
end
|
145
|
+
|
146
|
+
def add_registry(registry)
|
147
|
+
if !registry.is_a?(Indocker::Registries::Abstract)
|
148
|
+
raise ArgumentError.new("should be an instance of Indocker::Registries::Abstract, got: #{registry.inspect}")
|
149
|
+
end
|
150
|
+
|
151
|
+
registries.push(registry)
|
152
|
+
end
|
153
|
+
|
154
|
+
def add_server(server)
|
155
|
+
if !server.is_a?(Indocker::Server)
|
156
|
+
raise ArgumentError.new("should be an instance of Indocker::Server, got: #{server.inspect}")
|
157
|
+
end
|
158
|
+
|
159
|
+
existing = servers.detect {|s| s == server}
|
160
|
+
|
161
|
+
if existing
|
162
|
+
raise ArgumentError.new("server with name #{server.name} was already defined")
|
163
|
+
end
|
164
|
+
|
165
|
+
servers.push(server)
|
129
166
|
end
|
130
167
|
|
131
168
|
def define_network(name)
|
132
|
-
|
133
|
-
|
169
|
+
if networks.detect {|n| n.name == name}
|
170
|
+
raise ArgumentError.new("network :#{name} was already defined")
|
171
|
+
end
|
172
|
+
|
173
|
+
networks.push(Indocker::Network.new(name))
|
174
|
+
end
|
175
|
+
|
176
|
+
def container_files
|
177
|
+
@container_files || (raise ArgumentError.new("container files were not found. Set bounded contexts dir"))
|
178
|
+
end
|
179
|
+
|
180
|
+
def image_files
|
181
|
+
@image_files || (raise ArgumentError.new("image files were not found. Set bounded contexts dir"))
|
182
|
+
end
|
183
|
+
|
184
|
+
def set_bounded_contexts_dir(path)
|
185
|
+
@container_files = {}
|
186
|
+
|
187
|
+
Dir[File.join(path, '**/container.rb')].map do |path|
|
188
|
+
name = path.gsub('/container.rb', '').split('/').last.to_sym
|
189
|
+
@container_files[name] = path
|
190
|
+
end
|
191
|
+
|
192
|
+
@image_files = {}
|
193
|
+
|
194
|
+
Dir[File.join(path, '**/image.rb')].map do |path|
|
195
|
+
name = path.gsub('/image.rb', '').split('/').last.to_sym
|
196
|
+
@image_files[name] = path
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def define_env_file(env_file)
|
201
|
+
if env_files.detect {|ef| ef.name == env_file.name}
|
202
|
+
Indocker.logger.error("env file :#{env_file.name} was already defined")
|
203
|
+
exit 1
|
204
|
+
end
|
205
|
+
|
206
|
+
env_files.push(env_file)
|
207
|
+
end
|
208
|
+
|
209
|
+
def define_volume(volume)
|
210
|
+
if volumes.detect { |v| v.name == volume.name}
|
211
|
+
raise ArgumentError.new("volume :#{volume.name} was already defined")
|
212
|
+
end
|
213
|
+
|
214
|
+
volumes.push(volume)
|
215
|
+
end
|
216
|
+
|
217
|
+
def add_build_server(build_server)
|
218
|
+
if !build_server.is_a?(Indocker::BuildServer)
|
219
|
+
raise ArgumentError.new("should be an instance of Indocker::BuildServer, got: #{build_server.inspect}")
|
220
|
+
end
|
221
|
+
|
222
|
+
existing = build_servers.detect {|s| s == build_server}
|
223
|
+
|
224
|
+
if existing
|
225
|
+
raise ArgumentError.new("build server with name #{build_server.name} was already defined")
|
226
|
+
end
|
227
|
+
|
228
|
+
build_servers.push(build_server)
|
229
|
+
end
|
230
|
+
|
231
|
+
def repositories
|
232
|
+
@repositories ||= []
|
233
|
+
end
|
234
|
+
|
235
|
+
def registries
|
236
|
+
@registries ||= []
|
237
|
+
end
|
238
|
+
|
239
|
+
def networks
|
240
|
+
@networks ||= []
|
241
|
+
end
|
242
|
+
|
243
|
+
def volumes
|
244
|
+
@volumes ||= []
|
245
|
+
end
|
246
|
+
|
247
|
+
def servers
|
248
|
+
@servers ||= []
|
249
|
+
end
|
250
|
+
|
251
|
+
def artifacts
|
252
|
+
@artifacts ||= []
|
253
|
+
end
|
254
|
+
|
255
|
+
def build_servers
|
256
|
+
@build_servers ||= []
|
257
|
+
end
|
258
|
+
|
259
|
+
def env_files
|
260
|
+
@env_files ||= []
|
261
|
+
end
|
262
|
+
|
263
|
+
def configuration
|
264
|
+
@configuration || (raise ArgumentError.new("no configuration provided"))
|
265
|
+
end
|
266
|
+
|
267
|
+
def images
|
268
|
+
@images ||= []
|
269
|
+
end
|
270
|
+
|
271
|
+
def containers
|
272
|
+
@containers ||= []
|
273
|
+
end
|
274
|
+
|
275
|
+
def build_configuration(name)
|
276
|
+
builder = Indocker::Configurations::ConfigurationBuilder.new(
|
277
|
+
name: name,
|
278
|
+
repositories: repositories,
|
279
|
+
registries: registries,
|
280
|
+
servers: servers,
|
281
|
+
build_servers: build_servers,
|
282
|
+
volumes: volumes,
|
283
|
+
networks: networks,
|
284
|
+
env_files: env_files,
|
285
|
+
containers: containers,
|
134
286
|
)
|
287
|
+
|
288
|
+
@configuration = builder.configuration
|
289
|
+
builder
|
135
290
|
end
|
136
291
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
292
|
+
def define_image(name)
|
293
|
+
path = caller[0].split(':').first
|
294
|
+
|
295
|
+
if !(path =~ /\/image.rb$/)
|
296
|
+
Indocker.logger.error("image :#{name} should be defined in image.rb file")
|
297
|
+
exit 1
|
298
|
+
end
|
299
|
+
|
300
|
+
builder = Indocker::Images::ImageBuilder.new(
|
301
|
+
name: name,
|
302
|
+
configuration: configuration,
|
303
|
+
dir: path.split('image.rb').first
|
140
304
|
)
|
305
|
+
|
306
|
+
images.push(builder.image)
|
307
|
+
|
308
|
+
builder
|
141
309
|
end
|
142
310
|
|
143
|
-
def
|
144
|
-
|
311
|
+
def define_container(name)
|
312
|
+
builder = Indocker::Containers::ContainerBuilder.new(
|
313
|
+
name: name,
|
314
|
+
configuration: configuration,
|
315
|
+
)
|
316
|
+
|
317
|
+
containers.push(builder.container)
|
318
|
+
builder
|
319
|
+
end
|
320
|
+
|
321
|
+
def deploy(containers: [], skip_tags: [], tags: [], skip_dependent: false, skip_containers: [], servers: [], skip_build: false, force_restart: false, skip_force_restart: [], auto_confirm: false, require_confirmation: false)
|
322
|
+
Indocker::ConfigurationDeployer
|
323
|
+
.new(Indocker.logger)
|
324
|
+
.run(
|
325
|
+
configuration: configuration,
|
326
|
+
deploy_containers: containers,
|
327
|
+
deploy_tags: tags,
|
328
|
+
skip_dependent: skip_dependent,
|
329
|
+
skip_containers: skip_containers,
|
330
|
+
servers: servers,
|
331
|
+
skip_build: skip_build,
|
332
|
+
force_restart: force_restart,
|
333
|
+
skip_tags: skip_tags,
|
334
|
+
skip_force_restart: skip_force_restart,
|
335
|
+
auto_confirm: auto_confirm,
|
336
|
+
require_confirmation: require_confirmation,
|
337
|
+
)
|
338
|
+
end
|
339
|
+
|
340
|
+
def check(servers: [])
|
341
|
+
Indocker::DeploymentChecker
|
342
|
+
.new(Indocker.logger)
|
343
|
+
.run(
|
344
|
+
configuration: configuration,
|
345
|
+
servers: servers,
|
346
|
+
)
|
347
|
+
end
|
348
|
+
|
349
|
+
def launched?(contaner_name, servers: [])
|
350
|
+
silent_logger = Logger.new(File.open(File::NULL, "w"))
|
351
|
+
Indocker::DeploymentChecker
|
352
|
+
.new(silent_logger, silent_logger)
|
353
|
+
.launched?(
|
354
|
+
contaner_name,
|
355
|
+
configuration: configuration,
|
356
|
+
servers: servers,
|
357
|
+
)
|
358
|
+
end
|
359
|
+
|
360
|
+
def compile(images:, skip_dependent:)
|
361
|
+
Indocker::ImagesCompiler
|
362
|
+
.new(Indocker.logger)
|
363
|
+
.compile(
|
364
|
+
configuration: configuration,
|
365
|
+
image_list: images,
|
366
|
+
skip_dependent: skip_dependent,
|
367
|
+
)
|
368
|
+
end
|
369
|
+
|
370
|
+
def run(container_name, force_restart)
|
371
|
+
Indocker::ContainerRunner
|
372
|
+
.new(Indocker.logger)
|
373
|
+
.run(
|
374
|
+
configuration: configuration,
|
375
|
+
container_name: container_name,
|
376
|
+
force_restart: force_restart
|
377
|
+
)
|
378
|
+
end
|
379
|
+
|
380
|
+
def global_build_args
|
381
|
+
Indocker::ContextArgs.new(nil, configuration.global_build_args, nil)
|
382
|
+
end
|
383
|
+
|
384
|
+
def helper
|
385
|
+
Indocker::BuildContextHelper.new(Indocker.configuration, nil)
|
386
|
+
end
|
387
|
+
|
388
|
+
def logger
|
389
|
+
@logger ||= begin
|
390
|
+
logger = if @log_level == Logger::DEBUG
|
391
|
+
Logger.new(STDOUT)
|
392
|
+
else
|
393
|
+
Logger.new(File.open(File::NULL, "w"))
|
394
|
+
end
|
395
|
+
|
396
|
+
logger.level = @log_level || Logger::INFO
|
397
|
+
|
398
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
399
|
+
level = Logger::SEV_LABEL.index(severity)
|
400
|
+
|
401
|
+
severity = case level
|
402
|
+
when Logger::INFO
|
403
|
+
severity.green
|
404
|
+
when Logger::WARN
|
405
|
+
severity.purple
|
406
|
+
when Logger::DEBUG
|
407
|
+
severity.yellow
|
408
|
+
when Logger::ERROR
|
409
|
+
severity.red
|
410
|
+
when Logger::FATAL
|
411
|
+
severity.red
|
412
|
+
else
|
413
|
+
severity
|
414
|
+
end
|
415
|
+
|
416
|
+
severity = severity.downcase
|
417
|
+
|
418
|
+
if logger.debug?
|
419
|
+
if msg == "{timestamp}"
|
420
|
+
""
|
421
|
+
else
|
422
|
+
"#{datetime.strftime("%Y/%m/%d %H:%M:%S")} #{severity}: #{msg}\n"
|
423
|
+
end
|
424
|
+
else
|
425
|
+
# Use a nicer logging for not debug
|
426
|
+
if msg == "{timestamp}"
|
427
|
+
datetime.strftime("%Y/%m/%d %H:%M:%S\n").grey
|
428
|
+
else
|
429
|
+
" #{severity}: #{msg}\n"
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
logger
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
def set_log_level(level)
|
439
|
+
@log_level = level
|
440
|
+
end
|
441
|
+
|
442
|
+
def set_dockerignore(ignore_list)
|
443
|
+
@dockerignore = ignore_list
|
444
|
+
end
|
445
|
+
|
446
|
+
def dockerignore
|
447
|
+
@dockerignore || []
|
448
|
+
end
|
449
|
+
|
450
|
+
def build_helper(&proc)
|
451
|
+
Indocker::BuildContextHelper.class_exec(&proc)
|
145
452
|
end
|
146
453
|
|
147
|
-
def
|
148
|
-
|
454
|
+
def set_configuration_name(name)
|
455
|
+
@configuration_name = name
|
149
456
|
end
|
150
457
|
|
151
|
-
def
|
152
|
-
|
458
|
+
def configuration_name
|
459
|
+
@configuration_name || (raise ArgumentError.new("configuration was not specified"))
|
153
460
|
end
|
154
461
|
end
|
155
|
-
end
|
462
|
+
end
|