-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent Compose image pre-fetching from pulling all tags when tag is …
…absent (#4538)
- Loading branch information
Showing
2 changed files
with
14 additions
and
14 deletions.
There are no files selected for viewing
24 changes: 12 additions & 12 deletions
24
core/src/main/java/org/testcontainers/containers/DockerComposeFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.File; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class DockerComposeFiles { | ||
|
||
private List<ParsedDockerComposeFile> parsedComposeFiles; | ||
private final List<ParsedDockerComposeFile> parsedComposeFiles; | ||
|
||
public DockerComposeFiles(List<File> composeFiles) { | ||
this.parsedComposeFiles = composeFiles.stream().map(ParsedDockerComposeFile::new).collect(Collectors.toList()); | ||
} | ||
|
||
public Set<String> getDependencyImages() { | ||
|
||
Map<String, Set<String>> mergedServiceNameToImageNames = mergeServiceDependencyImageNames(); | ||
|
||
return getImageNames(mergedServiceNameToImageNames); | ||
} | ||
|
||
private Map<String, Set<String>> mergeServiceDependencyImageNames() { | ||
Map<String, Set<String>> mergedServiceNameToImageNames = new HashMap(); | ||
Map<String, Set<String>> mergedServiceNameToImageNames = new HashMap<>(); | ||
for (ParsedDockerComposeFile parsedComposeFile : parsedComposeFiles) { | ||
for (Entry<String, Set<String>> entry : parsedComposeFile.getServiceNameToImageNames().entrySet()) { | ||
mergedServiceNameToImageNames.put(entry.getKey(), entry.getValue()); | ||
} | ||
mergedServiceNameToImageNames.putAll(parsedComposeFile.getServiceNameToImageNames()); | ||
} | ||
return mergedServiceNameToImageNames; | ||
} | ||
|
||
private Set<String> getImageNames(Map<String, Set<String>> serviceToImageNames) { | ||
Set<String> imageNames = new HashSet<>(); | ||
serviceToImageNames.values().stream().forEach(imageNames::addAll); | ||
return imageNames; | ||
return serviceToImageNames.values().stream() | ||
.flatMap(Collection::stream) | ||
// Pass through DockerImageName to convert image names to canonical form (e.g. making implicit latest tag explicit) | ||
.map(DockerImageName::parse) | ||
.map(DockerImageName::asCanonicalNameString) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters