Search in sources :

Example 6 with ImageArchiveManifestAdapter

use of io.fabric8.maven.docker.model.ImageArchiveManifestAdapter in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findEntriesByRepoTagPatternSuccessfully.

@Test
public void findEntriesByRepoTagPatternSuccessfully() {
    ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
    Map<String, ImageArchiveManifestEntry> entries;
    // Complete match
    entries = ImageArchiveUtil.findEntriesByRepoTagPattern("test/image:latest", nonEmpty);
    Assert.assertNotNull(entries);
    Assert.assertNotNull(entries.get("test/image:latest"));
    Assert.assertTrue(entries.get("test/image:latest").getRepoTags().contains("test/image:latest"));
    // Unanchored match
    entries = ImageArchiveUtil.findEntriesByRepoTagPattern("test/image", nonEmpty);
    Assert.assertNotNull(entries);
    Assert.assertNotNull(entries.get("test/image:latest"));
    Assert.assertTrue(entries.get("test/image:latest").getRepoTags().contains("test/image:latest"));
    // Initial anchor
    entries = ImageArchiveUtil.findEntriesByRepoTagPattern("^test/image", nonEmpty);
    Assert.assertNotNull(entries);
    Assert.assertNotNull(entries.get("test/image:latest"));
    Assert.assertTrue(entries.get("test/image:latest").getRepoTags().contains("test/image:latest"));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) ImageArchiveManifestEntry(io.fabric8.maven.docker.model.ImageArchiveManifestEntry) Test(org.junit.Test)

Example 7 with ImageArchiveManifestAdapter

use of io.fabric8.maven.docker.model.ImageArchiveManifestAdapter in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtil method readManifest.

/**
 * Read the (possibly compressed) image archive stream provided and return the archive manifest.
 *
 * If there is no manifest found, then null is returned. Incomplete manifests are returned
 * with as much information parsed as possible.
 *
 * @param inputStream
 * @return the parsed manifest, or null if none found.
 * @throws IOException
 * @throws JsonParseException
 */
public static ImageArchiveManifest readManifest(InputStream inputStream) throws IOException, JsonParseException {
    Map<String, JsonParseException> parseExceptions = new LinkedHashMap<>();
    Map<String, JsonElement> parsedEntries = new LinkedHashMap<>();
    try (TarArchiveInputStream tarStream = new TarArchiveInputStream(createUncompressedStream(inputStream))) {
        TarArchiveEntry tarEntry;
        Gson gson = new Gson();
        while ((tarEntry = tarStream.getNextTarEntry()) != null) {
            if (tarEntry.isFile() && tarEntry.getName().endsWith(".json")) {
                try {
                    JsonElement element = gson.fromJson(new InputStreamReader(tarStream, StandardCharsets.UTF_8), JsonElement.class);
                    parsedEntries.put(tarEntry.getName(), element);
                } catch (JsonParseException exception) {
                    parseExceptions.put(tarEntry.getName(), exception);
                }
            }
        }
    }
    JsonElement manifestJson = parsedEntries.get(MANIFEST_JSON);
    if (manifestJson == null) {
        JsonParseException parseException = parseExceptions.get(MANIFEST_JSON);
        if (parseException != null) {
            throw parseException;
        }
        return null;
    }
    ImageArchiveManifestAdapter manifest = new ImageArchiveManifestAdapter(manifestJson);
    for (ImageArchiveManifestEntry entry : manifest.getEntries()) {
        JsonElement entryConfigJson = parsedEntries.get(entry.getConfig());
        if (entryConfigJson != null && entryConfigJson.isJsonObject()) {
            manifest.putConfig(entry.getConfig(), entryConfigJson.getAsJsonObject());
        }
    }
    return manifest;
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) JsonParseException(com.google.gson.JsonParseException) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) LinkedHashMap(java.util.LinkedHashMap) ImageArchiveManifestEntry(io.fabric8.maven.docker.model.ImageArchiveManifestEntry)

Example 8 with ImageArchiveManifestAdapter

use of io.fabric8.maven.docker.model.ImageArchiveManifestAdapter in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findByRepoTagPatternEmptyManifest.

@Test
public void findByRepoTagPatternEmptyManifest() {
    ImageArchiveManifest empty = new ImageArchiveManifestAdapter(new JsonArray());
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern(".*", empty));
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern(".*", null));
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern((String) null, null));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) JsonArray(com.google.gson.JsonArray) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 9 with ImageArchiveManifestAdapter

use of io.fabric8.maven.docker.model.ImageArchiveManifestAdapter in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findByRepoTagPatternNonEmptyManifest.

@Test
public void findByRepoTagPatternNonEmptyManifest() {
    ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern("does/not:match", nonEmpty));
    // Anchored pattern
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern("^test/image$", nonEmpty));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 10 with ImageArchiveManifestAdapter

use of io.fabric8.maven.docker.model.ImageArchiveManifestAdapter in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findByRepoTagSuccessfully.

@Test
public void findByRepoTagSuccessfully() {
    ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
    ImageArchiveManifestEntry found = ImageArchiveUtil.findEntryByRepoTag("test/image:latest", nonEmpty);
    Assert.assertNotNull(found);
    Assert.assertTrue(found.getRepoTags().contains("test/image:latest"));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) ImageArchiveManifestEntry(io.fabric8.maven.docker.model.ImageArchiveManifestEntry) Test(org.junit.Test)

Aggregations

ImageArchiveManifestAdapter (io.fabric8.maven.docker.model.ImageArchiveManifestAdapter)13 ImageArchiveManifest (io.fabric8.maven.docker.model.ImageArchiveManifest)12 Test (org.junit.Test)12 ImageArchiveManifestEntry (io.fabric8.maven.docker.model.ImageArchiveManifestEntry)7 JsonArray (com.google.gson.JsonArray)3 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonParseException (com.google.gson.JsonParseException)1 InputStreamReader (java.io.InputStreamReader)1 LinkedHashMap (java.util.LinkedHashMap)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1