feat: Allow to match containers against truncated ID (#160)

This commit is contained in:
Anton Ovchinnikov
2025-10-28 18:44:04 +01:00
committed by GitHub
parent 3b4bcb7932
commit 6af7a9861d
2 changed files with 9 additions and 4 deletions
+6 -1
View File
@@ -10,6 +10,7 @@ import (
"github.com/docker/compose/v2/pkg/progress"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stringid"
"github.com/psviderski/uncloud/internal/docker"
machinedocker "github.com/psviderski/uncloud/internal/machine/docker"
"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.
// containerNameOrID can be name, ID, or truncated ID of the container.
func (cli *Client) InspectContainer(
ctx context.Context, serviceNameOrID, containerNameOrID string,
) (api.MachineServiceContainer, error) {
@@ -207,8 +209,11 @@ func (cli *Client) InspectContainer(
return api.MachineServiceContainer{}, fmt.Errorf("inspect service: %w", err)
}
// TODO: support matching by any prefix of the container ID
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
}
}