Class: Dapp::Application
- Inherits:
-
Object
- Object
- Dapp::Application
- Includes:
- GitArtifact, Path, Stages, Tags, Helper::Sha256
- Defined in:
- lib/dapp/application.rb,
lib/dapp/application/path.rb,
lib/dapp/application/tags.rb,
lib/dapp/application/stages.rb,
lib/dapp/application/git_artifact.rb
Overview
Application
Direct Known Subclasses
Defined Under Namespace
Modules: GitArtifact, Path, Stages, Tags
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#ignore_git_fetch ⇒ Object
readonly
Returns the value of attribute ignore_git_fetch.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#should_be_built ⇒ Object
readonly
Returns the value of attribute should_be_built.
Instance Method Summary collapse
- #artifact? ⇒ Boolean
- #build! ⇒ Object
- #builder ⇒ Object
- #export!(repo, format:) ⇒ Object
- #export_base!(image, image_name) ⇒ Object
- #export_stages!(repo, format:) ⇒ Object
- #import_base!(image, image_name) ⇒ Object
- #import_stages!(repo, format:) ⇒ Object
-
#initialize(config:, project:, should_be_built: false, ignore_git_fetch: false) ⇒ Application
constructor
A new instance of Application.
- #run(docker_options, command) ⇒ Object
- #scratch? ⇒ Boolean
- #stage_image_name(stage_name) ⇒ Object
Methods included from Helper::Sha256
#hashsum, #paths_content_hashsum, #sha256
Methods included from Stages
#images, #signature, #stage_cache_format, #stage_dapp_label
Methods included from Path
#build_path, #container_dapp_path, #container_tmp_path, #home_path, #tmp_path
Methods included from GitArtifact
#git_artifacts, #local_git_artifacts, #remote_git_artifacts
Constructor Details
#initialize(config:, project:, should_be_built: false, ignore_git_fetch: false) ⇒ Application
Returns a new instance of Application.
16 17 18 19 20 21 22 23 24 |
# File 'lib/dapp/application.rb', line 16 def initialize(config:, project:, should_be_built: false, ignore_git_fetch: false) @config = config @project = project @ignore_git_fetch = ignore_git_fetch @should_be_built = should_be_built raise Error::Application, code: :application_not_built if should_be_built? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/dapp/application.rb', line 11 def config @config end |
#ignore_git_fetch ⇒ Object (readonly)
Returns the value of attribute ignore_git_fetch.
12 13 14 |
# File 'lib/dapp/application.rb', line 12 def ignore_git_fetch @ignore_git_fetch end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
14 15 16 |
# File 'lib/dapp/application.rb', line 14 def project @project end |
#should_be_built ⇒ Object (readonly)
Returns the value of attribute should_be_built.
13 14 15 |
# File 'lib/dapp/application.rb', line 13 def should_be_built @should_be_built end |
Instance Method Details
#artifact? ⇒ Boolean
118 119 120 |
# File 'lib/dapp/application.rb', line 118 def artifact? false end |
#build! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dapp/application.rb', line 26 def build! with_introspection do project.lock("#{config._basename}.images", readonly: true) do last_stage.build_lock! do last_stage.build! last_stage.save_in_cache! end end end ensure FileUtils.rm_rf(tmp_path) end |
#builder ⇒ Object
114 115 116 |
# File 'lib/dapp/application.rb', line 114 def builder @builder ||= Builder.const_get(config._builder.capitalize).new(self) end |
#export!(repo, format:) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/dapp/application.rb', line 39 def export!(repo, format:) project.lock("#{config._basename}.images", readonly: true) do .each do |tag| image_name = format % { repo: repo, application_name: config._name, tag: tag } export_base!(last_stage.image, image_name) end end end |
#export_base!(image, image_name) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dapp/application.rb', line 57 def export_base!(image, image_name) if project.dry_run? project.log_state(image_name, state: project.t(code: 'state.push'), styles: { status: :success }) else project.lock("image.#{hashsum image_name}") do Dapp::Image::Stage.cache_reset(image_name) project.log_process(image_name, process: project.t(code: 'status.process.pushing')) do project.with_log_indent do image.export!(image_name) end end end end end |
#export_stages!(repo, format:) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/dapp/application.rb', line 48 def export_stages!(repo, format:) project.lock("#{config._basename}.images", readonly: true) do export_images.each do |image| image_name = format % { repo: repo, signature: image.name.split(':').last } export_base!(image, image_name) end end end |
#import_base!(image, image_name) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dapp/application.rb', line 86 def import_base!(image, image_name) if project.dry_run? project.log_state(image_name, state: project.t(code: 'state.pull'), styles: { status: :success }) else project.lock("image.#{hashsum image_name}") do project.log_process(image_name, process: project.t(code: 'status.process.pulling'), status: { failed: project.t(code: 'status.failed.not_pulled') }, style: { failed: :secondary }) do image.import!(image_name) end end end end |
#import_stages!(repo, format:) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dapp/application.rb', line 72 def import_stages!(repo, format:) project.lock("#{config._basename}.images", readonly: true) do import_images.each do |image| begin image_name = format % { repo: repo, signature: image.name.split(':').last } import_base!(image, image_name) rescue Error::Shellout next end break unless project.pull_all_stages? end end end |
#run(docker_options, command) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/dapp/application.rb', line 101 def run(, command) cmd = "docker run #{[, last_stage.image.name, command].flatten.compact.join(' ')}" if project.dry_run? project.log(cmd) else system(cmd) || raise(Error::Application, code: :application_not_run) end end |
#scratch? ⇒ Boolean
122 123 124 |
# File 'lib/dapp/application.rb', line 122 def scratch? config._docker._from.nil? end |
#stage_image_name(stage_name) ⇒ Object
110 111 112 |
# File 'lib/dapp/application.rb', line 110 def stage_image_name(stage_name) stages.find { |stage| stage.send(:name) == stage_name }.image.name end |