use of com.google.cloud.tools.jib.configuration.ImageConfiguration in project jib by GoogleContainerTools.
the class ContainerizerTest method testGetImageConfiguration_registryImage.
@Test
public void testGetImageConfiguration_registryImage() throws InvalidImageReferenceException {
CredentialRetriever credentialRetriever = Mockito.mock(CredentialRetriever.class);
Containerizer containerizer = Containerizer.to(RegistryImage.named("registry/image").addCredentialRetriever(credentialRetriever));
ImageConfiguration imageConfiguration = containerizer.getImageConfiguration();
Assert.assertEquals("registry/image", imageConfiguration.getImage().toString());
Assert.assertEquals(Arrays.asList(credentialRetriever), imageConfiguration.getCredentialRetrievers());
}
use of com.google.cloud.tools.jib.configuration.ImageConfiguration in project jib by GoogleContainerTools.
the class JibContainerBuilderTest method testToBuildContext_containerConfigurationSet.
@Test
public void testToBuildContext_containerConfigurationSet() throws InvalidImageReferenceException, CacheDirectoryCreationException {
ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
JibContainerBuilder jibContainerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setEntrypoint(Arrays.asList("entry", "point")).setEnvironment(ImmutableMap.of("name", "value")).setExposedPorts(ImmutableSet.of(Port.tcp(1234), Port.udp(5678))).setLabels(ImmutableMap.of("key", "value")).setProgramArguments(Arrays.asList("program", "arguments")).setCreationTime(Instant.ofEpochMilli(1000)).setUser("user").setWorkingDirectory(AbsoluteUnixPath.get("/working/directory"));
BuildContext buildContext = jibContainerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), containerConfiguration.getPlatforms());
Assert.assertEquals(Arrays.asList("entry", "point"), containerConfiguration.getEntrypoint());
Assert.assertEquals(ImmutableMap.of("name", "value"), containerConfiguration.getEnvironmentMap());
Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678)), containerConfiguration.getExposedPorts());
Assert.assertEquals(ImmutableMap.of("key", "value"), containerConfiguration.getLabels());
Assert.assertEquals(Arrays.asList("program", "arguments"), containerConfiguration.getProgramArguments());
Assert.assertEquals(Instant.ofEpochMilli(1000), containerConfiguration.getCreationTime());
Assert.assertEquals("user", containerConfiguration.getUser());
Assert.assertEquals(AbsoluteUnixPath.get("/working/directory"), containerConfiguration.getWorkingDirectory());
}
use of com.google.cloud.tools.jib.configuration.ImageConfiguration in project jib by GoogleContainerTools.
the class PullBaseImageStep method pullBaseImages.
/**
* Pulls the base images specified in the platforms list.
*
* @param registryClient to communicate with remote registry
* @param progressDispatcherFactory the {@link ProgressEventDispatcher.Factory} for emitting
* {@link ProgressEvent}s
* @return the list of pulled base images and a registry client
* @throws IOException when an I/O exception occurs during the pulling
* @throws RegistryException if communicating with the registry caused a known error
* @throws LayerCountMismatchException if the manifest and configuration contain conflicting layer
* information
* @throws LayerPropertyNotFoundException if adding image layers fails
* @throws BadContainerConfigurationFormatException if the container configuration is in a bad
* format
*/
private List<Image> pullBaseImages(RegistryClient registryClient, ProgressEventDispatcher.Factory progressDispatcherFactory) throws IOException, RegistryException, LayerPropertyNotFoundException, LayerCountMismatchException, BadContainerConfigurationFormatException {
Cache cache = buildContext.getBaseImageLayersCache();
EventHandlers eventHandlers = buildContext.getEventHandlers();
ImageConfiguration baseImageConfig = buildContext.getBaseImageConfiguration();
try (ProgressEventDispatcher progressDispatcher1 = progressDispatcherFactory.create("pulling base image manifest and container config", 2)) {
ManifestAndDigest<?> manifestAndDigest = registryClient.pullManifest(baseImageConfig.getImageQualifier());
eventHandlers.dispatch(LogEvent.lifecycle("Using base image with digest: " + manifestAndDigest.getDigest()));
progressDispatcher1.dispatchProgress(1);
ProgressEventDispatcher.Factory childProgressDispatcherFactory = progressDispatcher1.newChildProducer();
ManifestTemplate manifestTemplate = manifestAndDigest.getManifest();
if (manifestTemplate instanceof V21ManifestTemplate) {
V21ManifestTemplate v21Manifest = (V21ManifestTemplate) manifestTemplate;
cache.writeMetadata(baseImageConfig.getImage(), v21Manifest);
return Collections.singletonList(JsonToImageTranslator.toImage(v21Manifest));
} else if (manifestTemplate instanceof BuildableManifestTemplate) {
// V22ManifestTemplate or OciManifestTemplate
BuildableManifestTemplate imageManifest = (BuildableManifestTemplate) manifestTemplate;
ContainerConfigurationTemplate containerConfig = pullContainerConfigJson(manifestAndDigest, registryClient, childProgressDispatcherFactory);
PlatformChecker.checkManifestPlatform(buildContext, containerConfig);
cache.writeMetadata(baseImageConfig.getImage(), imageManifest, containerConfig);
return Collections.singletonList(JsonToImageTranslator.toImage(imageManifest, containerConfig));
}
// TODO: support OciIndexTemplate once AbstractManifestPuller starts to accept it.
Verify.verify(manifestTemplate instanceof V22ManifestListTemplate);
List<ManifestAndConfigTemplate> manifestsAndConfigs = new ArrayList<>();
ImmutableList.Builder<Image> images = ImmutableList.builder();
Set<Platform> platforms = buildContext.getContainerConfiguration().getPlatforms();
try (ProgressEventDispatcher progressDispatcher2 = childProgressDispatcherFactory.create("pulling platform-specific manifests and container configs", 2L * platforms.size())) {
// If a manifest list, search for the manifests matching the given platforms.
for (Platform platform : platforms) {
String message = "Searching for architecture=%s, os=%s in the base image manifest list";
eventHandlers.dispatch(LogEvent.info(String.format(message, platform.getArchitecture(), platform.getOs())));
String manifestDigest = lookUpPlatformSpecificImageManifest((V22ManifestListTemplate) manifestTemplate, platform);
// TODO: pull multiple manifests (+ container configs) in parallel.
ManifestAndDigest<?> imageManifestAndDigest = registryClient.pullManifest(manifestDigest);
progressDispatcher2.dispatchProgress(1);
BuildableManifestTemplate imageManifest = (BuildableManifestTemplate) imageManifestAndDigest.getManifest();
ContainerConfigurationTemplate containerConfig = pullContainerConfigJson(imageManifestAndDigest, registryClient, progressDispatcher2.newChildProducer());
manifestsAndConfigs.add(new ManifestAndConfigTemplate(imageManifest, containerConfig, manifestDigest));
images.add(JsonToImageTranslator.toImage(imageManifest, containerConfig));
}
}
cache.writeMetadata(baseImageConfig.getImage(), new ImageMetadataTemplate(manifestTemplate, /* manifest list */
manifestsAndConfigs));
return images.build();
}
}
use of com.google.cloud.tools.jib.configuration.ImageConfiguration in project jib by GoogleContainerTools.
the class PluginConfigurationProcessorTest method testGetJavaContainerBuilderWithBaseImage_registry.
@Test
public void testGetJavaContainerBuilderWithBaseImage_registry() throws IncompatibleBaseImageJavaVersionException, InvalidImageReferenceException, IOException, CacheDirectoryCreationException {
when(rawConfiguration.getFromImage()).thenReturn(Optional.of("ima.ge/name"));
ImageConfiguration result = getCommonImageConfiguration();
assertThat(result.getImage().toString()).isEqualTo("ima.ge/name");
assertThat(result.getDockerClient()).isEmpty();
assertThat(result.getTarPath()).isEmpty();
}
use of com.google.cloud.tools.jib.configuration.ImageConfiguration in project jib by GoogleContainerTools.
the class PluginConfigurationProcessorTest method testGetJavaContainerBuilderWithBaseImage_registryWithPrefix.
@Test
public void testGetJavaContainerBuilderWithBaseImage_registryWithPrefix() throws IncompatibleBaseImageJavaVersionException, InvalidImageReferenceException, IOException, CacheDirectoryCreationException {
when(rawConfiguration.getFromImage()).thenReturn(Optional.of("registry://ima.ge/name"));
ImageConfiguration result = getCommonImageConfiguration();
assertThat(result.getImage().toString()).isEqualTo("ima.ge/name");
assertThat(result.getDockerClient()).isEmpty();
assertThat(result.getTarPath()).isEmpty();
}
Aggregations