forked from toolshed/abra
fix: select containers if we find multiple
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"github.com/docker/docker/api/types"
|
||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -37,19 +37,16 @@ var appRestartCommand = &cli.Command{
|
||||
serviceFilter := fmt.Sprintf("%s_%s", app.StackName(), serviceName)
|
||||
filters := filters.NewArgs()
|
||||
filters.Add("name", serviceFilter)
|
||||
containerOpts := types.ContainerListOptions{Filters: filters}
|
||||
containers, err := cl.ContainerList(c.Context, containerOpts)
|
||||
|
||||
targetContainer, err := containerPkg.GetContainer(c.Context, cl, filters, true)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if len(containers) != 1 {
|
||||
logrus.Fatalf("expected 1 service but got %v", len(containers))
|
||||
}
|
||||
|
||||
logrus.Debugf("attempting to restart %s", serviceFilter)
|
||||
|
||||
timeout := 30 * time.Second
|
||||
if err := cl.ContainerRestart(c.Context, containers[0].ID, &timeout); err != nil {
|
||||
if err := cl.ContainerRestart(c.Context, targetContainer.ID, &timeout); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
||||
"coopcloud.tech/abra/pkg/upstream/container"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types"
|
||||
@ -59,18 +60,11 @@ var appRunCommand = &cli.Command{
|
||||
filters := filters.NewArgs()
|
||||
filters.Add("name", stackAndServiceName)
|
||||
|
||||
containers, err := cl.ContainerList(c.Context, types.ContainerListOptions{Filters: filters})
|
||||
targetContainer, err := containerPkg.GetContainer(c.Context, cl, filters, true)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if len(containers) == 0 {
|
||||
logrus.Fatalf("no containers matching '%s' found?", stackAndServiceName)
|
||||
}
|
||||
if len(containers) > 1 {
|
||||
logrus.Fatalf("expected 1 container matching '%s' but got %d", stackAndServiceName, len(containers))
|
||||
}
|
||||
|
||||
cmd := c.Args().Slice()[2:]
|
||||
execCreateOpts := types.ExecConfig{
|
||||
AttachStderr: true,
|
||||
@ -98,7 +92,7 @@ var appRunCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := container.RunExec(dcli, cl, containers[0].ID, &execCreateOpts); err != nil {
|
||||
if err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user