MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / pullComposeImages

Function pullComposeImages

agent/utils/compose/compose.go:61–117  ·  view source on GitHub ↗
(filePath string, forcePull bool, task *task.Task)

Source from the content-addressed store, hash-verified

59}
60
61func pullComposeImages(filePath string, forcePull bool, task *task.Task) error {
62 images, err := GetComposeImages(filePath)
63 if err != nil {
64 return err
65 }
66 dockerCLi, err := docker.NewClient()
67 if err != nil {
68 return err
69 }
70 for _, image := range images {
71 if !forcePull {
72 if exist, _ := dockerCLi.ImageExists(image); exist {
73 if task != nil {
74 task.Log(i18n.GetMsgByKey("UseExistImage"))
75 }
76 continue
77 }
78 }
79
80 if task != nil {
81 task.Log(i18n.GetWithName("PullImageStart", image))
82 }
83 pullErr := error(nil)
84 if task != nil {
85 pullErr = dockerCLi.PullImageWithProcess(task, image)
86 } else {
87 pullErr = docker.PullImage(image)
88 }
89 if pullErr != nil {
90 errMsg := ""
91 errOur := pullErr.Error()
92 if errOur != "" {
93 if strings.Contains(errOur, "no such host") {
94 errMsg = i18n.GetMsgByKey("ErrNoSuchHost") + ":"
95 }
96 if strings.Contains(errOur, "Error response from daemon") {
97 errMsg = i18n.GetMsgByKey("PullImageTimeout") + ":"
98 }
99 }
100 message := errMsg + errOur
101 installErr := errors.New(message)
102 if task != nil {
103 task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), installErr)
104 }
105 if exist, _ := dockerCLi.ImageExists(image); !exist {
106 return installErr
107 }
108 if task != nil {
109 task.Log(i18n.GetMsgByKey("UseExistImage"))
110 }
111 } else if task != nil {
112 task.Log(i18n.GetMsgByKey("PullImageSuccess"))
113 }
114 }
115
116 return nil
117}
118

Callers 1

UpWithTaskFunction · 0.85

Calls 6

ImageExistsMethod · 0.95
PullImageWithProcessMethod · 0.95
GetComposeImagesFunction · 0.85
LogMethod · 0.45
ErrorMethod · 0.45
LogFailedWithErrMethod · 0.45

Tested by

no test coverage detected