mirror of
https://github.com/89luca89/distrobox.git
synced 2026-08-17 16:34:42 -05:00
feat(migrate): detect outdated containers via distrobox.version label
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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: ¬Needed,
|
||||
}
|
||||
|
||||
runMigrate(t, spy, "migrate", "my-box")
|
||||
|
||||
Reference in New Issue
Block a user