use of com.google.cloud.tools.jib.image.json.UnlistedPlatformInManifestListException in project jib by GoogleContainerTools.
the class PullBaseImageStep method lookUpPlatformSpecificImageManifest.
/**
* Looks through a manifest list for the manifest matching the {@code platform} and returns the
* digest of the first manifest it finds.
*/
// TODO: support OciIndexTemplate once AbstractManifestPuller starts to accept it.
@VisibleForTesting
String lookUpPlatformSpecificImageManifest(V22ManifestListTemplate manifestListTemplate, Platform platform) throws UnlistedPlatformInManifestListException {
EventHandlers eventHandlers = buildContext.getEventHandlers();
List<String> digests = manifestListTemplate.getDigestsForPlatform(platform.getArchitecture(), platform.getOs());
if (digests.isEmpty()) {
String errorTemplate = buildContext.getBaseImageConfiguration().getImage() + " is a manifest list, but the list does not contain an image for architecture=%s, " + "os=%s. If your intention was to specify a platform for your image, see " + "https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#how-do-i-specify-a-platform-in-the-manifest-list-or-oci-index-of-a-base-image";
String error = String.format(errorTemplate, platform.getArchitecture(), platform.getOs());
eventHandlers.dispatch(LogEvent.error(error));
throw new UnlistedPlatformInManifestListException(error);
}
// TODO: perhaps we should return multiple digests matching the platform.
return digests.get(0);
}
use of com.google.cloud.tools.jib.image.json.UnlistedPlatformInManifestListException 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.image.json.UnlistedPlatformInManifestListException in project jib by google.
the class PullBaseImageStep method lookUpPlatformSpecificImageManifest.
/**
* Looks through a manifest list for the manifest matching the {@code platform} and returns the
* digest of the first manifest it finds.
*/
// TODO: support OciIndexTemplate once AbstractManifestPuller starts to accept it.
@VisibleForTesting
String lookUpPlatformSpecificImageManifest(V22ManifestListTemplate manifestListTemplate, Platform platform) throws UnlistedPlatformInManifestListException {
EventHandlers eventHandlers = buildContext.getEventHandlers();
List<String> digests = manifestListTemplate.getDigestsForPlatform(platform.getArchitecture(), platform.getOs());
if (digests.isEmpty()) {
String errorTemplate = buildContext.getBaseImageConfiguration().getImage() + " is a manifest list, but the list does not contain an image for architecture=%s, " + "os=%s. If your intention was to specify a platform for your image, see " + "https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#how-do-i-specify-a-platform-in-the-manifest-list-or-oci-index-of-a-base-image";
String error = String.format(errorTemplate, platform.getArchitecture(), platform.getOs());
eventHandlers.dispatch(LogEvent.error(error));
throw new UnlistedPlatformInManifestListException(error);
}
// TODO: perhaps we should return multiple digests matching the platform.
return digests.get(0);
}
use of com.google.cloud.tools.jib.image.json.UnlistedPlatformInManifestListException in project jib by google.
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();
}
Aggregations