daemon: stop propagating Image.DockerVersion field

The DockerVersion field was used by the legacy builder, and set when
importing an image; when importing an image, this would potentially
result in less reproducible images, as the docker version used to import
the image would be encoded in the image's "v1" fields.

For the legacy builder, including the version of docker used to build
the image could still be useful information (but could be set as comment,
similar to what BuildKit does), however, many code paths were also shared
with other parts of the code; e.g., when listing images or inspecting images,
the `DockerVersion` field would always be set to the current version of
the docker daemon, and not taken from the information available in the
image (if any).

This patch removes locations where the `DockerVersion` field was set to
the current version of the daemon binary. When inspecting an image, the
field is still set with the information in the image itself (which may
be empty in most cases).

This also reduces the number of places where the `dockerversion` package
is used, which still needs a new home.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-05 13:35:20 +02:00
parent 19e498ea65
commit a99b7947e1
4 changed files with 17 additions and 25 deletions

View File

@@ -7,7 +7,6 @@ import (
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/v2/daemon/internal/image"
"github.com/moby/moby/v2/dockerversion"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@@ -18,13 +17,12 @@ import (
// - Details
func dockerOciImageToDockerImagePartial(id image.ID, img dockerspec.DockerOCIImage) *image.Image {
v1Image := image.V1Image{
DockerVersion: dockerversion.Version,
Config: dockerOCIImageConfigToContainerConfig(img.Config),
Architecture: img.Platform.Architecture,
Variant: img.Platform.Variant,
OS: img.Platform.OS,
Author: img.Author,
Created: img.Created,
Config: dockerOCIImageConfigToContainerConfig(img.Config),
Architecture: img.Platform.Architecture,
Variant: img.Platform.Variant,
OS: img.Platform.OS,
Author: img.Author,
Created: img.Created,
}
out := image.NewImage(id)

View File

@@ -14,7 +14,6 @@ import (
"github.com/moby/moby/v2/daemon/builder/dockerfile"
"github.com/moby/moby/v2/daemon/internal/image"
"github.com/moby/moby/v2/daemon/internal/layer"
"github.com/moby/moby/v2/dockerversion"
"github.com/moby/moby/v2/errdefs"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@@ -53,13 +52,12 @@ func (i *ImageService) ImportImage(ctx context.Context, newRef reference.Named,
created := time.Now().UTC()
imgConfig, err := json.Marshal(&image.Image{
V1Image: image.V1Image{
DockerVersion: dockerversion.Version,
Config: config,
Architecture: platform.Architecture,
Variant: platform.Variant,
OS: platform.OS,
Created: &created,
Comment: msg,
Config: config,
Architecture: platform.Architecture,
Variant: platform.Variant,
OS: platform.OS,
Created: &created,
Comment: msg,
},
RootFS: &image.RootFS{
Type: "layers",

View File

@@ -11,7 +11,6 @@ import (
"github.com/moby/moby/v2/daemon/builder"
"github.com/moby/moby/v2/daemon/internal/image"
"github.com/moby/moby/v2/daemon/internal/layer"
"github.com/moby/moby/v2/dockerversion"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
@@ -141,12 +140,11 @@ func (ic *ImageCache) restoreCachedImage(parent, target *image.Image, cfg *conta
restoredImg := image.Image{
V1Image: image.V1Image{
DockerVersion: dockerversion.Version,
Config: cfg,
Architecture: target.Architecture,
OS: target.OS,
Author: target.Author,
Created: history[len(history)-1].Created,
Config: cfg,
Architecture: target.Architecture,
OS: target.OS,
Author: target.Author,
Created: history[len(history)-1].Created,
},
RootFS: rootFS,
History: history,

View File

@@ -11,7 +11,6 @@ import (
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/v2/daemon/internal/layer"
"github.com/moby/moby/v2/dockerversion"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@@ -236,7 +235,6 @@ func NewChildImage(img *Image, child ChildConfig, os string) *Image {
return &Image{
V1Image: V1Image{
DockerVersion: dockerversion.Version,
Config: child.Config,
Architecture: img.BaseImgArch(),
Variant: img.BaseImgVariant(),