Skip to content

Commit 09afe32

Browse files
committed
Update uses of Image platform fields in OCI image-spec
The OCI image spec is considering to change the Image struct and embedding the Platform type (see opencontainers/image-spec#959) in the go implementation. BuildKit currently uses some struct-literals to propagate the platform fields, which will break once those changes in the OCI spec are merged. Ideally (once that change arrives) we would update the code to set the Platform information as a whole, instead of assigning related fields individually, but in some cases in the code, image platform information is only partially set (for example, OSVersion and OSFeatures are not preserved in all cases). This may be on purpose, so needs to be reviewed. This patch keeps the current behavior (assigning only specific fields), but removes the use of struct-literals to make the code compatible with the upcoming changes in the image-spec module. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c563db6 commit 09afe32

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

exporter/containerimage/writer.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,10 @@ func (ic *ImageWriter) Applier() diff.Applier {
530530
func defaultImageConfig() ([]byte, error) {
531531
pl := platforms.Normalize(platforms.DefaultSpec())
532532

533-
img := ocispecs.Image{
534-
Architecture: pl.Architecture,
535-
OS: pl.OS,
536-
Variant: pl.Variant,
537-
}
533+
img := ocispecs.Image{}
534+
img.Architecture = pl.Architecture
535+
img.OS = pl.OS
536+
img.Variant = pl.Variant
538537
img.RootFS.Type = "layers"
539538
img.Config.WorkingDir = "/"
540539
img.Config.Env = []string{"PATH=" + system.DefaultPathEnv(pl.OS)}
@@ -543,13 +542,12 @@ func defaultImageConfig() ([]byte, error) {
543542
}
544543

545544
func attestationsConfig(layers []ocispecs.Descriptor) ([]byte, error) {
546-
img := ocispecs.Image{
547-
Architecture: intotoPlatform.Architecture,
548-
OS: intotoPlatform.OS,
549-
OSVersion: intotoPlatform.OSVersion,
550-
OSFeatures: intotoPlatform.OSFeatures,
551-
Variant: intotoPlatform.Variant,
552-
}
545+
img := ocispecs.Image{}
546+
img.Architecture = intotoPlatform.Architecture
547+
img.OS = intotoPlatform.OS
548+
img.OSVersion = intotoPlatform.OSVersion
549+
img.OSFeatures = intotoPlatform.OSFeatures
550+
img.Variant = intotoPlatform.Variant
553551
img.RootFS.Type = "layers"
554552
for _, layer := range layers {
555553
img.RootFS.DiffIDs = append(img.RootFS.DiffIDs, digest.Digest(layer.Annotations["containerd.io/uncompressed"]))

frontend/dockerfile/dockerfile2llb/image.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ func clone(src image.Image) image.Image {
1616
}
1717

1818
func emptyImage(platform ocispecs.Platform) image.Image {
19-
img := image.Image{
20-
Image: ocispecs.Image{
21-
Architecture: platform.Architecture,
22-
OS: platform.OS,
23-
Variant: platform.Variant,
24-
},
25-
}
19+
img := image.Image{}
20+
img.Architecture = platform.Architecture
21+
img.OS = platform.OS
22+
img.Variant = platform.Variant
2623
img.RootFS.Type = "layers"
2724
img.Config.WorkingDir = "/"
2825
img.Config.Env = []string{"PATH=" + system.DefaultPathEnv(platform.OS)}

0 commit comments

Comments
 (0)