daemon.CreateImageFromContainer() already constructs a new config by taking
the image config, applying custom options (`docker commit --change ..`) (if
any), and merging those with the containers' configuration, so there is
no need to merge options again.
https://github.com/moby/moby/blob/e22758bfb2d615f67512336f121c677d099b3269/daemon/commit.go#L152-L158
This patch removes the merge logic from generateCommitImageConfig, and
removes the unused arguments and error-return.
Co-authored-by: Djordje Lukic <djordje.lukic@docker.com>
Co-authored-by: Laura Brehm <laurabrehm@hey.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -19,7 +19,6 @@ import ( |
| 19 | 19 |
"github.com/containerd/containerd/rootfs" |
| 20 | 20 |
"github.com/containerd/containerd/snapshots" |
| 21 | 21 |
"github.com/docker/docker/api/types/backend" |
| 22 |
- containerapi "github.com/docker/docker/api/types/container" |
|
| 23 | 22 |
"github.com/docker/docker/errdefs" |
| 24 | 23 |
"github.com/docker/docker/image" |
| 25 | 24 |
"github.com/opencontainers/go-digest" |
| ... | ... |
@@ -81,10 +80,7 @@ func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig) |
| 81 | 81 |
return "", fmt.Errorf("failed to export layer: %w", err)
|
| 82 | 82 |
} |
| 83 | 83 |
|
| 84 |
- imageConfig, err := generateCommitImageConfig(ctx, container.Config, ociimage, diffID, cc) |
|
| 85 |
- if err != nil {
|
|
| 86 |
- return "", fmt.Errorf("failed to generate commit image config: %w", err)
|
|
| 87 |
- } |
|
| 84 |
+ imageConfig := generateCommitImageConfig(ociimage, diffID, cc) |
|
| 88 | 85 |
|
| 89 | 86 |
rootfsID := identity.ChainID(imageConfig.RootFS.DiffIDs).String() |
| 90 | 87 |
if err := applyDiffLayer(ctx, rootfsID, ociimage, sn, differ, diffLayerDesc); err != nil {
|
| ... | ... |
@@ -116,14 +112,9 @@ func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig) |
| 116 | 116 |
return image.ID(img.Target.Digest), nil |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 |
-// generateCommitImageConfig returns commit oci image config based on the container's image. |
|
| 120 |
-func generateCommitImageConfig(ctx context.Context, container *containerapi.Config, baseConfig ocispec.Image, diffID digest.Digest, opts backend.CommitConfig) (ocispec.Image, error) {
|
|
| 121 |
- if opts.Config.Cmd != nil {
|
|
| 122 |
- baseConfig.Config.Cmd = opts.Config.Cmd |
|
| 123 |
- } |
|
| 124 |
- if opts.Config.Entrypoint != nil {
|
|
| 125 |
- baseConfig.Config.Entrypoint = opts.Config.Entrypoint |
|
| 126 |
- } |
|
| 119 |
+// generateCommitImageConfig generates an OCI Image config based on the |
|
| 120 |
+// container's image and the CommitConfig options. |
|
| 121 |
+func generateCommitImageConfig(baseConfig ocispec.Image, diffID digest.Digest, opts backend.CommitConfig) ocispec.Image {
|
|
| 127 | 122 |
if opts.Author == "" {
|
| 128 | 123 |
opts.Author = baseConfig.Author |
| 129 | 124 |
} |
| ... | ... |
@@ -145,7 +136,7 @@ func generateCommitImageConfig(ctx context.Context, container *containerapi.Conf |
| 145 | 145 |
OS: os, |
| 146 | 146 |
Created: &createdTime, |
| 147 | 147 |
Author: opts.Author, |
| 148 |
- Config: baseConfig.Config, |
|
| 148 |
+ Config: containerConfigToOciImageConfig(opts.Config), |
|
| 149 | 149 |
RootFS: ocispec.RootFS{
|
| 150 | 150 |
Type: "layers", |
| 151 | 151 |
DiffIDs: append(baseConfig.RootFS.DiffIDs, diffID), |
| ... | ... |
@@ -157,7 +148,7 @@ func generateCommitImageConfig(ctx context.Context, container *containerapi.Conf |
| 157 | 157 |
Comment: opts.Comment, |
| 158 | 158 |
EmptyLayer: diffID == "", |
| 159 | 159 |
}), |
| 160 |
- }, nil |
|
| 160 |
+ } |
|
| 161 | 161 |
} |
| 162 | 162 |
|
| 163 | 163 |
// writeContentsForImage will commit oci image config and manifest into containerd's content store. |