normalizeAndDedupeImages returns the unique set of images after normalization.
(images []string)
| 220 | |
| 221 | // normalizeAndDedupeImages returns the unique set of images after normalization. |
| 222 | func normalizeAndDedupeImages(images []string) []string { |
| 223 | seen := make(map[string]struct{}, len(images)) |
| 224 | for _, img := range images { |
| 225 | // since some references come from user input (service.image) and some |
| 226 | // come from the engine API, we standardize them, opting for the |
| 227 | // familiar name format since they'll also be displayed in the CLI |
| 228 | ref, err := reference.ParseNormalizedNamed(img) |
| 229 | if err == nil { |
| 230 | ref = reference.TagNameOnly(ref) |
| 231 | img = reference.FamiliarString(ref) |
| 232 | } |
| 233 | seen[img] = struct{}{} |
| 234 | } |
| 235 | ret := make([]string, 0, len(seen)) |
| 236 | for v := range seen { |
| 237 | ret = append(ret, v) |
| 238 | } |
| 239 | // ensure a deterministic return result - the actual ordering is not useful |
| 240 | sort.Strings(ret) |
| 241 | return ret |
| 242 | } |