feat(migrate): detect outdated containers via distrobox.version label

This commit is contained in:
Alessio Biancalana
2026-08-02 17:36:05 +02:00
parent 9b65bec2fd
commit 7ee57a7721
9 changed files with 206 additions and 41 deletions
+3
View File
@@ -75,6 +75,9 @@ func (s *spyContainerManager) InspectContainer(_ context.Context, _ string) (*co
return &containermanager.InspectResult{}, nil
}
func (s *spyContainerManager) Commit(_ context.Context, _, _ string) error { return nil }
func (s *spyContainerManager) NeedsMigration(_ context.Context, _ string) (bool, error) {
return false, nil
}
func (s *spyContainerManager) ImageExists(_ context.Context, _ string) bool {
return false
}
+15 -2
View File
@@ -20,6 +20,11 @@ type migrateSpyContainerManager struct {
commits []string
inspectResult *containermanager.InspectResult
// needsMigrationResult, when non-nil, overrides the default return
// of NeedsMigration. The default is true (migrate), matching a v1
// container with no version label.
needsMigrationResult *bool
}
func (s *migrateSpyContainerManager) Name() string { return "spy" }
@@ -57,6 +62,12 @@ func (s *migrateSpyContainerManager) ImageExists(_ context.Context, _ string) bo
func (s *migrateSpyContainerManager) PullImage(_ context.Context, _ string, _ string, _ bool) error {
return nil
}
func (s *migrateSpyContainerManager) NeedsMigration(_ context.Context, _ string) (bool, error) {
if s.needsMigrationResult != nil {
return *s.needsMigrationResult, nil
}
return true, nil
}
// runMigrate runs the migrate subcommand with the given argv (starting from
// "migrate") against a spy container manager. It returns the spy so the
@@ -178,6 +189,7 @@ func TestMigrateAction_V2Container_Skipped(t *testing.T) {
v2ScriptDir := t.TempDir()
t.Setenv("DBX_SCRIPTS_DIR", v2ScriptDir)
notNeeded := false
spy := &migrateSpyContainerManager{
inspectResult: &containermanager.InspectResult{
ContainerID: "abc123",
@@ -187,10 +199,11 @@ func TestMigrateAction_V2Container_Skipped(t *testing.T) {
IpcMode: "host",
PidMode: "host",
Env: []string{"HOME=/home/testuser"},
Mounts: []containermanager.MountInfo{
{Source: v2ScriptDir + "/distrobox-init", Destination: "/usr/bin/entrypoint"},
Labels: map[string]string{
containermanager.VersionLabelKey: "2",
},
},
needsMigrationResult: &notNeeded,
}
runMigrate(t, spy, "migrate", "my-box")