indocker 0.0.5 → 0.1.3
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 +44 -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 +104 -219
- 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,68 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Indocker::Images::ImageCompiler
|
4
|
+
BUILDS_DIR = 'image_build'.freeze
|
5
|
+
DOCKERIGNORE = <<~EOS
|
6
|
+
Dockerfile
|
7
|
+
.DS_Store
|
8
|
+
**/.DS_Store
|
9
|
+
**/*.log
|
10
|
+
**/*_spec.rb
|
11
|
+
node_modules
|
12
|
+
.vagrant
|
13
|
+
.vscode
|
14
|
+
tmp
|
15
|
+
logs
|
16
|
+
EOS
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@compiled_images = Hash.new(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
def compile(build_context, image, skip_dependent)
|
23
|
+
if !skip_dependent
|
24
|
+
image.dependent_images.each do |dependent_image|
|
25
|
+
compile_image(build_context, dependent_image)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
compile_image(build_context, image)
|
30
|
+
end
|
31
|
+
|
32
|
+
def compile_image(build_context, image)
|
33
|
+
return if @compiled_images[image]
|
34
|
+
|
35
|
+
compile_dir = File.join(build_context.configuration.build_dir, BUILDS_DIR, image.name.to_s)
|
36
|
+
FileUtils.rm_rf(compile_dir)
|
37
|
+
FileUtils.mkdir_p(compile_dir)
|
38
|
+
|
39
|
+
if image.build_context
|
40
|
+
templates_compiler = Indocker::Images::TemplatesCompiler.new
|
41
|
+
|
42
|
+
templates_compiler.compile(
|
43
|
+
templates_dir: image.build_context,
|
44
|
+
compile_dir: compile_dir,
|
45
|
+
context: build_context
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
compiler = Indocker::Images::TemplateCompiler.new
|
50
|
+
|
51
|
+
target_dockerfile = File.join(compile_dir, 'Dockerfile')
|
52
|
+
FileUtils.cp(image.dockerfile, target_dockerfile)
|
53
|
+
compiler.compile(target_dockerfile, build_context)
|
54
|
+
|
55
|
+
File
|
56
|
+
.join(compile_dir, '.dockerignore')
|
57
|
+
.tap { |_| File.write(_, Indocker.dockerignore.join("\n")) }
|
58
|
+
|
59
|
+
if image.before_build
|
60
|
+
image.before_build.call(build_context, compile_dir)
|
61
|
+
end
|
62
|
+
|
63
|
+
build_context.build_image(image, compile_dir)
|
64
|
+
build_context.set_compiled(image)
|
65
|
+
|
66
|
+
@compiled_images[image] = true
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Indocker::Images::TemplateCompiler
|
4
|
+
def compile(path, context)
|
5
|
+
Indocker.logger.debug("compiling template file #{path}".grey)
|
6
|
+
template = File.read(path)
|
7
|
+
content = ERB.new(template).result(context.helper.get_binding)
|
8
|
+
File.write(path, content)
|
9
|
+
rescue Errno::EACCES => e
|
10
|
+
# do nothing for read only files
|
11
|
+
rescue => e
|
12
|
+
Indocker.logger.error("compilation failed for template file #{path}. #{e.inspect}")
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Indocker::Images::TemplatesCompiler
|
5
|
+
def compile(templates_dir:, compile_dir:, context:)
|
6
|
+
prepare_dirs!(templates_dir, compile_dir)
|
7
|
+
|
8
|
+
compiler = Indocker::Images::TemplateCompiler.new
|
9
|
+
|
10
|
+
Dir[File.join(compile_dir, '**/**')].each do |file|
|
11
|
+
next if !File.file?(file)
|
12
|
+
compiler.compile(file, context)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def prepare_dirs!(templates_dir, compile_dir)
|
19
|
+
Indocker.logger.debug("recreating directory #{compile_dir}".grey)
|
20
|
+
FileUtils.rm_rf(compile_dir)
|
21
|
+
FileUtils.mkdir_p(compile_dir)
|
22
|
+
|
23
|
+
Indocker.logger.debug("copy template files".grey)
|
24
|
+
Indocker.logger.debug(" from: #{templates_dir}".grey)
|
25
|
+
Indocker.logger.debug(" to: #{compile_dir}".grey)
|
26
|
+
FileUtils.cp_r(File.join(templates_dir, '.'), compile_dir)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Indocker::ImagesCompiler
|
2
|
+
def initialize(logger)
|
3
|
+
@logger = logger
|
4
|
+
end
|
5
|
+
|
6
|
+
def compile(configuration:, image_list:, skip_dependent:)
|
7
|
+
preload_images(configuration, image_list)
|
8
|
+
|
9
|
+
build_context = Indocker::BuildContext.new(
|
10
|
+
configuration: configuration,
|
11
|
+
build_server: nil,
|
12
|
+
logger: Indocker.logger
|
13
|
+
)
|
14
|
+
|
15
|
+
image_compiler = Indocker::Images::ImageCompiler.new
|
16
|
+
|
17
|
+
image_list.each do |image_name|
|
18
|
+
image = Indocker.configuration.images.detect do |i|
|
19
|
+
i.name == image_name
|
20
|
+
end
|
21
|
+
|
22
|
+
image_compiler.compile(build_context, image, skip_dependent)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def preload_images(configuration, image_list)
|
29
|
+
image_list.each do |image_name|
|
30
|
+
image_path = Indocker.image_files.fetch(image_name) do
|
31
|
+
@logger.error("image not found :#{image_name} in configuration :#{configuration.name}")
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
require image_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Indocker::Registries::Abstract
|
2
|
+
include Indocker::Concerns::Inspectable
|
3
|
+
|
4
|
+
attr_reader :repository_name
|
5
|
+
|
6
|
+
def initialize(repository_name)
|
7
|
+
@repository_name = repository_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup(*args)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_local?
|
15
|
+
self.is_a?(Indocker::Registries::Local)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Indocker::Repositories::Abstract
|
2
|
+
include Indocker::Concerns::Inspectable
|
3
|
+
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup(*args)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_local?
|
15
|
+
self.is_a?(Indocker::Repositories::Local)
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_git?
|
19
|
+
self.is_a?(Indocker::Repositories::Git)
|
20
|
+
end
|
21
|
+
|
22
|
+
def is_no_sync?
|
23
|
+
self.is_a?(Indocker::Repositories::NoSync)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
|
3
|
+
class Indocker::Repositories::Clonner
|
4
|
+
def initialize(configuration, logger)
|
5
|
+
@configuration = configuration
|
6
|
+
@logger = logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def clone(session, repository)
|
10
|
+
raise ArgumenError.new("only git repositories should be clonned") if !repository.is_git?
|
11
|
+
|
12
|
+
session.exec!("rm -rf #{repository.clone_path} && mkdir -p #{repository.clone_path}")
|
13
|
+
|
14
|
+
git_command = "git clone -b #{repository.branch} --depth 1 #{repository.remote_url} #{repository.clone_path}"
|
15
|
+
session.exec!("ssh-agent bash -c 'ssh-add ~/.ssh/#{repository.ssh_key}; #{git_command}'")
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Indocker::Repositories::Git < Indocker::Repositories::Abstract
|
2
|
+
attr_reader :remote_url, :remote_name, :email, :password, :branch, :ssh_key
|
3
|
+
|
4
|
+
DEFAULT_SSH_KEY = "id_rsa"
|
5
|
+
|
6
|
+
def setup(remote_name:, remote_url:, email: nil, password: nil, branch:, clone_path: nil, ssh_key: DEFAULT_SSH_KEY)
|
7
|
+
@remote_name = remote_name
|
8
|
+
@remote_url = remote_url
|
9
|
+
@email = email
|
10
|
+
@password = password
|
11
|
+
@branch = branch
|
12
|
+
@clone_path = clone_path
|
13
|
+
@ssh_key = ssh_key
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def project_name
|
18
|
+
@remote_url.split('/').last.gsub('.git', '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def clone_path
|
22
|
+
@clone_path || "/tmp/#{Indocker.configuration.name}/repositories/git/#{project_name}/#{branch}"
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Indocker::Repositories::Local < Indocker::Repositories::Abstract
|
2
|
+
attr_reader :root_path
|
3
|
+
|
4
|
+
def setup(root_path)
|
5
|
+
@root_path = File.expand_path(root_path)
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def project_name
|
10
|
+
root_path.split('/').last
|
11
|
+
end
|
12
|
+
|
13
|
+
def root_path
|
14
|
+
@root_path || (raise ArgumentError.new("root path was not set. Set it using setup method"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def clone_path
|
18
|
+
"/tmp/#{Indocker.configuration.name}/repositories/local/#{project_name}"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Indocker::Repositories::NoSync < Indocker::Repositories::Abstract
|
2
|
+
attr_reader :root_path
|
3
|
+
|
4
|
+
def setup(root_path)
|
5
|
+
@root_path = File.expand_path(root_path)
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def project_name
|
10
|
+
root_path.split('/').last
|
11
|
+
end
|
12
|
+
|
13
|
+
def root_path
|
14
|
+
@root_path || (raise ArgumentError.new("root path was not set. Set it using setup method"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def clone_path
|
18
|
+
root_path
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative 'shell'
|
2
|
+
|
3
|
+
class Indocker::Rsync
|
4
|
+
def self.local_sync(from, to, create_path: nil, raise_on_error: false, exclude: nil)
|
5
|
+
@session ||= Indocker::SshSession.new(
|
6
|
+
host: 'localhost',
|
7
|
+
user: nil,
|
8
|
+
port: nil,
|
9
|
+
logger: Indocker.logger
|
10
|
+
)
|
11
|
+
|
12
|
+
sync(@session, from, to, create_path: create_path, raise_on_error: raise_on_error, exclude: exclude)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.sync(session, from, to, create_path: nil, raise_on_error: false, exclude: nil)
|
16
|
+
if create_path
|
17
|
+
session.exec!("mkdir -p #{create_path}")
|
18
|
+
end
|
19
|
+
|
20
|
+
if session.local?
|
21
|
+
return if File.expand_path(to) == File.expand_path(from)
|
22
|
+
|
23
|
+
Indocker::Shell.command("rm -rf #{to}", Indocker.logger, raise_on_error: raise_on_error)
|
24
|
+
|
25
|
+
if Indocker::Shell.command_exist?("rsync")
|
26
|
+
sync_local_rsync(from, to, raise_on_error: raise_on_error, exclude: exclude)
|
27
|
+
else
|
28
|
+
Indocker.logger.debug("WARNING: exclude option skipped due to fallback to CP command")
|
29
|
+
sync_local_cp(from, to, raise_on_error: raise_on_error)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
command = "rsync --delete-after -a -e 'ssh -p #{session.port}' #{from} #{session.user}@#{session.host}:#{to}"
|
33
|
+
Indocker.logger.debug("sync #{from} #{session.user}@#{session.host}:#{to}")
|
34
|
+
Indocker::Shell.command(command, Indocker.logger, raise_on_error: raise_on_error)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def self.sync_local_cp(from, to, raise_on_error:)
|
40
|
+
Indocker::Shell.command("cp -r #{from} #{to}", Indocker.logger, raise_on_error: raise_on_error)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.sync_local_rsync(from, to, raise_on_error:, exclude: nil)
|
44
|
+
options = []
|
45
|
+
options << " --exclude=#{exclude}" if exclude
|
46
|
+
# Add a trailing slash to directory to have behavior similar to CP command
|
47
|
+
if File.directory?(from) && !from.end_with?("/")
|
48
|
+
from = "#{from}/"
|
49
|
+
end
|
50
|
+
Indocker::Shell.command("rsync -a #{options.join(' ')} #{from} #{to}", Indocker.logger, raise_on_error: raise_on_error)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Indocker::Server
|
2
|
+
include Indocker::Concerns::Inspectable
|
3
|
+
|
4
|
+
attr_reader :name, :host, :user, :port
|
5
|
+
|
6
|
+
def initialize(name:, host:, user:, port:)
|
7
|
+
@name = name
|
8
|
+
@host = host
|
9
|
+
@user = user
|
10
|
+
@port = port
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(value)
|
14
|
+
if value.is_a?(Indocker::Server)
|
15
|
+
@name == value.name
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Indocker::ServerPool
|
2
|
+
def initialize(configuration:, logger:)
|
3
|
+
@logger = logger
|
4
|
+
@configuration = configuration
|
5
|
+
|
6
|
+
@contexts = configuration.servers.map do |server|
|
7
|
+
Indocker::DeployContext.new(
|
8
|
+
logger: @logger,
|
9
|
+
configuration: configuration,
|
10
|
+
server: server,
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(server)
|
16
|
+
Indocker::DeployContext.new(
|
17
|
+
logger: @logger,
|
18
|
+
configuration: @configuration,
|
19
|
+
server: server,
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def each(&proc)
|
24
|
+
@contexts.each(&proc)
|
25
|
+
end
|
26
|
+
|
27
|
+
def close_sessions
|
28
|
+
@contexts.each(&:close_session)
|
29
|
+
end
|
30
|
+
end
|