Search in sources :

Example 46 with Entry

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());
}
Also used : SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) AnsiLogger(io.fabric8.maven.docker.util.AnsiLogger) File(java.io.File) Test(org.junit.Test)

Example 47 with Entry

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;
}
Also used : Matcher(java.util.regex.Matcher) ImageArchiveManifestEntry(io.fabric8.maven.docker.model.ImageArchiveManifestEntry) LinkedHashMap(java.util.LinkedHashMap)

Example 48 with Entry

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;
}
Also used : Container(io.fabric8.maven.docker.model.Container) Properties(java.util.Properties) Map(java.util.Map)

Example 49 with Entry

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;
    }
}
Also used : NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 50 with Entry

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;
}
Also used : Entry(io.fabric8.maven.docker.config.CopyConfiguration.Entry) ArrayList(java.util.ArrayList)

Aggregations

Map (java.util.Map)89 HashMap (java.util.HashMap)57 IOException (java.io.IOException)31 File (java.io.File)30 ArrayList (java.util.ArrayList)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)16 List (java.util.List)14 Properties (java.util.Properties)14 HashSet (java.util.HashSet)10 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)9 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)9 Test (org.junit.Test)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 LinkedHashMap (java.util.LinkedHashMap)8 TreeMap (java.util.TreeMap)8 Resource (io.fabric8.kubernetes.client.dsl.Resource)7 FileInputStream (java.io.FileInputStream)7 Set (java.util.Set)7 Profile (io.fabric8.api.Profile)6 ProfileService (io.fabric8.api.ProfileService)5