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

Function getComposeImagesByCommand

agent/utils/compose/compose.go:137–176  ·  view source on GitHub ↗
(filePath string)

Source from the content-addressed store, hash-verified

135}
136
137func getComposeImagesByCommand(filePath string) ([]string, error) {
138 if err := checkCmd(); err != nil {
139 return nil, err
140 }
141 base, extra := getComposeBaseCmd()
142 args := append(extra, loadFiles(filePath)...)
143 args = append(args, "config", "--format", "json", "--no-normalize")
144 stdout, err := cmd.NewCommandMgr(cmd.WithTimeout(5*time.Minute)).
145 RunWithStdout(base, args...)
146 if err != nil {
147 return nil, fmt.Errorf("run compose config --format json --no-normalize failed, std: %s, err: %v", stdout, err)
148 }
149
150 var composeConfig struct {
151 Services map[string]struct {
152 Image string `json:"image"`
153 } `json:"services"`
154 }
155 if err = json.Unmarshal([]byte(stdout), &composeConfig); err != nil {
156 return nil, fmt.Errorf("parse compose config json failed, std: %s, err: %v", stdout, err)
157 }
158
159 var images []string
160 seen := make(map[string]struct{})
161 for _, service := range composeConfig.Services {
162 image := strings.TrimSpace(service.Image)
163 if image == "" {
164 continue
165 }
166 if _, ok := seen[image]; ok {
167 continue
168 }
169 seen[image] = struct{}{}
170 images = append(images, image)
171 }
172 if len(images) == 0 {
173 return nil, errors.New("no images found from compose config json")
174 }
175 return images, nil
176}
177
178func Down(filePath string) (string, error) {
179 if err := checkCmd(); err != nil {

Callers 1

GetComposeImagesFunction · 0.85

Calls 4

checkCmdFunction · 0.85
getComposeBaseCmdFunction · 0.85
loadFilesFunction · 0.85
RunWithStdoutMethod · 0.45

Tested by

no test coverage detected