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) ⇒ Object
- .names(**opts) ⇒ Object
- .run_cmd(cmd, stream: true, raise_on_fail: false) ⇒ Object
- .run_cmd!(cmd, stream: true) ⇒ Object
- .with_name(name, &block) ⇒ Object
Class Method Details
.build!(name:, path:, push: false, tags: [], _cmd_stream: true, **build_opts) ⇒ Object
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/qb/docker/image.rb', line 93 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) ⇒ Object
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/qb/docker/image.rb', line 135 def self.ensure_present! name:, pull: nil, build: nil, force: false, push: false 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, **build QB::Docker::CLI.push?( name: name ) if push 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, **build QB::Docker::CLI.push( name: name ) if push end |
.names(**opts) ⇒ Object
66 67 68 |
# File 'lib/qb/docker/image.rb', line 66 def self.names **opts QB::Docker::CLI.image_names **opts end |
.run_cmd(cmd, stream: true, raise_on_fail: false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/qb/docker/image.rb', line 71 def self.run_cmd cmd, stream: true, raise_on_fail: false if stream if raise_on_fail cmd.stream! else cmd.stream end else cmd.capture.tap { |result| if raise_on_fail && result.error? raise QB::Docker::CLI::Error.from_result result end } end end |
.run_cmd!(cmd, stream: true) ⇒ Object
88 89 90 |
# File 'lib/qb/docker/image.rb', line 88 def self.run_cmd! cmd, stream: true run_cmd cmd, stream: stream, raise_on_fail: true end |
.with_name(name, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/qb/docker/image.rb', line 49 def self.with_name name, &block block.call \ case name when QB::Docker::Image::Name name when String QB::Docker::Image::Name.from_s name when Hash QB::Docker::Image::Name.from_data name else raise NRSER::TypeError.new \ "Not sure what to do with ", name, name: name end end |