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"));
}
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;
}
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));
}
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));
}
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"));
}
Aggregations