feat: polish release v2 experience (#6800)

This commit is contained in:
Thomas authored and GitHub committed 2026-09-07 19:17:37 +02:00
1 parent 925b0fb801
commit a4a903d7c3
295 files changed
+10627 -7115

No files matched your search

+1
View File
@@ -58,6 +58,7 @@ homarr build --pr <number> Build a PR locally from a temporary checkout
homarr rebuild <name> Rebuild from recorded provenance
homarr images List local images with build provenance
homarr data List instance data volumes
homarr data rm <volume> Preview permanent data deletion; add --force to confirm
homarr prune Remove stopped instances
homarr list Script-friendly instance list
homarr logs <container> Follow logs
+88 -7
View File
@@ -95,6 +95,7 @@ func (a *App) imagesCommand() *cobra.Command {
}
func (a *App) dataCommand() *cobra.Command {
var force bool
data := &cobra.Command{
Use: "data",
Aliases: []string{"volumes", "volume"},
@@ -124,27 +125,107 @@ func (a *App) dataCommand() *cobra.Command {
return writer.Flush()
},
}
data.AddCommand(&cobra.Command{
remove := &cobra.Command{
Use: "rm <volume>...",
Aliases: []string{"remove", "delete"},
Short: "Delete instance data, removing the owning container first",
Short: "Preview instance data deletion; use --force to apply",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
for _, name := range args {
ctx := cmd.Context()
available, err := docker.ListVolumes(ctx, false)
if err != nil {
return err
}
requested, err := selectRequestedVolumes(available, args)
if err != nil {
return err
}
if !force {
fmt.Printf("Would permanently delete %d Homarr data volume(s) and remove their owning containers:\n", len(requested))
for _, volume := range requested {
owner, err := volumeOwnerContainer(volume.Name)
if err != nil {
return err
}
fmt.Printf(" %s (container: %s)\n", volume.Name, owner)
}
fmt.Println("\nRe-run with --force to delete this data.")
return nil
}
for _, volume := range requested {
// Docker refuses to delete an attached volume, and the data is
// going away regardless, so the container goes first.
_ = docker.Remove(strings.TrimSuffix(name, "_data"))
if err := docker.RemoveVolume(cmd.Context(), name); err != nil {
owner, err := volumeOwnerContainer(volume.Name)
if err != nil {
return err
}
fmt.Println("removed " + name)
containerID, mountsVolume, err := docker.InspectContainerVolumeMount(ctx, owner, volume.Name)
if err != nil && !docker.IsContainerNotFound(err) {
return fmt.Errorf("verify owning container %s: %w", owner, err)
}
if err == nil {
if !mountsVolume {
return fmt.Errorf("refusing to remove container %s: it does not mount volume %s", owner, volume.Name)
}
if err := docker.RemoveContext(ctx, containerID); err != nil && !docker.IsContainerNotFound(err) {
return fmt.Errorf("remove owning container %s: %w", owner, err)
}
}
if err := docker.RemoveVolume(ctx, volume.Name); err != nil {
return err
}
fmt.Println("removed " + volume.Name)
}
return nil
},
})
}
remove.Flags().BoolVarP(&force, "force", "f", false, "Permanently delete the data volumes")
data.AddCommand(remove)
return data
}
func selectRequestedVolumes(available []docker.Volume, names []string) ([]docker.Volume, error) {
availableByName := make(map[string]docker.Volume, len(available))
for _, volume := range available {
availableByName[volume.Name] = volume
}
requested := make([]docker.Volume, 0, len(names))
seen := make(map[string]bool, len(names))
for _, name := range names {
if seen[name] {
return nil, fmt.Errorf("volume %q was requested more than once", name)
}
seen[name] = true
volume, found := availableByName[name]
if !found {
return nil, fmt.Errorf("Homarr data volume %q was not found", name)
}
if _, err := volumeOwnerContainer(volume.Name); err != nil {
return nil, err
}
requested = append(requested, volume)
}
return requested, nil
}
func volumeOwnerContainer(name string) (string, error) {
if name == "homarr" {
return "homarr", nil
}
if !strings.HasSuffix(name, "_data") {
return "", fmt.Errorf("volume %q is not a Homarr instance data volume", name)
}
owner := strings.TrimSuffix(name, "_data")
if owner == "" {
return "", fmt.Errorf("volume %q has no owning container name", name)
}
return owner, nil
}
func (a *App) pruneCommand() *cobra.Command {
var force bool
cmd := &cobra.Command{
@@ -378,6 +378,13 @@ func IsPortConflict(err error) bool {
strings.Contains(message, "failed programming external connectivity")
}
func IsContainerNotFound(err error) bool {
if err == nil {
return false
}
return strings.Contains(strings.ToLower(err.Error()), "no such container")
}
func Stop(name string) error { return StopContext(context.Background(), name) }
func Restart(name string) error { return RestartContext(context.Background(), name) }
@@ -132,6 +132,41 @@ func volumesInUse(ctx context.Context) map[string]bool {
return inUse
}
// InspectContainerVolumeMount verifies that a container with the expected owner
// name uses the selected data volume and returns its immutable ID for removal.
func InspectContainerVolumeMount(ctx context.Context, containerName, volumeName string) (string, bool, error) {
out, err := exec.CommandContext(
ctx,
"docker",
"container",
"inspect",
"--format",
`{"id":{{json .Id}},"mounts":{{json .Mounts}}}`,
containerName,
).CombinedOutput()
if err != nil {
return "", false, fmt.Errorf("inspect container %s: %w: %s", containerName, err, strings.TrimSpace(string(out)))
}
var inspected struct {
ID string `json:"id"`
Mounts []struct {
Name string `json:"Name"`
} `json:"mounts"`
}
if err := json.Unmarshal(out, &inspected); err != nil {
return "", false, fmt.Errorf("parse mounts for container %s: %w", containerName, err)
}
if inspected.ID == "" {
return "", false, fmt.Errorf("inspect container %s: Docker returned an empty container ID", containerName)
}
for _, mount := range inspected.Mounts {
if mount.Name == volumeName {
return inspected.ID, true, nil
}
}
return inspected.ID, false, nil
}
// RemoveVolume deletes a volume and the instance data it holds.
func RemoveVolume(ctx context.Context, name string) error {
out, err := exec.CommandContext(ctx, "docker", "volume", "rm", name).CombinedOutput()