From 687dbca071ef9a6f72d4474151ee674853f2ff99 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 9 Nov 2021 11:43:58 +0100 Subject: [PATCH] libimage: inspect: extract healthchecks from configs buildkit is setting the health check in the image's config while Docker and Podman set it in the image's container config. Hence, if the container config's healthcheck is nil, have a look at the config. Fixes: #containers/podman/issues/12226 Signed-off-by: Valentin Rothberg --- libimage/image_test.go | 19 +++++++++++++++++++ libimage/inspect.go | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/libimage/image_test.go b/libimage/image_test.go index bf3ea4083..51e9ae67a 100644 --- a/libimage/image_test.go +++ b/libimage/image_test.go @@ -168,6 +168,25 @@ func TestImageFunctions(t *testing.T) { require.Equal(t, image.NamesHistory(), imageData.NamesHistory, "inspect data should match") } +func TestInspectHealthcheck(t *testing.T) { + runtime, cleanup := testNewRuntime(t) + defer cleanup() + ctx := context.Background() + + imageName := "quay.io/libpod/healthcheck:config-only" + pullOptions := &PullOptions{} + pullOptions.Writer = os.Stdout + pulledImages, err := runtime.Pull(ctx, imageName, config.PullPolicyAlways, pullOptions) + require.NoError(t, err) + require.Len(t, pulledImages, 1) + image := pulledImages[0] + + // Now compare the inspect data to what we expect. + imageData, err := image.Inspect(ctx, nil) + require.NotNil(t, imageData.HealthCheck, "health check should be found in config") + require.Equal(t, []string{"CMD-SHELL", "curl -f http://localhost/ || exit 1"}, imageData.HealthCheck.Test, "health check should be found in config") +} + func TestTag(t *testing.T) { // Note: this will resolve pull from the GCR registry (see // testdata/registries.conf). diff --git a/libimage/inspect.go b/libimage/inspect.go index 007cbdd89..d44ebf46e 100644 --- a/libimage/inspect.go +++ b/libimage/inspect.go @@ -187,7 +187,12 @@ func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageDat return nil, err } data.Comment = dockerManifest.Comment + // NOTE: Health checks may be listed in the container config or + // the config. data.HealthCheck = dockerManifest.ContainerConfig.Healthcheck + if data.HealthCheck == nil { + data.HealthCheck = dockerManifest.Config.Healthcheck + } } if data.Annotations == nil {