Search in sources :

Example 36 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class CacheStorageWriterTest method testWriteMetadata_v22.

@Test
public void testWriteMetadata_v22() throws IOException, URISyntaxException, InvalidImageReferenceException {
    ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
    V22ManifestTemplate manifest1 = loadJsonResource("core/json/v22manifest.json", V22ManifestTemplate.class);
    V22ManifestTemplate manifest2 = loadJsonResource("core/json/v22manifest_optional_properties.json", V22ManifestTemplate.class);
    V22ManifestListTemplate manifestList = loadJsonResource("core/json/v22manifest_list.json", V22ManifestListTemplate.class);
    ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
    List<ManifestAndConfigTemplate> manifestsAndConfigs = Arrays.asList(new ManifestAndConfigTemplate(manifest1, containerConfig, "sha256:digest"), new ManifestAndConfigTemplate(manifest2, containerConfig, "sha256:digest"));
    cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(manifestList, manifestsAndConfigs));
    Path savedMetadataPath = cacheRoot.resolve("images/image.reference/project/thing!tag/manifests_configs.json");
    Assert.assertTrue(Files.exists(savedMetadataPath));
    ImageMetadataTemplate savedMetadata = JsonTemplateMapper.readJsonFromFile(savedMetadataPath, ImageMetadataTemplate.class);
    MatcherAssert.assertThat(savedMetadata.getManifestList(), CoreMatchers.instanceOf(V22ManifestListTemplate.class));
    List<ManifestDescriptorTemplate> savedManifestDescriptors = ((V22ManifestListTemplate) savedMetadata.getManifestList()).getManifests();
    Assert.assertEquals(3, savedManifestDescriptors.size());
    Assert.assertEquals("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", savedManifestDescriptors.get(0).getDigest());
    Assert.assertEquals("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", savedManifestDescriptors.get(1).getDigest());
    Assert.assertEquals("sha256:cccbcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501999", savedManifestDescriptors.get(2).getDigest());
    Assert.assertEquals(2, savedMetadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate savedManifestAndConfig1 = savedMetadata.getManifestsAndConfigs().get(0);
    ManifestAndConfigTemplate savedManifestAndConfig2 = savedMetadata.getManifestsAndConfigs().get(1);
    V22ManifestTemplate savedManifest1 = (V22ManifestTemplate) savedManifestAndConfig1.getManifest();
    V22ManifestTemplate savedManifest2 = (V22ManifestTemplate) savedManifestAndConfig2.getManifest();
    Assert.assertEquals(2, savedManifest1.getSchemaVersion());
    Assert.assertEquals(2, savedManifest2.getSchemaVersion());
    Assert.assertEquals(1, savedManifest1.getLayers().size());
    Assert.assertEquals("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236", savedManifest1.getLayers().get(0).getDigest().getHash());
    Assert.assertEquals(Arrays.asList("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), savedManifest2.getLayers().stream().map(layer -> layer.getDigest().getHash()).collect(Collectors.toList()));
    Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest1.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", savedManifest2.getContainerConfiguration().getDigest().getHash());
    Assert.assertEquals("wasm", savedManifestAndConfig1.getConfig().getArchitecture());
    Assert.assertEquals("wasm", savedManifestAndConfig2.getConfig().getArchitecture());
}
Also used : Path(java.nio.file.Path) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ManifestDescriptorTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 37 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class CacheStorageWriterTest method testWriteMetadata_v21.

@Test
public void testWriteMetadata_v21() throws IOException, URISyntaxException, InvalidImageReferenceException {
    V21ManifestTemplate v21Manifest = loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class);
    ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(v21Manifest, null);
    cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)));
    Path savedMetadataPath = cacheRoot.resolve("images/image.reference/project/thing!tag/manifests_configs.json");
    Assert.assertTrue(Files.exists(savedMetadataPath));
    ImageMetadataTemplate savedMetadata = JsonTemplateMapper.readJsonFromFile(savedMetadataPath, ImageMetadataTemplate.class);
    Assert.assertNull(savedMetadata.getManifestList());
    Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate savedManifestAndConfig = savedMetadata.getManifestsAndConfigs().get(0);
    Assert.assertNull(savedManifestAndConfig.getConfig());
    V21ManifestTemplate savedManifest = (V21ManifestTemplate) savedManifestAndConfig.getManifest();
    Assert.assertEquals("ppc64le", savedManifest.getContainerConfiguration().get().getArchitecture());
}
Also used : Path(java.nio.file.Path) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

Example 38 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class PullBaseImageStepTest method testCall_digestBaseImage.

@Test
public void testCall_digestBaseImage() throws LayerPropertyNotFoundException, IOException, RegistryException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException, InvalidImageReferenceException {
    ImageReference imageReference = ImageReference.parse("awesome@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    Assert.assertTrue(imageReference.getDigest().isPresent());
    Mockito.when(imageConfiguration.getImage()).thenReturn(imageReference);
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("slim arch");
    containerConfigJson.setOs("fat system");
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    ImagesAndRegistryClient result = pullBaseImageStep.call();
    Assert.assertEquals("fat system", result.images.get(0).getOs());
    Assert.assertEquals(registryClient, result.registryClient);
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 39 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class PullBaseImageStepTest method testGetCachedBaseImages_emptyCache.

@Test
public void testGetCachedBaseImages_emptyCache() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.empty());
    Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) Test(org.junit.Test)

Example 40 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class RegistryCredentialRetrieverTest method makeFakeBuildContext.

private BuildContext makeFakeBuildContext(List<CredentialRetriever> baseCredentialRetrievers, List<CredentialRetriever> targetCredentialRetrievers) throws CacheDirectoryCreationException {
    ImageReference baseImage = ImageReference.of("baseregistry", "baserepo", null);
    ImageReference targetImage = ImageReference.of("targetregistry", "targetrepo", null);
    return BuildContext.builder().setEventHandlers(mockEventHandlers).setBaseImageConfiguration(ImageConfiguration.builder(baseImage).setCredentialRetrievers(baseCredentialRetrievers).build()).setTargetImageConfiguration(ImageConfiguration.builder(targetImage).setCredentialRetrievers(targetCredentialRetrievers).build()).setContainerConfiguration(ContainerConfiguration.builder().build()).setBaseImageLayersCacheDirectory(Paths.get("ignored")).setApplicationLayersCacheDirectory(Paths.get("ignored")).setExecutorService(MoreExecutors.newDirectExecutorService()).build();
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference)

Aggregations

ImageReference (com.google.cloud.tools.jib.api.ImageReference)46 Test (org.junit.Test)26 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)22 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)22 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)14 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)12 Image (com.google.cloud.tools.jib.image.Image)12 Path (java.nio.file.Path)12 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)10 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)10 Containerizer (com.google.cloud.tools.jib.api.Containerizer)9 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)9 ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)8 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)7 TarImage (com.google.cloud.tools.jib.api.TarImage)6 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)6 List (java.util.List)6 Credential (com.google.cloud.tools.jib.api.Credential)4 LogEvent (com.google.cloud.tools.jib.api.LogEvent)4