Module: Indocker
- Defined in:
- lib/indocker.rb,
lib/indocker/version.rb
Defined Under Namespace
Modules: Artifacts, Concerns, Configurations, Containers, EnvFiles, Images, Launchers, Networks, Registries, Repositories, ServerPools, Volumes
Classes: BuildContext, BuildContextHelper, BuildServer, ContainerDeployer, ContainerHelper, ContextArgs, CrontabRedeployRulesBuilder, DeployContext, DeploymentChecker, DeploymentPolicy, DeploymentProgress, Docker, DockerRunArgs, EnvFileHelper, HashMerger, IndockerHelper, LoggerFactory, Rsync, Server, Shell, SshResultLogger, SshSession
Constant Summary
collapse
- VERSION =
"0.6.3"
Class Method Summary
collapse
-
.add_artifact(artifact) ⇒ Object
-
.add_build_server(build_server) ⇒ Object
-
.add_registry(registry) ⇒ Object
-
.add_repository(repository) ⇒ Object
-
.add_server(server) ⇒ Object
-
.artifacts ⇒ Object
-
.build_configuration(name) ⇒ Object
-
.build_helper(&proc) ⇒ Object
-
.build_servers ⇒ Object
-
.check(servers: []) ⇒ Object
-
.compile(images:, skip_dependent:, compile_args: {}) ⇒ Object
-
.configuration ⇒ Object
-
.configuration_name ⇒ Object
-
.container_files ⇒ Object
-
.containers ⇒ Object
-
.define_container(name) ⇒ Object
-
.define_env_file(env_file) ⇒ Object
-
.define_image(name) ⇒ Object
-
.define_network(name) ⇒ Object
-
.define_volume(volume) ⇒ Object
-
.deploy(containers: [], skip_tags: [], tags: [], skip_dependent: false, skip_containers: [], servers: [], skip_build: false, skip_deploy: false, force_restart: false, skip_force_restart: [], auto_confirm: false, require_confirmation: false, compile_args: {}, deploy_args: {}) ⇒ Object
-
.deploy_dir ⇒ Object
-
.dockerignore ⇒ Object
-
.env_files ⇒ Object
-
.export_command ⇒ Object
-
.global_build_args ⇒ Object
-
.global_logger ⇒ Object
Global logger would output data without dependency on how we deploy the progress Currently it will always output data to stdout.
-
.helper ⇒ Object
-
.image_files ⇒ Object
-
.images ⇒ Object
-
.launched?(contaner_name, servers: nil) ⇒ Boolean
-
.logger ⇒ Object
This logger outputs progress of the deployment It will not output anything for deployment without debug option.
-
.networks ⇒ Object
-
.redeploy_crontab_path ⇒ Object
-
.registries ⇒ Object
-
.remote_operation_timeout ⇒ Object
-
.repositories ⇒ Object
-
.root_dir ⇒ Object
-
.run(container_name, force_restart, deploy_args: {}) ⇒ Object
-
.servers ⇒ Object
-
.set_bounded_contexts_dir(path) ⇒ Object
-
.set_configuration_name(name) ⇒ Object
-
.set_deploy_dir(val) ⇒ Object
-
.set_dockerignore(ignore_list) ⇒ Object
-
.set_export_command(command) ⇒ Object
-
.set_log_level(level) ⇒ Object
-
.set_redeploy_crontab_path(val) ⇒ Object
-
.set_remote_operation_timeout(seconds) ⇒ Object
-
.set_root_dir(val) ⇒ Object
-
.set_ssh_connect_timeout(seconds) ⇒ Object
-
.ssh_connect_timeout ⇒ Object
-
.volumes ⇒ Object
Class Method Details
.add_artifact(artifact) ⇒ Object
174
175
176
|
# File 'lib/indocker.rb', line 174
def add_artifact(artifact)
artifacts.push(artifact)
end
|
.add_build_server(build_server) ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/indocker.rb', line 257
def add_build_server(build_server)
if !build_server.is_a?(Indocker::BuildServer)
raise ArgumentError.new("should be an instance of Indocker::BuildServer, got: #{build_server.inspect}")
end
existing = build_servers.detect {|s| s == build_server}
if existing
raise ArgumentError.new("build server with name #{build_server.name} was already defined")
end
build_servers.push(build_server)
end
|
.add_registry(registry) ⇒ Object
186
187
188
189
190
191
192
|
# File 'lib/indocker.rb', line 186
def add_registry(registry)
if !registry.is_a?(Indocker::Registries::Abstract)
raise ArgumentError.new("should be an instance of Indocker::Registries::Abstract, got: #{registry.inspect}")
end
registries.push(registry)
end
|
.add_repository(repository) ⇒ Object
178
179
180
181
182
183
184
|
# File 'lib/indocker.rb', line 178
def add_repository(repository)
if !repository.is_a?(Indocker::Repositories::Abstract)
raise ArgumentError.new("should be an instance of Indocker::Repositories::Abstract, got: #{repository.inspect}")
end
repositories.push(repository)
end
|
.add_server(server) ⇒ Object
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/indocker.rb', line 194
def add_server(server)
if !server.is_a?(Indocker::Server)
raise ArgumentError.new("should be an instance of Indocker::Server, got: #{server.inspect}")
end
existing = servers.detect {|s| s == server}
if existing
raise ArgumentError.new("server with name #{server.name} was already defined")
end
servers.push(server)
end
|
.artifacts ⇒ Object
291
292
293
|
# File 'lib/indocker.rb', line 291
def artifacts
@artifacts ||= []
end
|
.build_configuration(name) ⇒ Object
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
# File 'lib/indocker.rb', line 315
def build_configuration(name)
builder = Indocker::Configurations::ConfigurationBuilder.new(
name: name,
repositories: repositories,
registries: registries,
servers: servers,
build_servers: build_servers,
volumes: volumes,
networks: networks,
env_files: env_files,
containers: containers,
)
@configuration = builder.configuration
builder
end
|
.build_helper(&proc) ⇒ Object
.build_servers ⇒ Object
295
296
297
|
# File 'lib/indocker.rb', line 295
def build_servers
@build_servers ||= []
end
|
.check(servers: []) ⇒ Object
397
398
399
400
401
402
403
404
|
# File 'lib/indocker.rb', line 397
def check(servers: [])
Indocker::DeploymentChecker
.new(Indocker.logger)
.run(
configuration: configuration,
servers: servers,
)
end
|
.compile(images:, skip_dependent:, compile_args: {}) ⇒ Object
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
# File 'lib/indocker.rb', line 417
def compile(images:, skip_dependent:, compile_args: {})
if compile_args
configuration.set_global_build_args(
Indocker::HashMerger.deep_merge(compile_args, configuration.global_build_args)
)
end
Indocker::Launchers::ImagesCompiler
.new(Indocker.logger)
.compile(
configuration: configuration,
image_list: images,
skip_dependent: skip_dependent,
)
end
|
.configuration ⇒ Object
303
304
305
|
# File 'lib/indocker.rb', line 303
def configuration
@configuration || (raise ArgumentError.new("no configuration provided"))
end
|
.configuration_name ⇒ Object
495
496
497
|
# File 'lib/indocker.rb', line 495
def configuration_name
@configuration_name || (raise ArgumentError.new("configuration was not specified"))
end
|
.container_files ⇒ Object
216
217
218
|
# File 'lib/indocker.rb', line 216
def container_files
@container_files || (raise ArgumentError.new("container files were not found. Set bounded contexts dir"))
end
|
.containers ⇒ Object
311
312
313
|
# File 'lib/indocker.rb', line 311
def containers
@containers ||= []
end
|
.define_container(name) ⇒ Object
351
352
353
354
355
356
357
358
359
|
# File 'lib/indocker.rb', line 351
def define_container(name)
builder = Indocker::Containers::ContainerBuilder.new(
name: name,
configuration: configuration,
)
containers.push(builder.container)
builder
end
|
.define_env_file(env_file) ⇒ Object
240
241
242
243
244
245
246
247
|
# File 'lib/indocker.rb', line 240
def define_env_file(env_file)
if env_files.detect {|ef| ef.name == env_file.name}
Indocker.logger.error("env file :#{env_file.name} was already defined")
exit 1
end
env_files.push(env_file)
end
|
.define_image(name) ⇒ Object
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
# File 'lib/indocker.rb', line 332
def define_image(name)
path = caller[0].split(':').first
if !(path =~ /\/image.rb$/)
Indocker.logger.error("image :#{name} should be defined in image.rb file")
exit 1
end
builder = Indocker::Images::ImageBuilder.new(
name: name,
configuration: configuration,
dir: path.split('image.rb').first
)
images.push(builder.image)
builder
end
|
.define_network(name) ⇒ Object
208
209
210
211
212
213
214
|
# File 'lib/indocker.rb', line 208
def define_network(name)
if networks.detect {|n| n.name == name}
raise ArgumentError.new("network :#{name} was already defined")
end
networks.push(Indocker::Networks::Network.new(name))
end
|
.define_volume(volume) ⇒ Object
249
250
251
252
253
254
255
|
# File 'lib/indocker.rb', line 249
def define_volume(volume)
if volumes.detect { |v| v.name == volume.name}
raise ArgumentError.new("volume :#{volume.name} was already defined")
end
volumes.push(volume)
end
|
.deploy(containers: [], skip_tags: [], tags: [], skip_dependent: false, skip_containers: [], servers: [], skip_build: false, skip_deploy: false, force_restart: false, skip_force_restart: [], auto_confirm: false, require_confirmation: false, compile_args: {}, deploy_args: {}) ⇒ Object
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
# File 'lib/indocker.rb', line 361
def deploy(containers: [], skip_tags: [], tags: [], skip_dependent: false,
skip_containers: [], servers: [], skip_build: false, skip_deploy: false,
force_restart: false, skip_force_restart: [], auto_confirm: false,
require_confirmation: false, compile_args: {}, deploy_args: {})
deployment_policy = Indocker::DeploymentPolicy.new(
deploy_containers: containers,
deploy_tags: tags,
servers: servers,
skip_dependent: skip_dependent,
skip_containers: skip_containers,
skip_build: skip_build,
skip_deploy: skip_deploy,
skip_tags: skip_tags,
force_restart: force_restart,
skip_force_restart: skip_force_restart,
auto_confirm: auto_confirm,
require_confirmation: require_confirmation,
)
if compile_args
configuration.set_compile_args(compile_args)
end
if deploy_args
configuration.set_deploy_args(deploy_args)
end
Indocker::Launchers::ConfigurationDeployer
.new(logger: Indocker.logger, global_logger: Indocker.global_logger)
.run(
configuration: configuration,
deployment_policy: deployment_policy
)
end
|
.deploy_dir ⇒ Object
158
159
160
161
162
163
164
|
# File 'lib/indocker.rb', line 158
def deploy_dir
if @deploy_dir
@deploy_dir
else
raise ArgumentError.new("deploy dir was not specified")
end
end
|
.dockerignore ⇒ Object
483
484
485
|
# File 'lib/indocker.rb', line 483
def dockerignore
@dockerignore || []
end
|
.env_files ⇒ Object
299
300
301
|
# File 'lib/indocker.rb', line 299
def env_files
@env_files ||= []
end
|
.export_command ⇒ Object
122
123
124
|
# File 'lib/indocker.rb', line 122
def export_command
@export_command
end
|
.global_build_args ⇒ Object
447
448
449
|
# File 'lib/indocker.rb', line 447
def global_build_args
Indocker::ContextArgs.new(nil, configuration.global_build_args, nil)
end
|
.global_logger ⇒ Object
Global logger would output data without dependency on how we deploy the progress
Currently it will always output data to stdout
471
472
473
|
# File 'lib/indocker.rb', line 471
def global_logger
@global_logger ||= Indocker::LoggerFactory.create(STDOUT, @log_level)
end
|
.image_files ⇒ Object
220
221
222
|
# File 'lib/indocker.rb', line 220
def image_files
@image_files || (raise ArgumentError.new("image files were not found. Set bounded contexts dir"))
end
|
.images ⇒ Object
307
308
309
|
# File 'lib/indocker.rb', line 307
def images
@images ||= []
end
|
.launched?(contaner_name, servers: nil) ⇒ Boolean
406
407
408
409
410
411
412
413
414
415
|
# File 'lib/indocker.rb', line 406
def launched?(contaner_name, servers: nil)
silent_logger = Logger.new(File.open(File::NULL, "w"))
Indocker::DeploymentChecker
.new(silent_logger, silent_logger)
.launched?(
contaner_name,
configuration: configuration,
servers: servers,
)
end
|
.logger ⇒ Object
This logger outputs progress of the deployment
It will not output anything for deployment without debug option
457
458
459
460
461
462
463
464
465
466
467
|
# File 'lib/indocker.rb', line 457
def logger
@logger ||= begin
logger_stdout = if @log_level == Logger::DEBUG
STDOUT
else
File.open(File::NULL, "w")
end
Indocker::LoggerFactory.create(logger_stdout, @log_level)
end
end
|
.networks ⇒ Object
279
280
281
|
# File 'lib/indocker.rb', line 279
def networks
@networks ||= []
end
|
.redeploy_crontab_path ⇒ Object
154
155
156
|
# File 'lib/indocker.rb', line 154
def redeploy_crontab_path
@redeploy_crontab_path
end
|
.registries ⇒ Object
275
276
277
|
# File 'lib/indocker.rb', line 275
def registries
@registries ||= []
end
|
.remote_operation_timeout ⇒ Object
142
143
144
|
# File 'lib/indocker.rb', line 142
def remote_operation_timeout
@remote_operation_timeout || 300
end
|
.repositories ⇒ Object
271
272
273
|
# File 'lib/indocker.rb', line 271
def repositories
@repositories ||= []
end
|
.root_dir ⇒ Object
166
167
168
169
170
171
172
|
# File 'lib/indocker.rb', line 166
def root_dir
if @root_dir
File.expand_path(@root_dir)
else
raise ArgumentError.new("root dir was not specified")
end
end
|
.run(container_name, force_restart, deploy_args: {}) ⇒ Object
433
434
435
436
437
438
439
440
441
442
443
444
445
|
# File 'lib/indocker.rb', line 433
def run(container_name, force_restart, deploy_args: {})
if deploy_args
configuration.set_deploy_args(deploy_args)
end
Indocker::Launchers::ContainerRunner
.new(Indocker.logger)
.run(
configuration: configuration,
container_name: container_name,
force_restart: force_restart
)
end
|
.servers ⇒ Object
287
288
289
|
# File 'lib/indocker.rb', line 287
def servers
@servers ||= []
end
|
.set_bounded_contexts_dir(path) ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/indocker.rb', line 224
def set_bounded_contexts_dir(path)
@container_files = {}
Dir[File.join(path, '**/container.rb')].map do |path|
name = path.gsub('/container.rb', '').split('/').last.to_sym
@container_files[name] = path
end
@image_files = {}
Dir[File.join(path, '**/image.rb')].map do |path|
name = path.gsub('/image.rb', '').split('/').last.to_sym
@image_files[name] = path
end
end
|
.set_configuration_name(name) ⇒ Object
491
492
493
|
# File 'lib/indocker.rb', line 491
def set_configuration_name(name)
@configuration_name = name
end
|
.set_deploy_dir(val) ⇒ Object
126
127
128
|
# File 'lib/indocker.rb', line 126
def set_deploy_dir(val)
@deploy_dir = val
end
|
.set_dockerignore(ignore_list) ⇒ Object
479
480
481
|
# File 'lib/indocker.rb', line 479
def set_dockerignore(ignore_list)
@dockerignore = ignore_list
end
|
.set_export_command(command) ⇒ Object
118
119
120
|
# File 'lib/indocker.rb', line 118
def set_export_command(command)
@export_command = command
end
|
.set_log_level(level) ⇒ Object
475
476
477
|
# File 'lib/indocker.rb', line 475
def set_log_level(level)
@log_level = level
end
|
.set_redeploy_crontab_path(val) ⇒ Object
134
135
136
|
# File 'lib/indocker.rb', line 134
def set_redeploy_crontab_path(val)
@redeploy_crontab_path = val
end
|
.set_remote_operation_timeout(seconds) ⇒ Object
138
139
140
|
# File 'lib/indocker.rb', line 138
def set_remote_operation_timeout(seconds)
@remote_operation_timeout = seconds
end
|
.set_root_dir(val) ⇒ Object
130
131
132
|
# File 'lib/indocker.rb', line 130
def set_root_dir(val)
@root_dir = val
end
|
.set_ssh_connect_timeout(seconds) ⇒ Object
146
147
148
|
# File 'lib/indocker.rb', line 146
def set_ssh_connect_timeout(seconds)
@ssh_connect_timeout = seconds
end
|
.ssh_connect_timeout ⇒ Object
150
151
152
|
# File 'lib/indocker.rb', line 150
def ssh_connect_timeout
@ssh_connect_timeout || 15
end
|
.volumes ⇒ Object
283
284
285
|
# File 'lib/indocker.rb', line 283
def volumes
@volumes ||= []
end
|