mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Merge pull request #20657 from nalind/commit-config
RHEL-14922: accept a config blob alongside the "changes" slice when committing
This commit is contained in:
@ -20,16 +20,16 @@ import (
|
||||
|
||||
// ContainerCommitOptions is a struct used to commit a container to an image
|
||||
// It uses buildah's CommitOptions as a base. Long-term we might wish to
|
||||
// add these to the buildah struct once buildah is more integrated with
|
||||
// libpod
|
||||
// decouple these because it includes duplicates of fields that are in, or
|
||||
// could later be added, to buildah's CommitOptions, which gets confusing
|
||||
type ContainerCommitOptions struct {
|
||||
buildah.CommitOptions
|
||||
Pause bool
|
||||
IncludeVolumes bool
|
||||
Author string
|
||||
Message string
|
||||
Changes []string
|
||||
Squash bool
|
||||
Changes []string // gets merged with CommitOptions.OverrideChanges
|
||||
Squash bool // always used instead of CommitOptions.Squash
|
||||
}
|
||||
|
||||
// Commit commits the changes between a container and its image, creating a new
|
||||
@ -69,6 +69,8 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
|
||||
Squash: options.Squash,
|
||||
SystemContext: c.runtime.imageContext,
|
||||
PreferredManifestType: options.PreferredManifestType,
|
||||
OverrideChanges: append(append([]string{}, options.Changes...), options.CommitOptions.OverrideChanges...),
|
||||
OverrideConfig: options.CommitOptions.OverrideConfig,
|
||||
}
|
||||
importBuilder, err := buildah.ImportBuilder(ctx, c.runtime.store, builderOptions)
|
||||
importBuilder.Format = options.PreferredManifestType
|
||||
@ -150,51 +152,6 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
|
||||
// Workdir
|
||||
importBuilder.SetWorkDir(c.config.Spec.Process.Cwd)
|
||||
|
||||
// Process user changes
|
||||
newImageConfig, err := libimage.ImageConfigFromChanges(options.Changes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if newImageConfig.User != "" {
|
||||
importBuilder.SetUser(newImageConfig.User)
|
||||
}
|
||||
// EXPOSE only appends
|
||||
for port := range newImageConfig.ExposedPorts {
|
||||
importBuilder.SetPort(port)
|
||||
}
|
||||
// ENV only appends
|
||||
for _, env := range newImageConfig.Env {
|
||||
splitEnv := strings.SplitN(env, "=", 2)
|
||||
key := splitEnv[0]
|
||||
value := ""
|
||||
if len(splitEnv) == 2 {
|
||||
value = splitEnv[1]
|
||||
}
|
||||
importBuilder.SetEnv(key, value)
|
||||
}
|
||||
if newImageConfig.Entrypoint != nil {
|
||||
importBuilder.SetEntrypoint(newImageConfig.Entrypoint)
|
||||
}
|
||||
if newImageConfig.Cmd != nil {
|
||||
importBuilder.SetCmd(newImageConfig.Cmd)
|
||||
}
|
||||
// VOLUME only appends
|
||||
for vol := range newImageConfig.Volumes {
|
||||
importBuilder.AddVolume(vol)
|
||||
}
|
||||
if newImageConfig.WorkingDir != "" {
|
||||
importBuilder.SetWorkDir(newImageConfig.WorkingDir)
|
||||
}
|
||||
for k, v := range newImageConfig.Labels {
|
||||
importBuilder.SetLabel(k, v)
|
||||
}
|
||||
if newImageConfig.StopSignal != "" {
|
||||
importBuilder.SetStopSignal(newImageConfig.StopSignal)
|
||||
}
|
||||
for _, onbuild := range newImageConfig.OnBuild {
|
||||
importBuilder.SetOnBuild(onbuild)
|
||||
}
|
||||
|
||||
var commitRef types.ImageReference
|
||||
if destImage != "" {
|
||||
// Now resolve the name.
|
||||
|
Reference in New Issue
Block a user