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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user