diff --git a/exporter/containerimage/writer.go b/exporter/containerimage/writer.go index f980afdc..4146efae 100644 --- a/exporter/containerimage/writer.go +++ b/exporter/containerimage/writer.go @@ -5,12 +5,12 @@ import ( "context" "encoding/json" "fmt" - "runtime" "time" "github.com/containerd/containerd/content" "github.com/containerd/containerd/diff" "github.com/containerd/containerd/images" + "github.com/containerd/containerd/platforms" "github.com/moby/buildkit/cache" "github.com/moby/buildkit/cache/blobs" "github.com/moby/buildkit/exporter" @@ -291,9 +291,21 @@ func (ic *ImageWriter) ContentStore() content.Store { } func emptyImageConfig() ([]byte, error) { - img := ocispec.Image{ - Architecture: runtime.GOARCH, - OS: runtime.GOOS, + pl := platforms.Normalize(platforms.DefaultSpec()) + + type image struct { + ocispec.Image + + // Variant defines platform variant. To be added to OCI. + Variant string `json:"variant,omitempty"` + } + + img := image{ + Image: ocispec.Image{ + Architecture: pl.Architecture, + OS: pl.OS, + }, + Variant: pl.Variant, } img.RootFS.Type = "layers" img.Config.WorkingDir = "/" diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index b63e7870..05279230 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -390,6 +390,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, if !platformOpt.implicitTarget { target.image.OS = platformOpt.targetPlatform.OS target.image.Architecture = platformOpt.targetPlatform.Architecture + target.image.Variant = platformOpt.targetPlatform.Variant } return &st, &target.image, nil diff --git a/frontend/dockerfile/dockerfile2llb/image.go b/frontend/dockerfile/dockerfile2llb/image.go index e83e58b6..55e9add2 100644 --- a/frontend/dockerfile/dockerfile2llb/image.go +++ b/frontend/dockerfile/dockerfile2llb/image.go @@ -50,6 +50,9 @@ type Image struct { // Config defines the execution parameters which should be used as a base when running a container using the image. Config ImageConfig `json:"config,omitempty"` + + // Variant defines platform variant. To be added to OCI. + Variant string `json:"variant,omitempty"` } func clone(src Image) Image { @@ -67,6 +70,7 @@ func emptyImage(platform specs.Platform) Image { Architecture: platform.Architecture, OS: platform.OS, }, + Variant: platform.Variant, } img.RootFS.Type = "layers" img.Config.WorkingDir = "/"