Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): find volumes that have no compose labels (#3586)

Hampus421981e7dff6
diff --git a/fluxer_rexctl/cmd/backup.go b/fluxer_rexctl/cmd/backup.go
index 0093d7d77..de3cef603 100644
--- a/fluxer_rexctl/cmd/backup.go
+++ b/fluxer_rexctl/cmd/backup.go
@@ -183,6 +183,7 @@ func warnBackupSkipped(app *App, m *backup.Manifest) {
func backupCreateErr(err error) error {
var ee *ui.ExitError
var disk *backup.DiskError
+ var missing *backup.MissingDataError
var dump *backup.DumpError
var stopped *backup.InterruptedError
switch {
@@ -192,6 +193,11 @@ func backupCreateErr(err error) error {
return err
case errors.Is(err, backup.ErrNeverStarted):
return ui.Refused("Fluxer hasn't started on this machine yet, and there's nothing to back up.", "Run rexctl start, then run rexctl backup.")
+ case errors.As(err, &missing):
+ return ui.Failed(
+ fmt.Sprintf("rexctl can't find your database data. It looked for the Docker volume %s and for a bind mount on the postgres service.", missing.Volume),
+ "Run docker volume ls to see your volumes, then run rexctl backup again.",
+ )
case errors.As(err, &disk):
return ui.Failed(
fmt.Sprintf("There isn't enough free space for a backup. It needs about %s and %s is free.", ui.Bytes(int64(disk.Need)), ui.Bytes(int64(disk.Available))),
diff --git a/fluxer_rexctl/internal/backup/create.go b/fluxer_rexctl/internal/backup/create.go
index af584f0b7..80a7b1518 100644
--- a/fluxer_rexctl/internal/backup/create.go
+++ b/fluxer_rexctl/internal/backup/create.go
@@ -44,6 +44,14 @@ type CreateOptions struct {
OnEvent func(engine.Event)
}
+type MissingDataError struct {
+ Volume string
+}
+
+func (e *MissingDataError) Error() string {
+ return fmt.Sprintf("backup: no database data found in volume %s or a bind mount", e.Volume)
+}
+
type DiskError struct {
Dir string
Need uint64
@@ -118,6 +126,9 @@ func Create(ctx context.Context, inst *instance.Instance, p *engine.Project, opt
return nil, err
}
if _, ok := dataVolume(model, p.Name, have, "postgres-data"); !ok {
+ if ps, err := p.PS(ctx); err == nil && len(ps) > 0 {
+ return nil, &MissingDataError{Volume: p.Name + "_postgres-data"}
+ }
return nil, ErrNeverStarted
}
}
diff --git a/fluxer_rexctl/internal/engine/plan.go b/fluxer_rexctl/internal/engine/plan.go
index 8d5aa1782..7f22950b0 100644
--- a/fluxer_rexctl/internal/engine/plan.go
+++ b/fluxer_rexctl/internal/engine/plan.go
@@ -162,7 +162,7 @@ func (p *Project) planVolumes(ctx context.Context, plan *Plan) error {
if err != nil {
return err
}
- res, err := c.VolumeList(ctx, client.VolumeListOptions{Filters: projectFilter(p.Name)})
+ items, err := projectVolumes(ctx, c, p.Name)
if err != nil {
return &Error{Op: "plan", Class: ClassOf(err), Err: err}
}
@@ -171,7 +171,7 @@ func (p *Project) planVolumes(ctx context.Context, plan *Plan) error {
if want.External {
continue
}
- for _, v := range res.Items {
+ for _, v := range items {
if v.Labels[api.VolumeLabel] != key && v.Name != want.Name {
continue
}
diff --git a/fluxer_rexctl/internal/engine/ps.go b/fluxer_rexctl/internal/engine/ps.go
index f18d8096a..4a117f560 100644
--- a/fluxer_rexctl/internal/engine/ps.go
+++ b/fluxer_rexctl/internal/engine/ps.go
@@ -14,6 +14,7 @@ import (
"github.com/distribution/reference"
"github.com/docker/compose/v5/pkg/api"
"github.com/moby/moby/api/types/container"
+ "github.com/moby/moby/api/types/volume"
"github.com/moby/moby/client"
)
@@ -109,16 +110,12 @@ func (e *Engine) Volumes(ctx context.Context, project string) ([]Volume, error)
if err != nil {
return nil, err
}
- opts := client.VolumeListOptions{}
- if project != "" {
- opts.Filters = projectFilter(project)
- }
- res, err := c.VolumeList(ctx, opts)
+ items, err := projectVolumes(ctx, c, project)
if err != nil {
return nil, &Error{Op: "volumes", Class: ClassOf(err), Err: err}
}
- out := make([]Volume, 0, len(res.Items))
- for _, v := range res.Items {
+ out := make([]Volume, 0, len(items))
+ for _, v := range items {
labels := v.Labels
if labels == nil {
labels = map[string]string{}
@@ -129,6 +126,28 @@ func (e *Engine) Volumes(ctx context.Context, project string) ([]Volume, error)
return out, nil
}
+func projectVolumes(ctx context.Context, c client.APIClient, project string) ([]volume.Volume, error) {
+ if project == "" {
+ res, err := c.VolumeList(ctx, client.VolumeListOptions{})
+ return res.Items, err
+ }
+ res, err := c.VolumeList(ctx, client.VolumeListOptions{Filters: projectFilter(project)})
+ if err != nil {
+ return nil, err
+ }
+ named, err := c.VolumeList(ctx, client.VolumeListOptions{Filters: make(client.Filters).Add("name", project+"_")})
+ if err != nil {
+ return nil, err
+ }
+ items := res.Items
+ for _, v := range named.Items {
+ if v.Labels[api.ProjectLabel] == "" && strings.HasPrefix(v.Name, project+"_") {
+ items = append(items, v)
+ }
+ }
+ return items, nil
+}
+
func (e *Engine) Projects(ctx context.Context) ([]ProjectInfo, error) {
c, err := e.conn()
if err != nil {