Skip to content

Commit 2c2df8f

Browse files
authored
Add docker migrate-storage-driver command (#613)
* Add `docker migrate-storage-driver` command Implement CLI for home-assistant/supervisor#6361. Without any extra argument, the command migrates to the overlayfs Containerd snapshotter, but the driver can be specified and will be validated by the Supervisor API - no need for another validation layer here. The list of driver is only used for shell completion. * Add more details to the confirmation prompt
1 parent 75e39ff commit 2c2df8f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package cmd
2+
3+
import (
4+
helper "github.com/home-assistant/cli/client"
5+
log "github.com/sirupsen/logrus"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var dockerMigrateStorageCmd = &cobra.Command{
10+
Use: "migrate-storage-driver [driver]",
11+
Short: "Migrate Docker storage driver",
12+
Long: `
13+
This command schedules a Docker storage driver migration to be performed on the
14+
next reboot. By default, it migrates to the (Containerd snapshotter) overlayfs.
15+
16+
The migration will be applied during the next system reboot. A reboot is required
17+
to complete the migration.
18+
`,
19+
Example: `
20+
ha docker migrate-storage-driver
21+
ha docker migrate-storage-driver overlayfs
22+
`,
23+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
24+
if len(args) != 0 {
25+
return nil, cobra.ShellCompDirectiveNoFileComp
26+
}
27+
return []string{"overlayfs", "overlay2"}, cobra.ShellCompDirectiveNoFileComp
28+
},
29+
Args: cobra.MaximumNArgs(1),
30+
Run: func(cmd *cobra.Command, args []string) {
31+
log.WithField("args", args).Debug("docker migrate-storage-driver")
32+
33+
section := "docker"
34+
command := "migrate-storage-driver"
35+
36+
// Default to overlayfs if no argument provided
37+
storageDriver := "overlayfs"
38+
if len(args) > 0 {
39+
storageDriver = args[0]
40+
}
41+
42+
confirmed, err := helper.AskForConfirmation(`
43+
This will schedule a Docker storage driver migration to "`+storageDriver+`".
44+
Make sure to create a full Home Assistant backup before proceeding.
45+
46+
Internet connectivity is required for re-download of all the container images
47+
and it is recommended to have at least 50% of free storage.
48+
49+
Once confirmed, the migration will be applied on the next system reboot.
50+
Are you sure you want to proceed?`, 0)
51+
52+
if err != nil {
53+
cmd.PrintErrln("Aborted:", err)
54+
ExitWithError = true
55+
return
56+
}
57+
58+
if confirmed {
59+
options := map[string]any{
60+
"storage_driver": storageDriver,
61+
}
62+
resp, err := helper.GenericJSONPost(section, command, options)
63+
if err != nil {
64+
helper.PrintError(err)
65+
ExitWithError = true
66+
} else {
67+
ExitWithError = !helper.ShowJSONResponse(resp)
68+
}
69+
} else {
70+
cmd.PrintErrln("Aborted.")
71+
ExitWithError = true
72+
}
73+
},
74+
}
75+
76+
func init() {
77+
dockerCmd.AddCommand(dockerMigrateStorageCmd)
78+
}

0 commit comments

Comments
 (0)