mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-28 12:03:33 +00:00
feat: Allow to match containers against truncated ID (#160)
This commit is contained in:
@@ -58,7 +58,7 @@ func inspect(ctx context.Context, uncli *cli.CLI, opts inspectOptions) error {
|
|||||||
machinesNamesByID[m.Machine.Id] = m.Machine.Name
|
machinesNamesByID[m.Machine.Id] = m.Machine.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("ID: %s\n", svc.ID)
|
fmt.Printf("Service ID: %s\n", svc.ID)
|
||||||
fmt.Printf("Name: %s\n", svc.Name)
|
fmt.Printf("Name: %s\n", svc.Name)
|
||||||
fmt.Printf("Mode: %s\n", svc.Mode)
|
fmt.Printf("Mode: %s\n", svc.Mode)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/docker/compose/v2/pkg/progress"
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/psviderski/uncloud/internal/docker"
|
"github.com/psviderski/uncloud/internal/docker"
|
||||||
machinedocker "github.com/psviderski/uncloud/internal/machine/docker"
|
machinedocker "github.com/psviderski/uncloud/internal/machine/docker"
|
||||||
"github.com/psviderski/uncloud/internal/secret"
|
"github.com/psviderski/uncloud/internal/secret"
|
||||||
@@ -199,6 +200,7 @@ func toPullProgressEvent(jm jsonmessage.JSONMessage) *progress.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InspectContainer returns the information about the specified container within the service.
|
// InspectContainer returns the information about the specified container within the service.
|
||||||
|
// containerNameOrID can be name, ID, or truncated ID of the container.
|
||||||
func (cli *Client) InspectContainer(
|
func (cli *Client) InspectContainer(
|
||||||
ctx context.Context, serviceNameOrID, containerNameOrID string,
|
ctx context.Context, serviceNameOrID, containerNameOrID string,
|
||||||
) (api.MachineServiceContainer, error) {
|
) (api.MachineServiceContainer, error) {
|
||||||
@@ -207,8 +209,11 @@ func (cli *Client) InspectContainer(
|
|||||||
return api.MachineServiceContainer{}, fmt.Errorf("inspect service: %w", err)
|
return api.MachineServiceContainer{}, fmt.Errorf("inspect service: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: support matching by any prefix of the container ID
|
||||||
for _, c := range svc.Containers {
|
for _, c := range svc.Containers {
|
||||||
if c.Container.ID == containerNameOrID || c.Container.Name == containerNameOrID {
|
if c.Container.ID == containerNameOrID ||
|
||||||
|
c.Container.Name == containerNameOrID ||
|
||||||
|
stringid.TruncateID(c.Container.ID) == containerNameOrID {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user