fix: Fix the issue of abnormal image list retrieval in snapshots (#11074)

Refs #11030
This commit is contained in:
ssongliu 2025-11-25 22:25:18 +08:00 committed by GitHub
parent 6ddee2649d
commit ac1f49f8dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ import (
"time"
"github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/docker/docker/api/types/image"
"github.com/1Panel-dev/1Panel/agent/app/dto"
"github.com/1Panel-dev/1Panel/agent/app/model"
@ -23,6 +24,7 @@ import (
"github.com/1Panel-dev/1Panel/agent/utils/common"
"github.com/1Panel-dev/1Panel/agent/utils/controller"
"github.com/1Panel-dev/1Panel/agent/utils/copier"
"github.com/1Panel-dev/1Panel/agent/utils/docker"
"github.com/1Panel-dev/1Panel/agent/utils/files"
"gorm.io/gorm"
)
@ -369,9 +371,21 @@ func snapAppImage(snap snapHelper, req dto.SnapshotCreate, targetDir string) err
}
}
client, err := docker.NewDockerClient()
if err != nil {
snap.Task.Log("load docker client failed, skip save app images")
return nil
}
images, err := client.ImageList(context.Background(), image.ListOptions{})
if err != nil {
snap.Task.Log("list docker images failed, skip save app images")
return nil
}
var existImages []string
for _, img := range images {
existImages = append(existImages, img.RepoTags...)
}
var imageList []string
existStr, _ := cmd.RunDefaultWithStdoutBashC("docker images | awk '{print $1\":\"$2}' | grep -v REPOSITORY:TAG")
existImages := strings.Split(existStr, "\n")
for _, app := range req.AppData {
for _, item := range app.Children {
if item.Label == "appImage" && item.IsCheck {