feat: initial commit for abra app volume ls/rm
This commit is contained in:
parent
ca4001a805
commit
5663659d23
@ -29,5 +29,6 @@ scaling apps up and spinning them down.
|
|||||||
appRunCommand,
|
appRunCommand,
|
||||||
appRollbackCommand,
|
appRollbackCommand,
|
||||||
appSecretCommand,
|
appSecretCommand,
|
||||||
|
appVolumeCommand,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
120
cli/app/volume.go
Normal file
120
cli/app/volume.go
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/cli/internal"
|
||||||
|
"coopcloud.tech/abra/client"
|
||||||
|
"coopcloud.tech/abra/config"
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var appVolumeListCommand = &cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "list volumes associated with an app",
|
||||||
|
Aliases: []string{"ls"},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
appName := c.Args().First()
|
||||||
|
if appName == "" {
|
||||||
|
internal.ShowSubcommandHelpAndError(c, errors.New("No app name provided!"))
|
||||||
|
}
|
||||||
|
appFiles, err := config.LoadAppFiles("")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
host := appFiles[appName].Server
|
||||||
|
ctx := context.Background()
|
||||||
|
cl, err := client.NewClientWithContext(host)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fs := filters.NewArgs()
|
||||||
|
fs.Add("name", appName)
|
||||||
|
|
||||||
|
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||||
|
volumeList := volumeListOKBody.Volumes
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println("DRIVER\t\t\tVOLUME NAME")
|
||||||
|
for _, volume := range volumeList {
|
||||||
|
fmt.Printf("%s\t\t\t%s\n", volume.Driver, volume.Name)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var appVolumeRemoveCommand = &cli.Command{
|
||||||
|
Name: "remove",
|
||||||
|
Usage: "remove volume(s) associated with an app",
|
||||||
|
Aliases: []string{"rm", "delete"},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
internal.ForceFlag,
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
appName := c.Args().First()
|
||||||
|
if appName == "" {
|
||||||
|
internal.ShowSubcommandHelpAndError(c, errors.New("No app name provided!"))
|
||||||
|
}
|
||||||
|
appFiles, err := config.LoadAppFiles("")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
host := appFiles[appName].Server
|
||||||
|
ctx := context.Background()
|
||||||
|
cl, err := client.NewClientWithContext(host)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fs := filters.NewArgs()
|
||||||
|
fs.Add("name", appName)
|
||||||
|
|
||||||
|
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||||
|
volumeList := volumeListOKBody.Volumes
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
var volumeNames []string
|
||||||
|
for _, volume := range volumeList {
|
||||||
|
volumeNames = append(volumeNames, volume.Name)
|
||||||
|
}
|
||||||
|
var volumesToRemove []string
|
||||||
|
if !internal.Force {
|
||||||
|
volumesPrompt := &survey.MultiSelect{
|
||||||
|
Message: "Which volumes do you want to remove?",
|
||||||
|
Options: volumeNames,
|
||||||
|
Default: volumeNames,
|
||||||
|
}
|
||||||
|
if err := survey.AskOne(volumesPrompt, &volumesToRemove); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
volumesToRemove = volumeNames
|
||||||
|
}
|
||||||
|
for _, vol := range volumesToRemove {
|
||||||
|
err := cl.VolumeRemove(ctx, vol, internal.Force)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
logrus.Info(fmt.Sprintf("Volume %s removed.", vol))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var appVolumeCommand = &cli.Command{
|
||||||
|
Name: "volume",
|
||||||
|
Usage: "List or remove volumes associated with app",
|
||||||
|
ArgsUsage: "<command>",
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
appVolumeListCommand,
|
||||||
|
appVolumeRemoveCommand,
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user