use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class ManifestPullerTest method testHandleResponse_v22ManifestListFromParentType.
@Test
public void testHandleResponse_v22ManifestListFromParentType() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
v22ManifestList.reset();
Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
ManifestAndDigest<?> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", ManifestTemplate.class).handleResponse(mockResponse);
ManifestTemplate manifestTemplate = manifestAndDigest.getManifest();
MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
Assert.assertTrue(((V22ManifestListTemplate) manifestTemplate).getManifests().size() > 0);
Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_validV22ManifestList.
@Test
public void testVerifyImageMetadata_validV22ManifestList() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest");
ImageMetadataTemplate metadata = new ImageMetadataTemplate(new V22ManifestListTemplate(), Arrays.asList(manifestAndConfig, manifestAndConfig));
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testRetrieveMetadata_v22ManifestList.
@Test
public void testRetrieveMetadata_v22ManifestList() throws IOException, URISyntaxException, CacheCorruptedException {
setupCachedMetadataV22ManifestList(cacheDirectory);
ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
MatcherAssert.assertThat(metadata.getManifestList(), CoreMatchers.instanceOf(V22ManifestListTemplate.class));
List<ManifestDescriptorTemplate> manifestDescriptors = ((V22ManifestListTemplate) metadata.getManifestList()).getManifests();
Assert.assertEquals(3, manifestDescriptors.size());
Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", manifestDescriptors.get(0).getDigest());
Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", manifestDescriptors.get(1).getDigest());
Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", manifestDescriptors.get(2).getDigest());
Assert.assertEquals(2, metadata.getManifestsAndConfigs().size());
ManifestAndConfigTemplate manifestAndConfig1 = metadata.getManifestsAndConfigs().get(0);
ManifestAndConfigTemplate manifestAndConfig2 = metadata.getManifestsAndConfigs().get(1);
V22ManifestTemplate manifest1 = (V22ManifestTemplate) manifestAndConfig1.getManifest();
V22ManifestTemplate manifest2 = (V22ManifestTemplate) manifestAndConfig2.getManifest();
Assert.assertEquals(2, manifest1.getSchemaVersion());
Assert.assertEquals(2, manifest2.getSchemaVersion());
Assert.assertEquals(1, manifest1.getLayers().size());
Assert.assertEquals(1, manifest2.getLayers().size());
Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", manifest1.getLayers().get(0).getDigest().getHash());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifest2.getLayers().get(0).getDigest().getHash());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifest1.getContainerConfiguration().getDigest().getHash());
Assert.assertEquals("2000a70a1ce8bba401c493376fdb9eb81bcf7155212f4ce4c6ff96e577718a49", manifest2.getContainerConfiguration().getDigest().getHash());
Assert.assertEquals("wasm", manifestAndConfig1.getConfig().getArchitecture());
Assert.assertEquals("wasm", manifestAndConfig2.getConfig().getArchitecture());
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by GoogleContainerTools.
the class BuildImageMojoIntegrationTest method testExecute_multiPlatformBuild.
@Test
public void testExecute_multiPlatformBuild() throws IOException, VerificationException, RegistryException {
String targetImage = "localhost:5000/multiplatform:maven" + System.nanoTime();
Verifier verifier = new Verifier(simpleTestProject.getProjectRoot().toString());
verifier.setSystemProperty("_TARGET_IMAGE", targetImage);
verifier.setSystemProperty("jib.to.auth.username", "testuser");
verifier.setSystemProperty("jib.to.auth.password", "testpassword");
verifier.setSystemProperty("sendCredentialsOverHttp", "true");
verifier.setSystemProperty("jib.allowInsecureRegistries", "true");
verifier.setAutoclean(false);
verifier.addCliOption("--file=pom-multiplatform-build.xml");
verifier.executeGoals(Arrays.asList("clean", "compile", "jib:build"));
verifier.verifyErrorFreeLog();
FailoverHttpClient httpClient = new FailoverHttpClient(true, true, ignored -> {
});
RegistryClient registryClient = RegistryClient.factory(EventHandlers.NONE, "localhost:5000", "multiplatform", httpClient).setCredential(Credential.from("testuser", "testpassword")).newRegistryClient();
registryClient.configureBasicAuth();
// manifest list by tag ":latest"
ManifestTemplate manifestList = registryClient.pullManifest("latest").getManifest();
assertThat(manifestList).isInstanceOf(V22ManifestListTemplate.class);
V22ManifestListTemplate v22ManifestList = (V22ManifestListTemplate) manifestList;
assertThat(v22ManifestList.getManifests().size()).isEqualTo(2);
ManifestDescriptorTemplate.Platform platform1 = v22ManifestList.getManifests().get(0).getPlatform();
ManifestDescriptorTemplate.Platform platform2 = v22ManifestList.getManifests().get(1).getPlatform();
assertThat(platform1.getArchitecture()).isEqualTo("arm64");
assertThat(platform1.getOs()).isEqualTo("linux");
assertThat(platform2.getArchitecture()).isEqualTo("amd64");
assertThat(platform2.getOs()).isEqualTo("linux");
// manifest list by tag ":another"
ManifestTemplate anotherManifestList = registryClient.pullManifest("another").getManifest();
assertThat(JsonTemplateMapper.toUtf8String(anotherManifestList)).isEqualTo(JsonTemplateMapper.toUtf8String(manifestList));
// Check arm64/linux container config.
List<String> arm64Digests = v22ManifestList.getDigestsForPlatform("arm64", "linux");
assertThat(arm64Digests.size()).isEqualTo(1);
String arm64Digest = arm64Digests.get(0);
ManifestTemplate arm64Manifest = registryClient.pullManifest(arm64Digest).getManifest();
assertThat(arm64Manifest).isInstanceOf(V22ManifestTemplate.class);
V22ManifestTemplate arm64V22Manifest = (V22ManifestTemplate) arm64Manifest;
DescriptorDigest arm64ConfigDigest = arm64V22Manifest.getContainerConfiguration().getDigest();
Blob arm64ConfigBlob = registryClient.pullBlob(arm64ConfigDigest, ignored -> {
}, ignored -> {
});
String arm64Config = Blobs.writeToString(arm64ConfigBlob);
assertThat(arm64Config).contains("\"architecture\":\"arm64\"");
assertThat(arm64Config).contains("\"os\":\"linux\"");
// Check amd64/linux container config.
List<String> amd64Digests = v22ManifestList.getDigestsForPlatform("amd64", "linux");
assertThat(amd64Digests.size()).isEqualTo(1);
String amd64Digest = amd64Digests.get(0);
ManifestTemplate amd64Manifest = registryClient.pullManifest(amd64Digest).getManifest();
assertThat(amd64Manifest).isInstanceOf(V22ManifestTemplate.class);
V22ManifestTemplate amd64V22Manifest = (V22ManifestTemplate) amd64Manifest;
DescriptorDigest amd64ConfigDigest = amd64V22Manifest.getContainerConfiguration().getDigest();
Blob amd64ConfigBlob = registryClient.pullBlob(amd64ConfigDigest, ignored -> {
}, ignored -> {
});
String amd64Config = Blobs.writeToString(amd64ConfigBlob);
assertThat(amd64Config).contains("\"architecture\":\"amd64\"");
assertThat(amd64Config).contains("\"os\":\"linux\"");
}
use of com.google.cloud.tools.jib.image.json.V22ManifestListTemplate in project jib by google.
the class JibIntegrationTest method testScratch_multiPlatform.
@Test
public void testScratch_multiPlatform() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException {
Jib.fromScratch().setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))).containerize(Containerizer.to(RegistryImage.named("localhost:5000/jib-scratch:multi-platform")).setAllowInsecureRegistries(true));
V22ManifestListTemplate manifestList = (V22ManifestListTemplate) registryClient.pullManifest("multi-platform").getManifest();
Assert.assertEquals(2, manifestList.getManifests().size());
ManifestDescriptorTemplate.Platform platform1 = manifestList.getManifests().get(0).getPlatform();
ManifestDescriptorTemplate.Platform platform2 = manifestList.getManifests().get(1).getPlatform();
Assert.assertEquals("arm64", platform1.getArchitecture());
Assert.assertEquals("windows", platform1.getOs());
Assert.assertEquals("amd32", platform2.getArchitecture());
Assert.assertEquals("windows", platform2.getOs());
}
Aggregations