Skip to content

Commit 419bd04

Browse files
committed
Correctly store "canonical" image refs in containerd's image store
In other words, instead of `ubuntu:22.04`, we should store it as `docker.io/library/ubuntu:22.04` (which Docker then converts appropriately on `docker load`).
1 parent c427135 commit 419bd04

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cmd/bashbrew/oci-builder.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ func ociImportBuild(tags []string, commit, dir, file string) error {
180180
is := client.ImageService()
181181

182182
for _, tag := range tags {
183+
ref, err := docker.ParseAnyReference(tag)
184+
if err != nil {
185+
return fmt.Errorf("failed to parse tag %q while updating image in containerd: %w", tag, err)
186+
}
183187
img := images.Image{
184-
Name: tag,
188+
Name: ref.String(),
185189
Target: manifestDescriptor,
186190
}
187191
img2, err := is.Update(ctx, img, "target") // "target" here is to specify that we want to update the descriptor that "Name" points to (if this image name already exists)
@@ -216,7 +220,11 @@ func ociImportDockerLoad(tags []string) error {
216220
archive.WithAllPlatforms(),
217221
}
218222
for _, tag := range tags {
219-
exportOpts = append(exportOpts, archive.WithImage(is, tag))
223+
ref, err := docker.ParseAnyReference(tag)
224+
if err != nil {
225+
return fmt.Errorf("failed to parse tag %q while loading containerd image into Docker: %w", tag, err)
226+
}
227+
exportOpts = append(exportOpts, archive.WithImage(is, ref.String()))
220228
}
221229

222230
dockerLoad := exec.Command("docker", "load")
@@ -260,7 +268,12 @@ func ociImportLookup(tag string) (*imagespec.Descriptor, error) {
260268

261269
is := client.ImageService()
262270

263-
img, err := is.Get(ctx, tag)
271+
ref, err := docker.ParseAnyReference(tag)
272+
if err != nil {
273+
return nil, fmt.Errorf("failed to parse tag %q while looking up containerd ref: %w", tag, err)
274+
}
275+
276+
img, err := is.Get(ctx, ref.String())
264277
if err != nil {
265278
return nil, err
266279
}

0 commit comments

Comments
 (0)