mirror of
https://github.com/containers/podman.git
synced 2025-08-24 01:50:58 +08:00
Accept a config blob alongside the "changes" slice when committing
When committing containers to create new images, accept a container config blob being passed in the body of the API request by adding a Config field to our API structures. Populate it from the body of requests that we receive, and use its contents as the body of requests that we make. Make the libpod commit endpoint split changes values at newlines, just like the compat endpoint does. Pass both the config blob and the "changes" slice to buildah's Commit() API, so that it can handle cases where they overlap or conflict. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
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