Skip to content

Commit

Permalink
libimage: inspect: extract healthchecks from configs
Browse files Browse the repository at this point in the history
buildkit is setting the health check in image's config while Docker and
Podman set it into 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 <[email protected]>
  • Loading branch information
vrothberg committed Nov 9, 2021
1 parent ca3c041 commit a1d72f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libimage/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 5 additions & 0 deletions libimage/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a1d72f2

Please sign in to comment.