Class: Microsandbox::Image
- Inherits:
-
Object
- Object
- Microsandbox::Image
- Defined in:
- lib/microsandbox/image.rb
Overview
Management of the local OCI image cache. Images are pulled automatically by Sandbox.create; this namespace lets you inspect and prune the cache.
Class Method Summary collapse
-
.get(reference) ⇒ ImageInfo
Metadata for one cached image.
-
.inspect(reference = nil) ⇒ ImageDetail
Full inspection detail for a cached image.
-
.list ⇒ Array<ImageInfo>
All cached images.
-
.load(input_path, tag: nil) ⇒ Array<ImageInfo>
Load images into the cache from a local
docker savetarball or an OCI Image Layout archive. -
.prune ⇒ ImagePruneReport
Garbage-collect unreferenced images, manifests, and layers.
-
.remove(reference, force: false) ⇒ nil
Remove a cached image.
-
.save(reference, output_path:, format: :docker) ⇒ nil
Save cached image(s) into a local archive.
Class Method Details
.get(reference) ⇒ ImageInfo
Metadata for one cached image.
84 85 86 |
# File 'lib/microsandbox/image.rb', line 84 def get(reference) ImageInfo.new(Native::Image.get(reference.to_s)) end |
.inspect(reference = nil) ⇒ ImageDetail
Full inspection detail for a cached image. With no argument this is the
normal class #inspect (so object display still works).
91 92 93 94 95 |
# File 'lib/microsandbox/image.rb', line 91 def inspect(reference = nil) return super() if reference.nil? ImageDetail.new(Native::Image.inspect(reference.to_s)) end |
.list ⇒ Array<ImageInfo>
All cached images.
78 79 80 |
# File 'lib/microsandbox/image.rb', line 78 def list Native::Image.list.map { |info| ImageInfo.new(info) } end |
.load(input_path, tag: nil) ⇒ Array<ImageInfo>
Load images into the cache from a local docker save tarball or an
OCI Image Layout archive. Pass "-" to read the archive from $stdin
(spooled to a temp file first, like the Python SDK — the core reads
seekable files only). Mirrors the Python Image.load / Node
imageLoad (runtime v0.6.7).
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/microsandbox/image.rb', line 119 def load(input_path, tag: nil) = Array(tag).map(&:to_s) path = input_path.to_s if path == "-" require "tempfile" Tempfile.create(["msb-image-load", ".tar"]) do |tmp| tmp.binmode IO.copy_stream($stdin, tmp) tmp.flush return Native::Image.load(tmp.path, ).map { |info| ImageInfo.new(info) } end end Native::Image.load(path, ).map { |info| ImageInfo.new(info) } end |
.prune ⇒ ImagePruneReport
Garbage-collect unreferenced images, manifests, and layers.
107 108 109 |
# File 'lib/microsandbox/image.rb', line 107 def prune ImagePruneReport.new(Native::Image.prune) end |
.remove(reference, force: false) ⇒ nil
Remove a cached image.
100 101 102 103 |
# File 'lib/microsandbox/image.rb', line 100 def remove(reference, force: false) Native::Image.remove(reference.to_s, force) nil end |
.save(reference, output_path:, format: :docker) ⇒ nil
Save cached image(s) into a local archive.
Mirrors the Python Image.save / Node imageSave (runtime v0.6.7).
141 142 143 144 145 146 147 |
# File 'lib/microsandbox/image.rb', line 141 def save(reference, output_path:, format: :docker) refs = Array(reference).map(&:to_s) raise ArgumentError, "at least one image reference is required" if refs.empty? Native::Image.save(refs, output_path.to_s, format.to_s) nil end |