fix: more precise filtering
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Closes coop-cloud/organising#305.
This commit is contained in:
parent
338360096c
commit
6aa23a76a1
|
@ -111,7 +111,7 @@ func configureAndCp(
|
||||||
}
|
}
|
||||||
|
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("name", fmt.Sprintf("%s_%s", app.StackName(), service))
|
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), service))
|
||||||
|
|
||||||
container, err := container.GetContainer(context.Background(), cl, filters, internal.NoInput)
|
container, err := container.GetContainer(context.Background(), cl, filters, internal.NoInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -95,7 +96,8 @@ func checkErrors(c *cli.Context, cl *dockerClient.Client, app config.App) error
|
||||||
|
|
||||||
for _, service := range recipe.Config.Services {
|
for _, service := range recipe.Config.Services {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("name", service.Name)
|
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), service.Name))
|
||||||
|
|
||||||
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -29,9 +29,12 @@ var logOpts = types.ContainerLogsOptions{
|
||||||
}
|
}
|
||||||
|
|
||||||
// stackLogs lists logs for all stack services
|
// stackLogs lists logs for all stack services
|
||||||
func stackLogs(c *cli.Context, stackName string, client *dockerClient.Client) {
|
func stackLogs(c *cli.Context, app config.App, client *dockerClient.Client) {
|
||||||
filters := filters.NewArgs()
|
filters, err := app.Filters()
|
||||||
filters.Add("name", stackName)
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
serviceOpts := types.ServiceListOptions{Filters: filters}
|
serviceOpts := types.ServiceListOptions{Filters: filters}
|
||||||
services, err := client.ServiceList(context.Background(), serviceOpts)
|
services, err := client.ServiceList(context.Background(), serviceOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,7 +89,7 @@ var appLogsCommand = cli.Command{
|
||||||
serviceName := c.Args().Get(1)
|
serviceName := c.Args().Get(1)
|
||||||
if serviceName == "" {
|
if serviceName == "" {
|
||||||
logrus.Debugf("tailing logs for all %s services", app.Recipe)
|
logrus.Debugf("tailing logs for all %s services", app.Recipe)
|
||||||
stackLogs(c, app.StackName(), cl)
|
stackLogs(c, app, cl)
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("tailing logs for %s", serviceName)
|
logrus.Debugf("tailing logs for %s", serviceName)
|
||||||
if err := tailServiceLogs(c, cl, app, serviceName); err != nil {
|
if err := tailServiceLogs(c, cl, app, serviceName); err != nil {
|
||||||
|
@ -100,7 +103,8 @@ var appLogsCommand = cli.Command{
|
||||||
|
|
||||||
func tailServiceLogs(c *cli.Context, cl *dockerClient.Client, app config.App, serviceName string) error {
|
func tailServiceLogs(c *cli.Context, cl *dockerClient.Client, app config.App, serviceName string) error {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("name", fmt.Sprintf("%s_%s", app.StackName(), serviceName))
|
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), serviceName))
|
||||||
|
|
||||||
chosenService, err := service.GetService(context.Background(), cl, filters, internal.NoInput)
|
chosenService, err := service.GetService(context.Background(), cl, filters, internal.NoInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/buger/goterm"
|
"github.com/buger/goterm"
|
||||||
dockerFormatter "github.com/docker/cli/cli/command/formatter"
|
dockerFormatter "github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
|
||||||
dockerClient "github.com/docker/docker/client"
|
dockerClient "github.com/docker/docker/client"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -67,8 +66,10 @@ var appPsCommand = cli.Command{
|
||||||
|
|
||||||
// showPSOutput renders ps output.
|
// showPSOutput renders ps output.
|
||||||
func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) {
|
func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) {
|
||||||
filters := filters.NewArgs()
|
filters, err := app.Filters()
|
||||||
filters.Add("name", app.StackName())
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
@ -66,8 +65,11 @@ var appRemoveCommand = cli.Command{
|
||||||
logrus.Fatalf("%s is still deployed. Run \"abra app undeploy %s\"", app.Name, app.Name)
|
logrus.Fatalf("%s is still deployed. Run \"abra app undeploy %s\"", app.Name, app.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := filters.NewArgs()
|
fs, err := app.Filters()
|
||||||
fs.Add("name", app.StackName())
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: fs})
|
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: fs})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -59,7 +59,7 @@ var appRunCommand = cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceName := c.Args().Get(1)
|
serviceName := c.Args().Get(1)
|
||||||
stackAndServiceName := fmt.Sprintf("%s_%s", app.StackName(), serviceName)
|
stackAndServiceName := fmt.Sprintf("^%s_%s", app.StackName(), serviceName)
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("name", stackAndServiceName)
|
filters.Add("name", stackAndServiceName)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
"coopcloud.tech/abra/pkg/secret"
|
"coopcloud.tech/abra/pkg/secret"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
|
||||||
dockerClient "github.com/docker/docker/client"
|
dockerClient "github.com/docker/docker/client"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -217,8 +216,11 @@ Example:
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filters := filters.NewArgs()
|
filters, err := app.Filters()
|
||||||
filters.Add("name", app.StackName())
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: filters})
|
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: filters})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
@ -291,8 +293,11 @@ var appSecretLsCommand = cli.Command{
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filters := filters.NewArgs()
|
filters, err := app.Filters()
|
||||||
filters.Add("name", app.StackName())
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: filters})
|
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: filters})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -26,7 +26,12 @@ var appVolumeListCommand = cli.Command{
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
volumeList, err := client.GetVolumes(context.Background(), app.Server, app.StackName())
|
filters, err := app.Filters()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeList, err := client.GetVolumes(context.Background(), app.Server, filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +80,12 @@ Passing "--force/-f" will select all volumes for removal. Be careful.
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
volumeList, err := client.GetVolumes(context.Background(), app.Server, app.StackName())
|
filters, err := app.Filters()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeList, err := client.GetVolumes(context.Background(), app.Server, filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,12 @@ import (
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetVolumes(ctx context.Context, server string, appName string) ([]*types.Volume, error) {
|
func GetVolumes(ctx context.Context, server string, fs filters.Args) ([]*types.Volume, error) {
|
||||||
cl, err := New(server)
|
cl, err := New(server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := filters.NewArgs()
|
|
||||||
fs.Add("name", appName)
|
|
||||||
|
|
||||||
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||||
volumeList := volumeListOKBody.Volumes
|
volumeList := volumeListOKBody.Volumes
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
loader "coopcloud.tech/abra/pkg/upstream/stack"
|
loader "coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
composetypes "github.com/docker/cli/cli/compose/types"
|
composetypes "github.com/docker/cli/cli/compose/types"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,6 +64,29 @@ func (a App) StackName() string {
|
||||||
return stackName
|
return stackName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filters retrieves exact app filters for querying the container runtime.
|
||||||
|
func (a App) Filters() (filters.Args, error) {
|
||||||
|
filters := filters.NewArgs()
|
||||||
|
|
||||||
|
composeFiles, err := GetAppComposeFiles(a.Recipe, a.Env)
|
||||||
|
if err != nil {
|
||||||
|
return filters, err
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := stack.Deploy{Composefiles: composeFiles}
|
||||||
|
compose, err := GetAppComposeConfig(a.Recipe, opts, a.Env)
|
||||||
|
if err != nil {
|
||||||
|
return filters, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, service := range compose.Services {
|
||||||
|
filter := fmt.Sprintf("^%s_%s", a.StackName(), service.Name)
|
||||||
|
filters.Add("name", filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
return filters, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ByServer sort a slice of Apps
|
// ByServer sort a slice of Apps
|
||||||
type ByServer []App
|
type ByServer []App
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue