1
0
mirror of https://github.com/containers/buildah.git synced 2026-02-05 09:45:38 +01:00

commit: set "parent" for docker format only when requested

Make setting the Parent field in the config blob of a docker format
image optional (yes, we're bringing it back!), since it no longer
appears to be set by newer versions of docker build.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2024-06-06 15:57:56 -04:00
committed by Chris Evich
parent b97639bd1f
commit 435fd2673e
5 changed files with 18 additions and 0 deletions

View File

@@ -108,6 +108,10 @@ type CommitOptions struct {
// UnsetEnvs is a list of environments to not add to final image.
// Deprecated: use UnsetEnv() before committing instead.
UnsetEnvs []string
// CompatSetParent causes the "parent" field to be set when committing
// the image in Docker format. Newer BuildKit-based builds don't set
// this field.
CompatSetParent types.OptionalBool
}
var (

View File

@@ -316,4 +316,8 @@ type BuildOptions struct {
// value set in a base image will be preserved, so this does not
// frequently need to be set.
OSVersion string
// CompatSetParent causes the "parent" field to be set in the image's
// configuration when committing in Docker format. Newer
// BuildKit-based docker build doesn't set this field.
CompatSetParent types.OptionalBool
}

View File

@@ -76,6 +76,7 @@ type containerImageRef struct {
blobDirectory string
preEmptyLayers []v1.History
postEmptyLayers []v1.History
compatSetParent types.OptionalBool
}
type blobLayerInfo struct {
@@ -230,6 +231,11 @@ func (i *containerImageRef) createConfigsAndManifests() (v1.Image, v1.Manifest,
if err := json.Unmarshal(i.dconfig, &dimage); err != nil {
return v1.Image{}, v1.Manifest{}, docker.V2Image{}, docker.V2S2Manifest{}, err
}
// Set the parent, but only if we want to be compatible with "classic" docker build.
if i.compatSetParent == types.OptionalBoolTrue {
dimage.Parent = docker.ID(i.parent)
}
// Set the container ID and containerConfig in the docker format.
dimage.Container = i.containerID
if dimage.Config != nil {
dimage.ContainerConfig = *dimage.Config
@@ -838,6 +844,7 @@ func (b *Builder) makeContainerImageRef(options CommitOptions) (*containerImageR
blobDirectory: options.BlobDirectory,
preEmptyLayers: b.PrependedEmptyLayers,
postEmptyLayers: b.AppendedEmptyLayers,
compatSetParent: options.CompatSetParent,
}
return ref, nil
}

View File

@@ -141,6 +141,7 @@ type Executor struct {
osVersion string
osFeatures []string
envs []string
compatSetParent types.OptionalBool
}
type imageTypeAndHistoryAndDiffIDs struct {
@@ -293,6 +294,7 @@ func newExecutor(logger *logrus.Logger, logPrefix string, store storage.Store, o
osVersion: options.OSVersion,
osFeatures: append([]string{}, options.OSFeatures...),
envs: append([]string{}, options.Envs...),
compatSetParent: options.CompatSetParent,
}
if exec.err == nil {
exec.err = os.Stderr

View File

@@ -2014,6 +2014,7 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
RetryDelay: s.executor.retryPullPushDelay,
HistoryTimestamp: s.executor.timestamp,
Manifest: s.executor.manifest,
CompatSetParent: s.executor.compatSetParent,
}
imgID, _, manifestDigest, err := s.builder.Commit(ctx, imageRef, options)
if err != nil {