indocker 0.0.6 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +10 -2
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +19 -49
- data/LICENSE.txt +17 -18
- data/README.md +20 -1
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/indocker/bin/deploy +120 -0
- data/example/indocker/bin/remote/compile +72 -0
- data/example/indocker/bin/remote/run +66 -0
- data/example/indocker/bin/utils/configurations.rb +3 -0
- data/example/indocker/bounded_contexts/shared/ruby/Dockerfile +10 -0
- data/example/indocker/bounded_contexts/shared/ruby/container.rb +5 -0
- data/example/indocker/bounded_contexts/shared/ruby/image.rb +3 -0
- data/example/indocker/configurations/dev.rb +9 -0
- data/example/indocker/infrastructure/build_servers.rb +8 -0
- data/example/indocker/infrastructure/networks.rb +1 -0
- data/example/indocker/infrastructure/registries.rb +3 -0
- data/example/indocker/infrastructure/servers.rb +8 -0
- data/example/indocker/setup.rb +24 -0
- data/indocker.gemspec +27 -25
- data/lib/indocker.rb +437 -130
- data/lib/indocker/artifacts/git.rb +25 -0
- data/lib/indocker/build_context.rb +87 -0
- data/lib/indocker/build_context_helper.rb +109 -0
- data/lib/indocker/build_context_pool.rb +36 -0
- data/lib/indocker/build_server.rb +2 -0
- data/lib/indocker/colored_string.rb +33 -0
- data/lib/indocker/concerns/inspectable.rb +12 -0
- data/lib/indocker/configuration_deployer.rb +525 -0
- data/lib/indocker/configurations/configuration.rb +122 -0
- data/lib/indocker/configurations/configuration_builder.rb +250 -0
- data/lib/indocker/configurations/formatters/stdout.rb +36 -0
- data/lib/indocker/container_deployer.rb +73 -0
- data/lib/indocker/container_helper.rb +13 -0
- data/lib/indocker/container_runner.rb +23 -0
- data/lib/indocker/containers/container.rb +118 -0
- data/lib/indocker/containers/container_builder.rb +186 -0
- data/lib/indocker/containers/restart_policy.rb +36 -0
- data/lib/indocker/context_args.rb +43 -0
- data/lib/indocker/crontab_redeploy_rules_builder.rb +54 -0
- data/lib/indocker/deploy_context.rb +126 -0
- data/lib/indocker/deployment_checker.rb +121 -0
- data/lib/indocker/deployment_progress.rb +495 -0
- data/lib/indocker/docker.rb +87 -0
- data/lib/indocker/docker_run_args.rb +183 -0
- data/lib/indocker/env_file_helper.rb +13 -0
- data/lib/indocker/env_files/local.rb +8 -0
- data/lib/indocker/env_files/remote.rb +8 -0
- data/lib/indocker/hash_merger.rb +9 -0
- data/lib/indocker/images/image.rb +86 -0
- data/lib/indocker/images/image_builder.rb +98 -0
- data/lib/indocker/images/image_compiler.rb +68 -0
- data/lib/indocker/images/template_compiler.rb +15 -0
- data/lib/indocker/images/templates_compiler.rb +28 -0
- data/lib/indocker/images_compiler.rb +38 -0
- data/lib/indocker/indocker_helper.rb +9 -0
- data/lib/indocker/network.rb +12 -0
- data/lib/indocker/network_helper.rb +7 -0
- data/lib/indocker/registries/abstract.rb +17 -0
- data/lib/indocker/registries/local.rb +5 -0
- data/lib/indocker/registries/remote.rb +12 -0
- data/lib/indocker/repositories/abstract.rb +25 -0
- data/lib/indocker/repositories/clonner.rb +17 -0
- data/lib/indocker/repositories/git.rb +24 -0
- data/lib/indocker/repositories/local.rb +20 -0
- data/lib/indocker/repositories/no_sync.rb +20 -0
- data/lib/indocker/rsync.rb +52 -0
- data/lib/indocker/server.rb +20 -0
- data/lib/indocker/server_pool.rb +30 -0
- data/lib/indocker/shell.rb +60 -0
- data/lib/indocker/ssh_result_logger.rb +18 -0
- data/lib/indocker/ssh_session.rb +92 -0
- data/lib/indocker/version.rb +1 -1
- data/lib/indocker/volume_helper.rb +7 -0
- data/lib/indocker/volumes/external.rb +8 -0
- data/lib/indocker/volumes/local.rb +9 -0
- data/lib/indocker/volumes/repository.rb +9 -0
- metadata +107 -222
- data/bin/indocker +0 -9
- data/lib/indocker/application_initializer.rb +0 -19
- data/lib/indocker/cli.rb +0 -27
- data/lib/indocker/configs/config.rb +0 -147
- data/lib/indocker/configs/config_factory.rb +0 -37
- data/lib/indocker/configs/config_initializer.rb +0 -9
- data/lib/indocker/configs/locator.rb +0 -23
- data/lib/indocker/container/container_builder.rb +0 -29
- data/lib/indocker/container/container_directives_runner.rb +0 -54
- data/lib/indocker/container/container_dsl.rb +0 -83
- data/lib/indocker/container/container_evaluator.rb +0 -13
- data/lib/indocker/container/container_inspector.rb +0 -26
- data/lib/indocker/container/container_manager.rb +0 -122
- data/lib/indocker/container/container_metadata.rb +0 -112
- data/lib/indocker/container/container_metadata_factory.rb +0 -30
- data/lib/indocker/container/container_metadata_repository.rb +0 -27
- data/lib/indocker/directives/base.rb +0 -17
- data/lib/indocker/directives/container_directives/base.rb +0 -23
- data/lib/indocker/directives/container_directives/cmd.rb +0 -7
- data/lib/indocker/directives/container_directives/depends_on.rb +0 -7
- data/lib/indocker/directives/container_directives/env.rb +0 -7
- data/lib/indocker/directives/container_directives/env_file.rb +0 -7
- data/lib/indocker/directives/container_directives/expose.rb +0 -7
- data/lib/indocker/directives/container_directives/from.rb +0 -14
- data/lib/indocker/directives/container_directives/network.rb +0 -12
- data/lib/indocker/directives/container_directives/ports.rb +0 -15
- data/lib/indocker/directives/container_directives/ready.rb +0 -16
- data/lib/indocker/directives/container_directives/volume.rb +0 -23
- data/lib/indocker/directives/image_directives/base.rb +0 -27
- data/lib/indocker/directives/image_directives/cmd.rb +0 -19
- data/lib/indocker/directives/image_directives/copy.rb +0 -32
- data/lib/indocker/directives/image_directives/docker_cp.rb +0 -20
- data/lib/indocker/directives/image_directives/entrypoint.rb +0 -19
- data/lib/indocker/directives/image_directives/env.rb +0 -9
- data/lib/indocker/directives/image_directives/env_file.rb +0 -19
- data/lib/indocker/directives/image_directives/expose.rb +0 -9
- data/lib/indocker/directives/image_directives/from.rb +0 -36
- data/lib/indocker/directives/image_directives/registry.rb +0 -30
- data/lib/indocker/directives/image_directives/run.rb +0 -17
- data/lib/indocker/directives/image_directives/workdir.rb +0 -9
- data/lib/indocker/directives/partial.rb +0 -21
- data/lib/indocker/docker_api/container_config.rb +0 -121
- data/lib/indocker/docker_api/docker_api.rb +0 -207
- data/lib/indocker/dsl_context.rb +0 -21
- data/lib/indocker/envs/env_metadata.rb +0 -39
- data/lib/indocker/envs/loader.rb +0 -19
- data/lib/indocker/errors.rb +0 -21
- data/lib/indocker/git/git_api.rb +0 -32
- data/lib/indocker/git/git_helper.rb +0 -34
- data/lib/indocker/git/git_service.rb +0 -21
- data/lib/indocker/handlers/container_run.rb +0 -20
- data/lib/indocker/handlers/container_stop.rb +0 -17
- data/lib/indocker/handlers/performable.rb +0 -22
- data/lib/indocker/image/image_builder.rb +0 -54
- data/lib/indocker/image/image_dependencies_manager.rb +0 -47
- data/lib/indocker/image/image_directives_runner.rb +0 -99
- data/lib/indocker/image/image_dockerfile_builder.rb +0 -24
- data/lib/indocker/image/image_dsl.rb +0 -89
- data/lib/indocker/image/image_evaluator.rb +0 -21
- data/lib/indocker/image/image_helper.rb +0 -9
- data/lib/indocker/image/image_metadata.rb +0 -50
- data/lib/indocker/image/image_metadata_factory.rb +0 -31
- data/lib/indocker/image/image_metadata_repository.rb +0 -29
- data/lib/indocker/networks/network_metadata.rb +0 -9
- data/lib/indocker/networks/network_metadata_factory.rb +0 -9
- data/lib/indocker/networks/network_metadata_repository.rb +0 -34
- data/lib/indocker/partial/partial_metadata.rb +0 -8
- data/lib/indocker/partial/partial_metadata_repository.rb +0 -26
- data/lib/indocker/registry/registry_api.rb +0 -46
- data/lib/indocker/registry/registry_helper.rb +0 -20
- data/lib/indocker/registry/registry_service.rb +0 -28
- data/lib/indocker/utils/ioc_container.rb +0 -17
- data/lib/indocker/utils/logger.rb +0 -62
- data/lib/indocker/utils/logger_factory.rb +0 -13
- data/lib/indocker/utils/registry_authenticator.rb +0 -19
- data/lib/indocker/utils/render_namespace.rb +0 -11
- data/lib/indocker/utils/render_util.rb +0 -15
- data/lib/indocker/utils/string_utils.rb +0 -11
- data/lib/indocker/utils/tar_helper.rb +0 -40
- data/lib/indocker/utils/test_logger_factory.rb +0 -9
- data/lib/indocker/volumes/volume_metadata.rb +0 -9
- data/lib/indocker/volumes/volume_metadata_factory.rb +0 -9
- data/lib/indocker/volumes/volume_metadata_repository.rb +0 -34
- data/spec/example/.indocker/config.rb +0 -30
- data/spec/example/.indocker/images_and_containers.rb +0 -25
- data/spec/example/assets/index.css +0 -1
- data/spec/example/assets/index.js +0 -1
- data/spec/fixtures/spec.env +0 -2
- data/spec/indocker/configs/config_factory_spec.rb +0 -18
- data/spec/indocker/configs/config_spec.rb +0 -88
- data/spec/indocker/container/container_builder_spec.rb +0 -67
- data/spec/indocker/container/container_manager_spec.rb +0 -278
- data/spec/indocker/docker_api/container_config_spec.rb +0 -64
- data/spec/indocker/docker_api/docker_api_spec.rb +0 -112
- data/spec/indocker/handlers/container_run_spec.rb +0 -60
- data/spec/indocker/image/image_builder_spec.rb +0 -153
- data/spec/indocker/image/image_directives_runner_spec.rb +0 -141
- data/spec/indocker/image/image_dockerfile_builder_spec.rb +0 -25
- data/spec/indocker/image/image_evaluator_spec.rb +0 -85
- data/spec/spec_helper.rb +0 -68
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'docker-api'
|
2
|
-
require 'io/console'
|
3
|
-
|
4
|
-
Docker.options = { read_timeout: 600, write_timeout: 600, chunk_size: 1 }
|
5
|
-
|
6
|
-
class Indocker::DockerAPI
|
7
|
-
include SmartIoC::Iocify
|
8
|
-
include Indocker::ImageHelper
|
9
|
-
|
10
|
-
bean :docker_api
|
11
|
-
|
12
|
-
inject :logger
|
13
|
-
|
14
|
-
def check_docker_installed!
|
15
|
-
Docker.info
|
16
|
-
nil
|
17
|
-
rescue Excon::Error::Socket
|
18
|
-
raise Indocker::Errors::DockerDoesNotInstalled
|
19
|
-
end
|
20
|
-
|
21
|
-
def authenticate!(serveraddress:, email:, password:, username:)
|
22
|
-
params = {
|
23
|
-
'serveraddress' => serveraddress,
|
24
|
-
'email' => email,
|
25
|
-
'password' => password,
|
26
|
-
'username' => username
|
27
|
-
}.delete_if {|_, value| value.to_s.empty?}
|
28
|
-
|
29
|
-
Docker.authenticate!(params)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Networks
|
33
|
-
|
34
|
-
def create_network(name)
|
35
|
-
Docker::Network.create(name.to_s).id
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_container_to_network(network_name:, container_name:)
|
39
|
-
container_id = get_container_id(container_name.to_s)
|
40
|
-
|
41
|
-
Docker::Network.get(network_name.to_s).connect(container_id.to_s)
|
42
|
-
end
|
43
|
-
|
44
|
-
def delete_network(name)
|
45
|
-
Docker::Network.get(name.to_s).remove
|
46
|
-
end
|
47
|
-
|
48
|
-
def network_exists?(name)
|
49
|
-
!Docker::Network.get(name.to_s).nil? rescue false
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_network_id(name)
|
53
|
-
Docker::Network.get(name.to_s).id
|
54
|
-
end
|
55
|
-
|
56
|
-
def inspect_network(name)
|
57
|
-
Docker::Network.get(name.to_s).info
|
58
|
-
end
|
59
|
-
|
60
|
-
def delete_networks_where(&condition)
|
61
|
-
Docker::Network.all.select(&condition).map do |network|
|
62
|
-
network.remove
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Images
|
67
|
-
|
68
|
-
def get_image_id(repo, tag: nil)
|
69
|
-
Docker::Image.get(full_name(repo, tag)).id rescue nil
|
70
|
-
end
|
71
|
-
|
72
|
-
def image_exists?(repo, tag: nil)
|
73
|
-
Docker::Image.exist?(full_name(repo, tag))
|
74
|
-
end
|
75
|
-
|
76
|
-
def delete_image(repo, tag: nil)
|
77
|
-
Docker::Image.get(full_name(repo, tag)).remove(force: true)
|
78
|
-
end
|
79
|
-
|
80
|
-
def build_from_dir(repo:, tag:, build_dir:)
|
81
|
-
image = Docker::Image.build_from_dir(build_dir, { 't' => "#{repo}:#{tag}" }) do |x|
|
82
|
-
x.split("\r\n").each do |y|
|
83
|
-
if (log = JSON.parse(y)) && log.has_key?("stream")
|
84
|
-
yield log["stream"].strip
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
image.id
|
90
|
-
end
|
91
|
-
|
92
|
-
def tag(repo:, tag: nil, new_repo:, new_tag:)
|
93
|
-
Docker::Image.get(full_name(repo, tag)).tag('repo' => new_repo, 'tag' => new_tag)
|
94
|
-
|
95
|
-
nil
|
96
|
-
end
|
97
|
-
|
98
|
-
def push(repo:, tag:, push_to_repo:, push_to_tag:)
|
99
|
-
Docker::Image.get(full_name(repo, tag)).push(nil, repo_tag: full_name(push_to_repo, push_to_tag))
|
100
|
-
|
101
|
-
nil
|
102
|
-
end
|
103
|
-
|
104
|
-
def pull(opts)
|
105
|
-
image = Docker::Image.create(opts)
|
106
|
-
|
107
|
-
image.id
|
108
|
-
end
|
109
|
-
|
110
|
-
def delete_images_where(&condition)
|
111
|
-
Docker::Image.all.select(&condition).map do |image|
|
112
|
-
image.remove(force: true)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
#Volumes
|
117
|
-
|
118
|
-
def create_volume(name)
|
119
|
-
Docker::Volume.create(name.to_s).id
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_volume_id(name)
|
123
|
-
Docker::Volume.get(name.to_s).id
|
124
|
-
end
|
125
|
-
|
126
|
-
def all_volumes(name)
|
127
|
-
Docker::Volume.all
|
128
|
-
end
|
129
|
-
|
130
|
-
def delete_volume(name)
|
131
|
-
Docker::Volume.get(name.to_s).remove
|
132
|
-
end
|
133
|
-
|
134
|
-
def volume_exists?(name)
|
135
|
-
!Docker::Volume.get(name.to_s).nil? rescue false
|
136
|
-
end
|
137
|
-
|
138
|
-
def inspect_volume(name)
|
139
|
-
Docker::Volume.get(name.to_s).info
|
140
|
-
end
|
141
|
-
|
142
|
-
def delete_volumes_where(&condition)
|
143
|
-
Docker::Volume.all.select(&condition).map do |volume|
|
144
|
-
volume.remove
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# Containers
|
149
|
-
|
150
|
-
def inspect_container(name)
|
151
|
-
Docker::Container.get(name.to_s).info
|
152
|
-
end
|
153
|
-
|
154
|
-
def get_container_id(name)
|
155
|
-
Docker::Container.get(name.to_s).id rescue nil
|
156
|
-
end
|
157
|
-
|
158
|
-
def get_container_image_id(name)
|
159
|
-
Docker::Container.get(name.to_s).info['Image'] rescue nil
|
160
|
-
end
|
161
|
-
|
162
|
-
def get_container_state(name)
|
163
|
-
Docker::Container.get(name.to_s).info["State"]["Status"]
|
164
|
-
end
|
165
|
-
|
166
|
-
def container_exists?(name)
|
167
|
-
!Docker::Container.get(name.to_s).nil? rescue false
|
168
|
-
end
|
169
|
-
|
170
|
-
def start_container(name, attach: false)
|
171
|
-
container = Docker::Container.get(name.to_s).start!
|
172
|
-
|
173
|
-
if attach
|
174
|
-
STDIN.raw do |stdin|
|
175
|
-
container.attach(stdin: stdin, tty: true) do |chunk|
|
176
|
-
logger << chunk
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
container.id
|
182
|
-
end
|
183
|
-
|
184
|
-
def stop_container(name)
|
185
|
-
Docker::Container.get(name.to_s).stop rescue nil
|
186
|
-
end
|
187
|
-
|
188
|
-
def copy_from_container(name:, path:, &block)
|
189
|
-
Docker::Container.get(name.to_s).copy(path, &block)
|
190
|
-
end
|
191
|
-
|
192
|
-
# TODO: Add contract
|
193
|
-
def create_container(container_config)
|
194
|
-
Docker::Container.create(container_config.to_hash).id
|
195
|
-
end
|
196
|
-
|
197
|
-
def delete_container(name)
|
198
|
-
Docker::Container.get(name.to_s).delete(:force => true)
|
199
|
-
end
|
200
|
-
|
201
|
-
def delete_containers_where(&condition)
|
202
|
-
Docker::Container.all(all: true).select(&condition).map do |container|
|
203
|
-
container.stop
|
204
|
-
container.delete(force: true)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
data/lib/indocker/dsl_context.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Indocker::DSLContext
|
2
|
-
attr_reader :storage
|
3
|
-
|
4
|
-
def initialize(storage = {})
|
5
|
-
@storage = storage
|
6
|
-
end
|
7
|
-
|
8
|
-
def method_missing(method, *args)
|
9
|
-
super unless @storage.key?(method)
|
10
|
-
|
11
|
-
@storage.fetch(method)
|
12
|
-
end
|
13
|
-
|
14
|
-
def set_value(key, value)
|
15
|
-
@storage[key] = value
|
16
|
-
end
|
17
|
-
|
18
|
-
def +(other)
|
19
|
-
Indocker::DSLContext.new(@storage.merge(other.storage))
|
20
|
-
end
|
21
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Indocker::Envs
|
2
|
-
class EnvMetadata
|
3
|
-
def initialize(variables = {})
|
4
|
-
@variables = variables
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_hash
|
8
|
-
@variables
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_json
|
12
|
-
to_hash.to_json
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_array
|
16
|
-
to_hash.inject([]) do |all, (k, v)|
|
17
|
-
all.push "#{k}=#{v}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
to_array.join(' ')
|
23
|
-
end
|
24
|
-
|
25
|
-
def set(key:, value:)
|
26
|
-
overwritten = @variables.has_key?(key) and @variables[key] != value
|
27
|
-
|
28
|
-
@variables[key] = value
|
29
|
-
|
30
|
-
overwritten
|
31
|
-
end
|
32
|
-
|
33
|
-
def +(other)
|
34
|
-
combined_hash = to_hash.merge(other.to_hash)
|
35
|
-
|
36
|
-
Indocker::Envs::EnvMetadata.new(combined_hash)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/indocker/envs/loader.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Indocker::Envs::Loader
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :envs_loader
|
5
|
-
|
6
|
-
def parse(path)
|
7
|
-
raise Indocker::Errors::EnvFileDoesNotExist if !File.exists?(path)
|
8
|
-
|
9
|
-
env_metadata = Indocker::Envs::EnvMetadata.new
|
10
|
-
|
11
|
-
File.foreach(path) do |line|
|
12
|
-
key, value = line.split('=').map(&:strip)
|
13
|
-
|
14
|
-
env_metadata.set(key: key, value: value)
|
15
|
-
end
|
16
|
-
|
17
|
-
env_metadata
|
18
|
-
end
|
19
|
-
end
|
data/lib/indocker/errors.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Indocker::Errors
|
2
|
-
class ImageIsNotDefined < StandardError; end
|
3
|
-
class ImageIsNotBuilded < StandardError; end
|
4
|
-
class PartialIsNotDefined < StandardError; end
|
5
|
-
class ContainerIsNotDefined < StandardError; end
|
6
|
-
class CircularImageDependency < StandardError; end
|
7
|
-
class ImageForContainerDoesNotExist < StandardError; end
|
8
|
-
class DockerDoesNotInstalled < StandardError; end
|
9
|
-
class ConfigFilesDoesNotFound < StandardError; end
|
10
|
-
class ConfigOptionTypeMismatch < StandardError; end
|
11
|
-
class DockerRegistryAuthenticationError < StandardError; end
|
12
|
-
class EnvFileDoesNotExist < StandardError; end
|
13
|
-
class ContainerTimeoutError < StandardError; end
|
14
|
-
class ReservedKeywordUsed < StandardError; end
|
15
|
-
class VolumeIsNotDefined < StandardError; end
|
16
|
-
|
17
|
-
class ContainerImageAlreadyDefined < StandardError; end
|
18
|
-
class NetworkAlreadyDefined < StandardError; end
|
19
|
-
|
20
|
-
class InvalidParams < StandardError; end
|
21
|
-
end
|
data/lib/indocker/git/git_api.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'git'
|
2
|
-
|
3
|
-
class Indocker::Git::GitAPI
|
4
|
-
include SmartIoC::Iocify
|
5
|
-
|
6
|
-
bean :git_api
|
7
|
-
|
8
|
-
DEFAULT_REMOTE = 'origin'
|
9
|
-
|
10
|
-
def get_remote_from_directory(dir)
|
11
|
-
Git.open(dir).remote(DEFAULT_REMOTE).url
|
12
|
-
rescue ArgumentError
|
13
|
-
nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def fetch(dir)
|
17
|
-
Git.open(dir).pull
|
18
|
-
end
|
19
|
-
|
20
|
-
def clone(repository:, dir:)
|
21
|
-
dir = File.expand_path(dir)
|
22
|
-
|
23
|
-
git_path = File.dirname(dir)
|
24
|
-
app_name = File.basename(dir)
|
25
|
-
|
26
|
-
Git.clone(repository, app_name, path: git_path)
|
27
|
-
end
|
28
|
-
|
29
|
-
def checkout(revision:, dir:)
|
30
|
-
Git.open(dir).checkout(revision)
|
31
|
-
end
|
32
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Indocker::Git
|
2
|
-
class GitHelper
|
3
|
-
include SmartIoC::Iocify
|
4
|
-
|
5
|
-
bean :git_helper
|
6
|
-
|
7
|
-
inject :config
|
8
|
-
inject :git_service
|
9
|
-
|
10
|
-
def method_missing(method, *args)
|
11
|
-
git_config = config.git.send(method)
|
12
|
-
git_cache_dir = config.git.cache_dir.join(method.to_s)
|
13
|
-
|
14
|
-
return git_cache_dir if updated?(git_config.repository)
|
15
|
-
|
16
|
-
git_service.update(
|
17
|
-
repository: git_config.repository,
|
18
|
-
revision: git_config.branch || git_config.tag,
|
19
|
-
workdir: git_cache_dir
|
20
|
-
)
|
21
|
-
git_cache.push(git_config.repository)
|
22
|
-
|
23
|
-
Pathname.new(git_cache_dir)
|
24
|
-
end
|
25
|
-
|
26
|
-
def git_cache
|
27
|
-
@git_cache ||= []
|
28
|
-
end
|
29
|
-
|
30
|
-
def updated?(url)
|
31
|
-
git_cache.include?(url)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class Indocker::Git::GitService
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :git_service
|
5
|
-
|
6
|
-
inject :git_api
|
7
|
-
|
8
|
-
def update(repository:, revision:, workdir:)
|
9
|
-
workdir_repository = git_api.get_remote_from_directory(workdir)
|
10
|
-
|
11
|
-
if workdir_repository == repository
|
12
|
-
git_api.fetch(workdir)
|
13
|
-
git_api.checkout(revision: revision, dir: workdir)
|
14
|
-
else
|
15
|
-
FileUtils.rm_rf(workdir)
|
16
|
-
|
17
|
-
git_api.clone(repository: repository, dir: workdir)
|
18
|
-
git_api.checkout(revision: revision, dir: workdir)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class Indocker::Handlers::ContainerRun
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :run_container_handler
|
5
|
-
|
6
|
-
inject :container_manager
|
7
|
-
inject :container_metadata_repository
|
8
|
-
inject :image_builder
|
9
|
-
|
10
|
-
include Indocker::Handlers::Performable
|
11
|
-
|
12
|
-
def handle(name:, current_path:)
|
13
|
-
name = name.to_s
|
14
|
-
|
15
|
-
container_metadata = container_metadata_repository.get_by_name(name)
|
16
|
-
image_builder.build(container_metadata.repo, tag: container_metadata.tag)
|
17
|
-
|
18
|
-
container_manager.run(name)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class Indocker::Handlers::ContainerStop
|
2
|
-
include SmartIoC::Iocify
|
3
|
-
|
4
|
-
bean :stop_container_handler
|
5
|
-
|
6
|
-
inject :container_manager
|
7
|
-
inject :container_metadata_repository
|
8
|
-
inject :image_builder
|
9
|
-
|
10
|
-
include Indocker::Handlers::Performable
|
11
|
-
|
12
|
-
def handle(name:, current_path:)
|
13
|
-
name = name.to_s
|
14
|
-
|
15
|
-
container_manager.stop(name)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Indocker
|
2
|
-
module Handlers
|
3
|
-
module Performable
|
4
|
-
def self.included(klass)
|
5
|
-
klass.inject(:logger)
|
6
|
-
klass.inject(:application_initializer)
|
7
|
-
end
|
8
|
-
|
9
|
-
def perform(options)
|
10
|
-
env = options.delete(:env)
|
11
|
-
|
12
|
-
application_initializer.init_app(options[:current_path], env: env)
|
13
|
-
|
14
|
-
self.method(:handle).call(options)
|
15
|
-
rescue Docker::Error::ClientError => e
|
16
|
-
logger.error e.message
|
17
|
-
rescue Docker::Error::NotFoundError => e
|
18
|
-
logger.error(e.message)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|