Search in sources :

Example 1 with V22ManifestTemplate

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

the class BlobCheckerIntegrationTest method testCheck_exists.

@Test
public void testCheck_exists() throws IOException, RegistryException {
    RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
    V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class);
    DescriptorDigest blobDigest = manifestTemplate.getLayers().get(0).getDigest();
    Assert.assertEquals(blobDigest, registryClient.checkBlob(blobDigest).getDigest());
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Test(org.junit.Test)

Example 2 with V22ManifestTemplate

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

the class ManifestPullerIntegrationTest method testPull_v22.

@Test
public void testPull_v22() throws IOException, RegistryException {
    RegistryClient registryClient = new RegistryClient(null, "gcr.io", "distroless/java");
    ManifestTemplate manifestTemplate = registryClient.pullManifest("latest");
    Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
    V22ManifestTemplate v22ManifestTemplate = (V22ManifestTemplate) manifestTemplate;
    Assert.assertTrue(v22ManifestTemplate.getLayers().size() > 0);
}
Also used : V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) Test(org.junit.Test)

Example 3 with V22ManifestTemplate

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

the class ManifestPusherIntegrationTest method testPush_missingBlobs.

@Test
public void testPush_missingBlobs() throws IOException, RegistryException {
    RegistryClient registryClient = new RegistryClient(null, "gcr.io", "distroless/java");
    ManifestTemplate manifestTemplate = registryClient.pullManifest("latest");
    registryClient = new RegistryClient(null, "localhost:5000", "busybox");
    try {
        registryClient.pushManifest((V22ManifestTemplate) manifestTemplate, "latest");
        Assert.fail("Pushing manifest without its BLOBs should fail");
    } catch (RegistryErrorException ex) {
        HttpResponseException httpResponseException = (HttpResponseException) ex.getCause();
        Assert.assertEquals(HttpStatusCodes.STATUS_CODE_BAD_REQUEST, httpResponseException.getStatusCode());
    }
}
Also used : HttpResponseException(com.google.api.client.http.HttpResponseException) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) Test(org.junit.Test)

Example 4 with V22ManifestTemplate

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

the class ManifestPusherIntegrationTest method testPush.

/**
 * Tests manifest pushing. This test is a comprehensive test of push and pull.
 */
@Test
public void testPush() throws DigestException, IOException, RegistryException {
    Blob testLayerBlob = Blobs.from("crepecake");
    // Known digest for 'crepecake'
    DescriptorDigest testLayerBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
    Blob testContainerConfigurationBlob = Blobs.from("12345");
    DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.fromHash("5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5");
    // Creates a valid image manifest.
    V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate();
    expectedManifestTemplate.addLayer(9, testLayerBlobDigest);
    expectedManifestTemplate.setContainerConfiguration(5, testContainerConfigurationBlobDigest);
    // Pushes the BLOBs.
    RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "testimage");
    Assert.assertFalse(registryClient.pushBlob(testLayerBlobDigest, testLayerBlob));
    Assert.assertFalse(registryClient.pushBlob(testContainerConfigurationBlobDigest, testContainerConfigurationBlob));
    // Pushes the manifest.
    registryClient.pushManifest(expectedManifestTemplate, "latest");
    // Pulls the manifest.
    V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class);
    Assert.assertEquals(1, manifestTemplate.getLayers().size());
    Assert.assertEquals(testLayerBlobDigest, manifestTemplate.getLayers().get(0).getDigest());
    Assert.assertEquals(testContainerConfigurationBlobDigest, manifestTemplate.getContainerConfiguration().getDigest());
}
Also used : Blob(com.google.cloud.tools.jib.blob.Blob) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Test(org.junit.Test)

Example 5 with V22ManifestTemplate

use of com.google.cloud.tools.jib.image.json.V22ManifestTemplate 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)

Aggregations

V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)5 Test (org.junit.Test)4 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)3 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)2 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)2 HttpResponseException (com.google.api.client.http.HttpResponseException)1 Timer (com.google.cloud.tools.jib.Timer)1 Blob (com.google.cloud.tools.jib.blob.Blob)1 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)1 UnknownManifestFormatException (com.google.cloud.tools.jib.image.json.UnknownManifestFormatException)1 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1