Search in sources :

Example 1 with V21ManifestTemplate

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

the class ManifestPullerIntegrationTest method testPull_v21.

@Test
public void testPull_v21() throws IOException, RegistryException {
    RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
    V21ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V21ManifestTemplate.class);
    Assert.assertEquals(1, manifestTemplate.getSchemaVersion());
    Assert.assertTrue(manifestTemplate.getFsLayers().size() > 0);
}
Also used : V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

Example 2 with V21ManifestTemplate

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

the class PullBaseImageStep method call.

/**
 * Depends on {@code pullAuthorizationFuture}.
 */
@Override
public Image call() throws IOException, RegistryException, LayerPropertyNotFoundException, LayerCountMismatchException, ExecutionException, InterruptedException {
    try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
        RegistryClient registryClient = new RegistryClient(NonBlockingFutures.get(pullAuthorizationFuture), buildConfiguration.getBaseImageRegistry(), buildConfiguration.getBaseImageRepository());
        ManifestTemplate manifestTemplate = registryClient.pullManifest(buildConfiguration.getBaseImageTag());
        // TODO: Make schema version be enum.
        switch(manifestTemplate.getSchemaVersion()) {
            case 1:
                V21ManifestTemplate v21ManifestTemplate = (V21ManifestTemplate) manifestTemplate;
                return JsonToImageTranslator.toImage(v21ManifestTemplate);
            case 2:
                V22ManifestTemplate v22ManifestTemplate = (V22ManifestTemplate) manifestTemplate;
                if (v22ManifestTemplate.getContainerConfiguration() == null || v22ManifestTemplate.getContainerConfiguration().getDigest() == null) {
                    throw new UnknownManifestFormatException("Invalid container configuration in Docker V2.2 manifest: \n" + Blobs.writeToString(JsonTemplateMapper.toBlob(v22ManifestTemplate)));
                }
                ByteArrayOutputStream containerConfigurationOutputStream = new ByteArrayOutputStream();
                registryClient.pullBlob(v22ManifestTemplate.getContainerConfiguration().getDigest(), containerConfigurationOutputStream);
                String containerConfigurationString = new String(containerConfigurationOutputStream.toByteArray(), StandardCharsets.UTF_8);
                ContainerConfigurationTemplate containerConfigurationTemplate = JsonTemplateMapper.readJson(containerConfigurationString, ContainerConfigurationTemplate.class);
                return JsonToImageTranslator.toImage(v22ManifestTemplate, containerConfigurationTemplate);
        }
        throw new IllegalStateException("Unknown manifest schema version");
    }
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Timer(com.google.cloud.tools.jib.Timer) UnknownManifestFormatException(com.google.cloud.tools.jib.image.json.UnknownManifestFormatException) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate)

Example 3 with V21ManifestTemplate

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

the class BlobPullerIntegrationTest method testPull.

@Test
public void testPull() throws IOException, RegistryException {
    // Pulls the busybox image.
    RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
    V21ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V21ManifestTemplate.class);
    DescriptorDigest realDigest = manifestTemplate.getLayerDigests().get(0);
    // Pulls a layer BLOB of the busybox image.
    CountingDigestOutputStream layerOutputStream = new CountingDigestOutputStream(ByteStreams.nullOutputStream());
    registryClient.pullBlob(realDigest, layerOutputStream);
    Assert.assertEquals(realDigest, layerOutputStream.toBlobDescriptor().getDigest());
}
Also used : CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

Aggregations

V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)3 Test (org.junit.Test)2 Timer (com.google.cloud.tools.jib.Timer)1 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)1 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)1 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)1 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)1 UnknownManifestFormatException (com.google.cloud.tools.jib.image.json.UnknownManifestFormatException)1 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)1 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1