mirror of
https://github.com/docker/compose.git
synced 2025-07-30 09:04:12 +02:00
Add container inspect view
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
aa09ecb1f8
commit
49759af15c
@ -20,10 +20,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/client"
|
"github.com/docker/compose-cli/api/client"
|
||||||
|
"github.com/docker/compose-cli/api/containers"
|
||||||
"github.com/docker/compose-cli/formatter"
|
"github.com/docker/compose-cli/formatter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,7 +55,9 @@ func runInspect(ctx context.Context, id string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
j, err := formatter.ToStandardJSON(container)
|
view := getInspectView(container)
|
||||||
|
|
||||||
|
j, err := formatter.ToStandardJSON(view)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -60,3 +65,71 @@ func runInspect(ctx context.Context, id string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type containerInspectView struct {
|
||||||
|
ID string
|
||||||
|
Status string
|
||||||
|
Image string
|
||||||
|
Command string `json:",omitempty"`
|
||||||
|
HostConfig *containers.HostConfig `json:",omitempty"`
|
||||||
|
Ports *[]containers.Port `json:",omitempty"`
|
||||||
|
Platform string
|
||||||
|
Healthcheck *containerInspectHealthcheck `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type containerInspectHealthcheck struct {
|
||||||
|
// Test is the command to be run to check the health of the container
|
||||||
|
Test *[]string `json:",omitempty"`
|
||||||
|
// Interval is the period in between the checks
|
||||||
|
Interval *types.Duration `json:",omitempty"`
|
||||||
|
// Retries is the number of attempts before declaring the container as healthy or unhealthy
|
||||||
|
Retries *int `json:",omitempty"`
|
||||||
|
// StartPeriod is the start delay before starting the checks
|
||||||
|
StartPeriod *types.Duration `json:",omitempty"`
|
||||||
|
// Timeout is the timeout in between checks
|
||||||
|
Timeout *types.Duration `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getInspectView(container containers.Container) containerInspectView {
|
||||||
|
var (
|
||||||
|
healthcheck *containerInspectHealthcheck
|
||||||
|
test *[]string
|
||||||
|
retries *int
|
||||||
|
ports *[]containers.Port
|
||||||
|
)
|
||||||
|
|
||||||
|
if !container.Healthcheck.Disable && len(container.Healthcheck.Test) > 0 {
|
||||||
|
test = &container.Healthcheck.Test
|
||||||
|
if container.Healthcheck.Retries != 0 {
|
||||||
|
retries = to.IntPtr(container.Healthcheck.Retries)
|
||||||
|
}
|
||||||
|
if len(container.Ports) > 0 {
|
||||||
|
ports = &container.Ports
|
||||||
|
}
|
||||||
|
getDurationPtr := func(d types.Duration) *types.Duration {
|
||||||
|
if d == types.Duration(0) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &d
|
||||||
|
}
|
||||||
|
|
||||||
|
healthcheck = &containerInspectHealthcheck{
|
||||||
|
Test: test,
|
||||||
|
Retries: retries,
|
||||||
|
Interval: getDurationPtr(container.Healthcheck.Interval),
|
||||||
|
StartPeriod: getDurationPtr(container.Healthcheck.StartPeriod),
|
||||||
|
Timeout: getDurationPtr(container.Healthcheck.Timeout),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return containerInspectView{
|
||||||
|
ID: container.ID,
|
||||||
|
Status: container.Status,
|
||||||
|
Image: container.Image,
|
||||||
|
Command: container.Command,
|
||||||
|
HostConfig: container.HostConfig,
|
||||||
|
Ports: ports,
|
||||||
|
Platform: container.Platform,
|
||||||
|
Healthcheck: healthcheck,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
15
cli/cmd/testdata/inspect-out-id.golden
vendored
15
cli/cmd/testdata/inspect-out-id.golden
vendored
@ -2,11 +2,6 @@
|
|||||||
"ID": "id",
|
"ID": "id",
|
||||||
"Status": "",
|
"Status": "",
|
||||||
"Image": "nginx",
|
"Image": "nginx",
|
||||||
"Command": "",
|
|
||||||
"CPUTime": 0,
|
|
||||||
"MemoryUsage": 0,
|
|
||||||
"PidsCurrent": 0,
|
|
||||||
"PidsLimit": 0,
|
|
||||||
"HostConfig": {
|
"HostConfig": {
|
||||||
"RestartPolicy": "none",
|
"RestartPolicy": "none",
|
||||||
"CPUReservation": 0,
|
"CPUReservation": 0,
|
||||||
@ -15,13 +10,5 @@
|
|||||||
"MemoryLimit": 0,
|
"MemoryLimit": 0,
|
||||||
"AutoRemove": false
|
"AutoRemove": false
|
||||||
},
|
},
|
||||||
"Platform": "Linux",
|
"Platform": "Linux"
|
||||||
"Healthcheck": {
|
|
||||||
"Disable": false,
|
|
||||||
"Test": null,
|
|
||||||
"Interval": "0s",
|
|
||||||
"Retries": 0,
|
|
||||||
"StartPeriod": "0s",
|
|
||||||
"Timeout": "0s"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
15
tests/e2e/testdata/inspect-id.golden
vendored
15
tests/e2e/testdata/inspect-id.golden
vendored
@ -2,11 +2,6 @@
|
|||||||
"ID": "id",
|
"ID": "id",
|
||||||
"Status": "",
|
"Status": "",
|
||||||
"Image": "nginx",
|
"Image": "nginx",
|
||||||
"Command": "",
|
|
||||||
"CPUTime": 0,
|
|
||||||
"MemoryUsage": 0,
|
|
||||||
"PidsCurrent": 0,
|
|
||||||
"PidsLimit": 0,
|
|
||||||
"HostConfig": {
|
"HostConfig": {
|
||||||
"RestartPolicy": "none",
|
"RestartPolicy": "none",
|
||||||
"CPUReservation": 0,
|
"CPUReservation": 0,
|
||||||
@ -15,13 +10,5 @@
|
|||||||
"MemoryLimit": 0,
|
"MemoryLimit": 0,
|
||||||
"AutoRemove": false
|
"AutoRemove": false
|
||||||
},
|
},
|
||||||
"Platform": "Linux",
|
"Platform": "Linux"
|
||||||
"Healthcheck": {
|
|
||||||
"Disable": false,
|
|
||||||
"Test": null,
|
|
||||||
"Interval": "0s",
|
|
||||||
"Retries": 0,
|
|
||||||
"StartPeriod": "0s",
|
|
||||||
"Timeout": "0s"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user