-
Notifications
You must be signed in to change notification settings - Fork 18.8k
image-inspect: remove Config fields that are not part of the image #48457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Keeping this in draft for now; it looks like the image-spec types use |
// FIXME(thaJeztah): this is a copy of dockerOCIImageConfigToContainerConfig in daemon/containerd: https://github.com/moby/moby/blob/6b617699c500522aa6526cfcae4558333911b11f/daemon/containerd/imagespec.go#L107-L128 | ||
func dockerOCIImageConfigToContainerConfig(cfg dockerspec.DockerOCIImageConfig) *container.Config { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from
moby/daemon/containerd/imagespec.go
Lines 107 to 128 in 6b61769
func dockerOCIImageConfigToContainerConfig(cfg imagespec.DockerOCIImageConfig) *container.Config { | |
exposedPorts := make(nat.PortSet, len(cfg.ExposedPorts)) | |
for k, v := range cfg.ExposedPorts { | |
exposedPorts[nat.Port(k)] = v | |
} | |
return &container.Config{ | |
Entrypoint: cfg.Entrypoint, | |
Env: cfg.Env, | |
Cmd: cfg.Cmd, | |
User: cfg.User, | |
WorkingDir: cfg.WorkingDir, | |
ExposedPorts: exposedPorts, | |
Volumes: cfg.Volumes, | |
Labels: cfg.Labels, | |
ArgsEscaped: cfg.ArgsEscaped, //nolint:staticcheck // Ignore SA1019. Need to keep it in image. | |
StopSignal: cfg.StopSignal, | |
Healthcheck: cfg.Healthcheck, | |
OnBuild: cfg.OnBuild, | |
Shell: cfg.Shell, | |
} | |
} |
We should probably look at moving that to an internal/
package so that we can re-use those functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even move it to https://github.com/moby/docker-image-spec? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but that would require a docker-specific type to be imported there, so probably won't work.
@@ -53,6 +53,7 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, _ backe | |||
layers = append(layers, l.String()) | |||
} | |||
|
|||
imgConfig := containerConfigToDockerOCIImageConfig(img.Config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wondering if we should consider (and if it'd be possible) to change the image-type we store on disk to use the new type so that we don't have to perform conversion (other than when committing a container to an image)
Looks like docker-py may need an update, as I think it's checking for an empty
edit: hm.. not sure now; it's edit2: ah; It's building the first target, which doesn't have |
3df5ef6
to
6feb664
Compare
6feb664
to
c6e7214
Compare
c6e7214
to
4b7dd37
Compare
hack/make/test-docker-py
Outdated
@@ -22,6 +22,9 @@ if [ -n "$TEST_INTEGRATION_USE_SNAPSHOTTER" ]; then | |||
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_build_test.py::BuildTest::test_build_squash" | |||
fi | |||
|
|||
# TODO(thaJeztah) re-enable after https://github.com/docker/docker-py/pull/3336 is in the DOCKER_PY_COMMIT release. | |||
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_build_test.pyy::BuildTest::test_build_container_with_target" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arf;
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_build_test.pyy::BuildTest::test_build_container_with_target" | |
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_build_test.py::BuildTest::test_build_container_with_target" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of skipping, let's just pull docker-py by commit?
Line 8 in 04d3817
: "${DOCKER_PY_COMMIT:=7.1.0}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's a bunch of other tests that are also waiting for a new release; didn't want to include all of those in this PR (and ideally, look if we can have a new release of docker-py); let me keep that for a follow-up.
Mostly dusted-off this PR because we kept on forgetting about it 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, fixed the typo for now 👍
4b7dd37
to
9da4321
Compare
Looks like test is failing:
|
Heh. Looks like that test piggy-backed on the moby/integration-cli/docker_cli_by_digest_test.go Lines 188 to 189 in f4ffeb8
|
9da4321
to
505bd61
Compare
// verify the build was ok | ||
res := inspectField(c, name, "Config.Cmd") | ||
assert.Equal(c, res, `[/bin/echo Hello World]`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to a sanity check that the build indeed "built" (may even be redundant)
make BIND_DIR=. TEST_FILTER='TestBuildByDigest' test-integration
...
=== RUN TestDockerRegistrySuite/TestBuildByDigest
check_test.go:468: [de4fbab56e382] daemon is not started
--- PASS: TestDockerRegistrySuite (1.80s)
--- PASS: TestDockerRegistrySuite/TestBuildByDigest (1.80s)
@@ -160,7 +160,7 @@ type ImageInspectOpts struct { | |||
type CommitConfig struct { | |||
Author string | |||
Comment string | |||
Config *container.Config | |||
Config *container.Config // TODO(thaJeztah); change this to [dockerspec.DockerOCIImageConfig] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly this would help reduce the conversion juggling - I'd have to check though exactly where this field is all used 🤔
docs/api/version-history.md
Outdated
@@ -24,6 +24,14 @@ keywords: "API, Docker, rcli, REST, documentation" | |||
* Deprecated: The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the | |||
`GET /info` response were deprecated in API v1.48, and are now omitted | |||
in API v1.50. | |||
* Deprecated: `GT /images/{name}/json` no longer returns the following `Config` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Deprecated: `GT /images/{name}/json` no longer returns the following `Config` | |
* Deprecated: `GET /images/{name}/json` no longer returns the following `Config` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
commit af0cdc3 marked these fields as deprecated and to be removed in API v1.47 (which was targeted for v28.0). We shipped v1.47 with the v27.2 release, but did not yet remove the erroneous fields, so the version to deprecate was updated to v1.48 through 3df03d8 This patch removes fields that are not part of the image by replacing the type with the Config struct from the docker image-spec. curl -s --unix-socket /var/run/docker.sock http://localhost/v1.50/images/alpine/json | jq .Config { "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh" ] } curl -s --unix-socket /var/run/docker.sock http://localhost/v1.49/images/alpine/json | jq .Config { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh" ], "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null } Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
505bd61
to
d7cca3f
Compare
Was it actually intended that This change resulted in a bug in Scuba (JonathonReinhart/scuba#262) which was essentially doing this: cp = subprocess.run("docker", "inspect", "--type", "image", image, capture=True)
info = json.loads(cp.stdout)[0]
entrypoint = info["Config"]["Entrypoint"]
# ^^^^^^^^^^^^ KeyError on docker-ce 28.2 The commit messages for 4dc961d and referenced depreciation commit af0cdc3 only talk about erroneous fields not part of the image; it is never mentioned that the behavior for actual image fields (e.g. This seems like a regression to me. Edit: This appears to apply to Without Entrypointhttps://github.com/JonathonReinhart/scuba/blob/main/test-docker-images/hello/Dockerfile FROM alpine
ADD hello.sh /hello.sh
RUN chmod 755 /hello.sh
CMD ["/hello.sh"] $ docker inspect --type image scuba/hello | jq '.[0].Config'
{
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/hello.sh"
],
"WorkingDir": "/",
"ArgsEscaped": true
} With Entrypointhttps://github.com/JonathonReinhart/scuba/blob/main/test-docker-images/entrypoint-test/Dockerfile FROM alpine:latest
COPY entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] $ docker inspect --type image scuba/entrypoint-test | jq '.[0].Config'
{
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Entrypoint": [
"/entrypoint.sh"
],
"WorkingDir": "/"
} |
@JonathonReinhart see;
Empty values will likely be omitted in future though, so In general, I'd recommend adjusting how those are handled to either unmarshal to a type on the receiving end, or to handle missing fields gracefully. Omitting the fields is a closer alignment to the OCI image specification, which also omits Config options that are not set; https://github.com/opencontainers/image-spec/blob/v1.1.1/specs-go/v1/config.go#L23-L62 |
relates to:
GET /images/{name}/json
response #47941commit af0cdc3 marked these fields as deprecated and to be removed in API v1.47 (which was targeted for v28.0). We shipped v1.47 with the v27.2 release, but did not yet remove the erroneous fields, so the version to deprecate was updated to v1.48 through 3df03d8
This patch removes fields that are not part of the image by replacing the type with the Config struct from the docker image-spec.
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)