use of com.google.cloud.tools.jib.image.json.ManifestTemplate in project jib by google.
the class ManifestPullerTest method testHandleResponse_v21.
@Test
public void testHandleResponse_v21() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v21ManifestFile = Paths.get(Resources.getResource("json/v21manifest.json").toURI());
Mockito.when(mockResponse.getBody()).thenReturn(Blobs.from(v21ManifestFile));
ManifestTemplate manifestTemplate = new ManifestPuller<>(fakeRegistryEndpointProperties, "test-image-tag", V21ManifestTemplate.class).handleResponse(mockResponse);
Assert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V21ManifestTemplate.class));
}
use of com.google.cloud.tools.jib.image.json.ManifestTemplate 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);
}
use of com.google.cloud.tools.jib.image.json.ManifestTemplate 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());
}
}
use of com.google.cloud.tools.jib.image.json.ManifestTemplate 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");
}
}
use of com.google.cloud.tools.jib.image.json.ManifestTemplate in project jib by google.
the class ManifestPullerTest method testHandleResponse_v22.
@Test
public void testHandleResponse_v22() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestFile = Paths.get(Resources.getResource("json/v22manifest.json").toURI());
Mockito.when(mockResponse.getBody()).thenReturn(Blobs.from(v22ManifestFile));
ManifestTemplate manifestTemplate = new ManifestPuller<>(fakeRegistryEndpointProperties, "test-image-tag", V22ManifestTemplate.class).handleResponse(mockResponse);
Assert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestTemplate.class));
}
Aggregations