use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class PushImageStep method makeList.
static ImmutableList<PushImageStep> makeList(BuildContext buildContext, ProgressEventDispatcher.Factory progressEventDispatcherFactory, RegistryClient registryClient, BlobDescriptor containerConfigurationDigestAndSize, Image builtImage, boolean manifestAlreadyExists) throws IOException {
// Gets the image manifest to push.
BuildableManifestTemplate manifestTemplate = new ImageToJsonTranslator(builtImage).getManifestTemplate(buildContext.getTargetFormat(), containerConfigurationDigestAndSize);
DescriptorDigest manifestDigest = Digests.computeJsonDigest(manifestTemplate);
Set<String> imageQualifiers = getImageQualifiers(buildContext, builtImage, manifestDigest);
EventHandlers eventHandlers = buildContext.getEventHandlers();
try (TimerEventDispatcher ignored = new TimerEventDispatcher(eventHandlers, "Preparing manifest pushers");
ProgressEventDispatcher progressDispatcher = progressEventDispatcherFactory.create("launching manifest pushers", imageQualifiers.size())) {
if (JibSystemProperties.skipExistingImages() && manifestAlreadyExists) {
eventHandlers.dispatch(LogEvent.info("Skipping pushing manifest; already exists."));
return ImmutableList.of();
}
return imageQualifiers.stream().map(qualifier -> new PushImageStep(buildContext, progressDispatcher.newChildProducer(), registryClient, manifestTemplate, qualifier, manifestDigest, containerConfigurationDigestAndSize.getDigest())).collect(ImmutableList.toImmutableList());
}
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by GoogleContainerTools.
the class PullBaseImageStep method getCachedBaseImages.
/**
* Retrieves the cached base images. If a base image reference is not a manifest list, returns a
* single image (if cached). If a manifest list, returns all the images matching the configured
* platforms in the manifest list but only when all of the images are cached.
*
* @return the cached images, if found
* @throws IOException when an I/O exception occurs
* @throws CacheCorruptedException if the cache is corrupted
* @throws LayerPropertyNotFoundException if adding image layers fails
* @throws BadContainerConfigurationFormatException if the container configuration is in a bad
* format
* @throws UnlistedPlatformInManifestListException if a cached manifest list has no manifests
* matching the configured platform
*/
@VisibleForTesting
List<Image> getCachedBaseImages() throws IOException, CacheCorruptedException, BadContainerConfigurationFormatException, LayerCountMismatchException, UnlistedPlatformInManifestListException {
ImageReference baseImage = buildContext.getBaseImageConfiguration().getImage();
Optional<ImageMetadataTemplate> metadata = buildContext.getBaseImageLayersCache().retrieveMetadata(baseImage);
if (!metadata.isPresent()) {
return Collections.emptyList();
}
ManifestTemplate manifestList = metadata.get().getManifestList();
List<ManifestAndConfigTemplate> manifestsAndConfigs = metadata.get().getManifestsAndConfigs();
if (manifestList == null) {
Verify.verify(manifestsAndConfigs.size() == 1);
ManifestTemplate manifest = manifestsAndConfigs.get(0).getManifest();
if (manifest instanceof V21ManifestTemplate) {
return Collections.singletonList(JsonToImageTranslator.toImage((V21ManifestTemplate) manifest));
}
ContainerConfigurationTemplate containerConfig = Verify.verifyNotNull(manifestsAndConfigs.get(0).getConfig());
PlatformChecker.checkManifestPlatform(buildContext, containerConfig);
return Collections.singletonList(JsonToImageTranslator.toImage((BuildableManifestTemplate) Verify.verifyNotNull(manifest), containerConfig));
}
// Manifest list cached. Identify matching platforms and check if all of them are cached.
ImmutableList.Builder<Image> images = ImmutableList.builder();
for (Platform platform : buildContext.getContainerConfiguration().getPlatforms()) {
String manifestDigest = lookUpPlatformSpecificImageManifest((V22ManifestListTemplate) manifestList, platform);
Optional<ManifestAndConfigTemplate> manifestAndConfigFound = manifestsAndConfigs.stream().filter(entry -> manifestDigest.equals(entry.getManifestDigest())).findFirst();
if (!manifestAndConfigFound.isPresent()) {
return Collections.emptyList();
}
ManifestTemplate manifest = Verify.verifyNotNull(manifestAndConfigFound.get().getManifest());
ContainerConfigurationTemplate containerConfig = Verify.verifyNotNull(manifestAndConfigFound.get().getConfig());
images.add(JsonToImageTranslator.toImage((BuildableManifestTemplate) manifest, containerConfig));
}
return images.build();
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class ContainerBuildersTest method testCreate_dockerBaseImage.
@Test
public void testCreate_dockerBaseImage() throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
JibContainerBuilder containerBuilder = ContainerBuilders.create("docker://docker-image-ref", Collections.emptySet(), mockCommonCliOptions, mockLogger);
BuildContext buildContext = JibContainerBuilderTestHelper.toBuildContext(containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();
assertThat(imageConfiguration.getImage().toString()).isEqualTo("docker-image-ref");
assertThat(imageConfiguration.getDockerClient().isPresent()).isTrue();
assertThat(imageConfiguration.getTarPath().isPresent()).isFalse();
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class ContainerBuildersTest method testCreate_tarBase.
@Test
public void testCreate_tarBase() throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
JibContainerBuilder containerBuilder = ContainerBuilders.create("tar:///path/to.tar", Collections.emptySet(), mockCommonCliOptions, mockLogger);
BuildContext buildContext = JibContainerBuilderTestHelper.toBuildContext(containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();
assertThat(imageConfiguration.getTarPath()).isEqualTo(Optional.of(Paths.get("/path/to.tar")));
assertThat(imageConfiguration.getDockerClient().isPresent()).isFalse();
}
use of com.google.cloud.tools.jib.configuration.BuildContext in project jib by google.
the class Containerizer method to.
/**
* Gets a new {@link Containerizer} that containerizes to a container registry.
*
* @param registryImage the {@link RegistryImage} that defines target container registry and
* credentials
* @return a new {@link Containerizer}
*/
public static Containerizer to(RegistryImage registryImage) {
ImageConfiguration imageConfiguration = ImageConfiguration.builder(registryImage.getImageReference()).setCredentialRetrievers(registryImage.getCredentialRetrievers()).build();
Function<BuildContext, StepsRunner> stepsRunnerFactory = buildContext -> StepsRunner.begin(buildContext).registryPushSteps();
return new Containerizer(DESCRIPTION_FOR_DOCKER_REGISTRY, imageConfiguration, stepsRunnerFactory, true);
}
Aggregations