From 77e96105a5cb45b4a3a33d4878296732452908ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 Nov 2023 18:41:35 +0100 Subject: [PATCH 1/2] Rename dockerManifest to dockerConfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... just because this is incorrect and confusing. Should not change behavior. Signed-off-by: Miloslav Trmač --- libimage/inspect.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libimage/inspect.go b/libimage/inspect.go index 1003b6483..7597e2cc9 100644 --- a/libimage/inspect.go +++ b/libimage/inspect.go @@ -185,16 +185,16 @@ func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageDat if err != nil { return nil, err } - var dockerManifest manifest.Schema2V1Image - if err := json.Unmarshal(rawConfig, &dockerManifest); err != nil { + var dockerConfig manifest.Schema2V1Image + if err := json.Unmarshal(rawConfig, &dockerConfig); err != nil { return nil, err } - data.Comment = dockerManifest.Comment + data.Comment = dockerConfig.Comment // NOTE: Health checks may be listed in the container config or // the config. - data.HealthCheck = dockerManifest.ContainerConfig.Healthcheck - if data.HealthCheck == nil && dockerManifest.Config != nil { - data.HealthCheck = dockerManifest.Config.Healthcheck + data.HealthCheck = dockerConfig.ContainerConfig.Healthcheck + if data.HealthCheck == nil && dockerConfig.Config != nil { + data.HealthCheck = dockerConfig.Config.Healthcheck } } From 2a7533ee5ece950f07a758f2d90c70da6d7a8b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 Nov 2023 18:43:54 +0100 Subject: [PATCH 2/2] Fix inspect of unsigned schema1 images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... by not incorrectly invoking the schema2 code; otherwise it tries to unmarshal nil as JSOn, and fails. I'm not sure whether schema1 images can contain a comment or a health check; just not crashing is an improvement. Signed-off-by: Miloslav Trmač --- libimage/inspect.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libimage/inspect.go b/libimage/inspect.go index 7597e2cc9..ed1ae719d 100644 --- a/libimage/inspect.go +++ b/libimage/inspect.go @@ -180,7 +180,7 @@ func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageDat } // Docker image - case manifest.DockerV2Schema1MediaType, manifest.DockerV2Schema2MediaType: + case manifest.DockerV2Schema2MediaType: rawConfig, err := i.rawConfigBlob(ctx) if err != nil { return nil, err @@ -196,6 +196,10 @@ func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageDat if data.HealthCheck == nil && dockerConfig.Config != nil { data.HealthCheck = dockerConfig.Config.Healthcheck } + + case manifest.DockerV2Schema1MediaType, manifest.DockerV2Schema1SignedMediaType: + // There seem to be at least _some_ images with .Healthcheck set in schema1 (possibly just as an artifact + // of testing format conversion?), so this could plausibly read these values. } if data.Annotations == nil {