use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project docker-maven-plugin by fabric8io.
the class TrackArchiverCollectionTest method multipleAssemblies.
@Test
public void multipleAssemblies() throws Exception {
TrackArchiverCollection archiverCollection = new TrackArchiverCollection();
AnsiLogger logger = new AnsiLogger(new SystemStreamLog(), false, "build");
archiverCollection.init(logger, "maven");
archiverCollection.init(logger, "deps");
// Add files to "maven" assembly
MappingTrackArchiver mavenArchiver = archiverCollection.get("maven");
mavenArchiver.setDestFile(new File("target/test-data/maven.tracker"));
new File(mavenArchiver.getDestFile(), "maven").mkdirs();
File tempFile = File.createTempFile("tracker", "txt");
File destination = new File("target/test-data/maven/test.txt");
org.codehaus.plexus.util.FileUtils.copyFile(tempFile, destination);
// Add files to "deps" assembly
MappingTrackArchiver depsArchiver = archiverCollection.get("deps");
depsArchiver.setDestFile(new File("target/test-data/deps.tracker"));
new File(mavenArchiver.getDestFile(), "deps").mkdirs();
File tempFile2 = File.createTempFile("tracker", "txt");
File destination2 = new File("target/test-data/deps/deps.txt");
org.codehaus.plexus.util.FileUtils.copyFile(tempFile2, destination2);
mavenArchiver.addFile(tempFile, "test.txt");
depsArchiver.addFile(tempFile2, "deps.txt");
// Verify tracking of files in "maven" assembly
AssemblyFiles files = archiverCollection.getAssemblyFiles(session, "maven");
assertNotNull(files);
List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
assertEquals(0, entries.size());
FileUtils.touch(tempFile);
entries = files.getUpdatedEntriesAndRefresh();
assertEquals(1, entries.size());
AssemblyFiles.Entry entry = entries.get(0);
assertEquals(tempFile, entry.getSrcFile());
assertEquals(destination, entry.getDestFile());
// Verify tracking of files in "deps" assembly
AssemblyFiles deps = archiverCollection.getAssemblyFiles(session, "deps");
assertNotNull(deps);
entries = deps.getUpdatedEntriesAndRefresh();
assertEquals(0, entries.size());
FileUtils.touch(tempFile2);
entries = deps.getUpdatedEntriesAndRefresh();
assertEquals(1, entries.size());
entry = entries.get(0);
assertEquals(tempFile2, entry.getSrcFile());
assertEquals(destination2, entry.getDestFile());
// Verify that updating a file in "deps" doesn't pollute "maven"
entries = files.getUpdatedEntriesAndRefresh();
assertEquals(0, entries.size());
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtil method findEntriesByRepoTagPattern.
/**
* Search the manifest for an entry that has a repository and tag matching the provided pattern.
*
* @param repoTagPattern the repository and tag to search (e.g. busybox:latest).
* @param manifest the manifest to be searched
* @return a pair containing the matched tag and the entry found, or null if no match.
*/
public static Map<String, ImageArchiveManifestEntry> findEntriesByRepoTagPattern(Pattern repoTagPattern, ImageArchiveManifest manifest) throws PatternSyntaxException {
Map<String, ImageArchiveManifestEntry> entries = new LinkedHashMap<>();
if (repoTagPattern == null || manifest == null) {
return entries;
}
Matcher matcher = repoTagPattern.matcher("");
for (ImageArchiveManifestEntry entry : manifest.getEntries()) {
for (String entryRepoTag : entry.getRepoTags()) {
if (matcher.reset(entryRepoTag).find()) {
entries.putIfAbsent(entryRepoTag, entry);
}
}
}
return entries;
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project docker-maven-plugin by fabric8io.
the class StartContainerExecutor method queryContainerProperties.
public Properties queryContainerProperties(String containerId) throws DockerAccessException {
String propKey = getExposedPropertyKeyPart();
Properties exposedProperties = new Properties();
if (StringUtils.isNotEmpty(exposeContainerProps) && StringUtils.isNotEmpty(propKey)) {
Container container = hub.getQueryService().getMandatoryContainer(containerId);
String prefix = addDot(exposeContainerProps) + addDot(propKey);
exposedProperties.put(prefix + "id", containerId);
String ip = container.getIPAddress();
if (StringUtils.isNotEmpty(ip)) {
exposedProperties.put(prefix + "ip", ip);
}
Map<String, String> nets = container.getCustomNetworkIpAddresses();
if (nets != null) {
for (Map.Entry<String, String> entry : nets.entrySet()) {
exposedProperties.put(prefix + addDot("net") + addDot(entry.getKey()) + "ip", entry.getValue());
}
}
}
return exposedProperties;
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project docker-maven-plugin by fabric8io.
the class DockerComposeServiceWrapper method getNetworkConfig.
NetworkConfig getNetworkConfig() {
String net = asString("network_mode");
if (net != null) {
return new NetworkConfig(net);
}
Object networks = asObject("networks");
if (networks == null) {
return null;
}
if (networks instanceof List) {
List<String> toJoin = (List<String>) networks;
if (toJoin.size() > 1) {
throwIllegalArgumentException("'networks:' Only one custom network to join is supported currently");
}
return new NetworkConfig(NetworkConfig.Mode.custom, toJoin.get(0));
} else if (networks instanceof Map) {
Map<String, Object> toJoin = (Map<String, Object>) networks;
if (toJoin.size() > 1) {
throwIllegalArgumentException("'networks:' Only one custom network to join is supported currently");
}
String custom = toJoin.keySet().iterator().next();
NetworkConfig ret = new NetworkConfig(NetworkConfig.Mode.custom, custom);
Object aliases = toJoin.get(custom);
if (aliases != null) {
if (aliases instanceof List) {
for (String alias : (List<String>) aliases) {
ret.addAlias(alias);
}
} else if (aliases instanceof Map) {
Map<String, List<String>> map = (Map<String, List<String>>) aliases;
if (map.containsKey("aliases")) {
for (String alias : map.get("aliases")) {
ret.addAlias(alias);
}
} else {
throwIllegalArgumentException("'networks:' Aliases must be given as a map of strings. 'aliases' key not founded");
}
} else {
throwIllegalArgumentException("'networks:' No aliases entry found in network config map");
}
}
return ret;
} else {
throwIllegalArgumentException("'networks:' must beu either a list or a map");
return null;
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project docker-maven-plugin by fabric8io.
the class CopyConfigurationTest method entries.
private List<Entry> entries() {
final List<Entry> entries = new ArrayList<>();
entries.add(new Entry("container1", "host1"));
entries.add(new Entry("container2", "host2"));
entries.add(new Entry("container3", null));
return entries;
}
Aggregations