Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions agent/app/service/snapshot_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"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"
Expand All @@ -23,6 +24,7 @@
"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"
)
Expand Down Expand Up @@ -353,7 +355,7 @@
return nil
}

func snapAppImage(snap snapHelper, req dto.SnapshotCreate, targetDir string) error {

Check failure on line 358 in agent/app/service/snapshot_create.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 31 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=1Panel-dev_1Panel&issues=AZq7YnqAwigPo6fBpenc&open=AZq7YnqAwigPo6fBpenc&pullRequest=11074
snap.Task.Log("---------------------- 3 / 8 ----------------------")
snap.Task.LogStart(i18n.GetMsgByKey("SnapInstallApp"))

Expand All @@ -369,9 +371,21 @@
}
}

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 {
Expand Down
Loading