Class: QB::Docker::Image
- Inherits:
-
QB::Data::Immutable
- Object
- Hamster::Hash
- QB::Data::Immutable
- QB::Docker::Image
- Includes:
- NRSER::Log::Mixin
- Defined in:
- lib/qb/docker/image.rb,
lib/qb/docker/image/tag.rb,
lib/qb/docker/image/name.rb
Defined Under Namespace
Class Method Summary collapse
- .build!(name:, path:, push: false, tags: [], _cmd_stream: true, **build_opts) ⇒ Object
- .ensure_present!(name:, pull: nil, build: nil, force: false, push: false, tags: []) ⇒ Object
- .names(**opts) ⇒ Object
Class Method Details
.build!(name:, path:, push: false, tags: [], _cmd_stream: true, **build_opts) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/qb/docker/image.rb', line 78 def self.build! name:, path:, push: false, tags: [], _cmd_stream: true, **build_opts cmd = QB::Docker::CLI.build_cmd path, tag: name.to_s, **build_opts logger.info "building...", name: name.to_s, path: path, push: push, _cmd_stream: _cmd_stream, cmd: cmd.prepare result = run_cmd! cmd, stream: _cmd_stream .each do |tag_arg| cmd = QB::Docker::CLI.tag_cmd name, tag_arg tag = cmd.args[1] logger.debug "Tagging #{ name } as #{ tag }", tag_arg: tag_arg result = run_cmd cmd, stream: _cmd_stream if result.ok? logger.info "Tagged #{ name } as #{ tag }.", cmd: cmd.last_prepared_cmd else logger.error "Failed to tag #{ name } as #{ tag }", tag_arg: tag_arg, cmd: cmd.last_prepared_cmd end end QB::Docker::CLI.push( name ) if push result end |
.ensure_present!(name:, pull: nil, build: nil, force: false, push: false, tags: []) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/qb/docker/image.rb', line 120 def self.ensure_present! name:, pull: nil, build: nil, force: false, push: false, tags: [] name = QB::Docker::Image::Name.from name if pull.nil? && name.tag && name.tag.version.is_a?( QB::Package::Version::Leveled ) pull = !name.tag.version.dev? end logger.info "Ensuring image is present...", name: name.to_s, pull: pull, push: push, force: force if force logger.info "Forcing build...", name: name.to_s build! name: name, push: push, tags: , **build return end if name.exists? logger.info "Image exists", name: name.to_s return end logger.info "Name does NOT exist", name: name.to_s if pull logger.info "Attempting to pull...", name: name.to_s return if QB::Docker::CLI.pull?( name ) end logger.info "Resorting to building...", name: name.to_s, path: build[:path] build! name: name, push: push, tags: , **build end |
.names(**opts) ⇒ Object
47 48 49 |
# File 'lib/qb/docker/image.rb', line 47 def self.names **opts QB::Docker::CLI.image_names **opts end |