Search in sources :

Example 76 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate 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 77 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.

the class CacheStorageReaderTest method setupCachedMetadataV22.

private static void setupCachedMetadataV22(Path cacheDirectory) throws IOException, URISyntaxException {
    Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
    Files.createDirectories(imageDirectory);
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(loadJsonResource("core/json/v22manifest.json", V22ManifestTemplate.class), loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class), "sha256:digest");
    try (OutputStream out = Files.newOutputStream(imageDirectory.resolve("manifests_configs.json"))) {
        JsonTemplateMapper.writeTo(new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)), out);
    }
}
Also used : Path(java.nio.file.Path) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) OutputStream(java.io.OutputStream) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)

Example 78 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.

the class CacheStorageReaderTest method testVerifyImageMetadata_validV22.

@Test
public void testVerifyImageMetadata_validV22() throws CacheCorruptedException {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate());
    ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 79 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.

the class CacheStorageReaderTest method testVerifyImageMetadata_schema2ManifestsCorrupted_nullContainerConfig.

@Test
public void testVerifyImageMetadata_schema2ManifestsCorrupted_nullContainerConfig() {
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), null, "sha256:digest");
    ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    try {
        CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
        Assert.fail();
    } catch (CacheCorruptedException ex) {
        MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Schema 2 manifests corrupted"));
    }
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Test(org.junit.Test)

Example 80 with ImageMetadataTemplate

use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.

the class CacheStorageReader method retrieveMetadata.

/**
 * Retrieves the cached image metadata (a manifest list and a list of manifest/container
 * configuration pairs) for an image reference.
 *
 * @param imageReference the image reference
 * @return the image metadata for the image reference, if found
 * @throws IOException if an I/O exception occurs
 * @throws CacheCorruptedException if the cache is corrupted
 */
Optional<ImageMetadataTemplate> retrieveMetadata(ImageReference imageReference) throws IOException, CacheCorruptedException {
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Path metadataPath = imageDirectory.resolve("manifests_configs.json");
    if (!Files.exists(metadataPath)) {
        return Optional.empty();
    }
    ImageMetadataTemplate metadata;
    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
        metadata = JsonTemplateMapper.readJsonFromFile(metadataPath, ImageMetadataTemplate.class);
    }
    verifyImageMetadata(metadata, imageDirectory);
    return Optional.of(metadata);
}
Also used : Path(java.nio.file.Path) LockFile(com.google.cloud.tools.jib.filesystem.LockFile) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)

Aggregations

ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)82 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)70 Test (org.junit.Test)58 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)52 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)34 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)28 ImageReference (com.google.cloud.tools.jib.api.ImageReference)26 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)22 Path (java.nio.file.Path)22 OciManifestTemplate (com.google.cloud.tools.jib.image.json.OciManifestTemplate)18 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)14 Image (com.google.cloud.tools.jib.image.Image)12 OutputStream (java.io.OutputStream)12 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)10 BuildableManifestTemplate (com.google.cloud.tools.jib.image.json.BuildableManifestTemplate)8 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)6 Blobs (com.google.cloud.tools.jib.blob.Blobs)6 ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)6 OciIndexTemplate (com.google.cloud.tools.jib.image.json.OciIndexTemplate)6 JsonTemplateMapper (com.google.cloud.tools.jib.json.JsonTemplateMapper)6