Skip to content

Commit a5ba66a

Browse files
committed
Fix annotations for containerd
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
1 parent fd18316 commit a5ba66a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

internal/oci_image_build.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,32 @@ func (ic *ImageBuilder) CreateImageFromCheckpoint(ctx context.Context) error {
8080
}
8181

8282
// Step 4: Commit the container to an image
83-
_, err = runBuildahCommand("commit", newContainer, ic.imageName)
83+
imageID, err := runBuildahCommand("commit", newContainer, ic.imageName)
8484
if err != nil {
8585
return fmt.Errorf("committing container annotations failed: %w", err)
8686
}
8787

88+
// Step 5: Create a manifest for containerd compatibility
89+
manifestName := ic.imageName + "-manifest"
90+
// Remove any existing manifest with the same name
91+
_, _ = runBuildahCommand("manifest", "rm", manifestName)
92+
if _, err := runBuildahCommand("manifest", "create", manifestName, strings.TrimSpace(imageID)); err != nil {
93+
return fmt.Errorf("creating manifest failed: %w", err)
94+
}
95+
96+
// Step 6: Annotate the manifest with checkpoint annotations
97+
for key, value := range checkpointImageAnnotations {
98+
if _, err := runBuildahCommand("manifest", "annotate", "--index", "--annotation", fmt.Sprintf("%s=%s", key, value), manifestName); err != nil {
99+
return fmt.Errorf("annotating manifest failed: %w", err)
100+
}
101+
}
102+
103+
// Step 7: Tag the manifest with the final image name and clean up
104+
if _, err := runBuildahCommand("tag", manifestName, ic.imageName); err != nil {
105+
return fmt.Errorf("tagging manifest failed: %w", err)
106+
}
107+
_, _ = runBuildahCommand("manifest", "rm", manifestName) // Remove temp manifest name
108+
88109
return nil
89110
}
90111

0 commit comments

Comments
 (0)