(filePath string)
| 135 | } |
| 136 | |
| 137 | func 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 | |
| 178 | func Down(filePath string) (string, error) { |
| 179 | if err := checkCmd(); err != nil { |
no test coverage detected