use of com.google.cloud.tools.jib.api.ImageReference in project jib by google.
the class PluginConfigurationProcessor method createJibBuildRunnerForDockerDaemonImage.
/**
* Generate a runner for image builds to docker daemon.
*
* @param rawConfiguration the raw configuration from the plugin
* @param inferredAuthProvider the plugin specific auth provider
* @param projectProperties an plugin specific implementation of {@link ProjectProperties}
* @param globalConfig the Jib global config
* @param helpfulSuggestions a plugin specific instance of {@link HelpfulSuggestions}
* @return new {@link JibBuildRunner} to execute a build
* @throws InvalidImageReferenceException if the image reference is invalid
* @throws MainClassInferenceException if a main class could not be found
* @throws InvalidAppRootException if the specific path for application root is invalid
* @throws IOException if an error occurs creating the container builder
* @throws InvalidWorkingDirectoryException if the working directory specified for the build is
* invalid
* @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
* specified platforms list that is missing required fields or has invalid values
* @throws InvalidContainerVolumeException if a specific container volume is invalid
* @throws IncompatibleBaseImageJavaVersionException if the base image java version cannot support
* this build
* @throws NumberFormatException if a string to number conversion operation fails
* @throws InvalidContainerizingModeException if an invalid {@link ContainerizingMode} was
* specified
* @throws InvalidFilesModificationTimeException if configured modification time could not be
* parsed
* @throws InvalidCreationTimeException if configured creation time could not be parsed
* @throws JibPluginExtensionException if an error occurred while running plugin extensions
* @throws ExtraDirectoryNotFoundException if the extra directory specified for the build is not
* found
*/
public static JibBuildRunner createJibBuildRunnerForDockerDaemonImage(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties, GlobalConfig globalConfig, HelpfulSuggestions helpfulSuggestions) throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException, JibPluginExtensionException {
ImageReference targetImageReference = getGeneratedTargetDockerTag(rawConfiguration, projectProperties, helpfulSuggestions);
DockerDaemonImage targetImage = DockerDaemonImage.named(targetImageReference);
Optional<Path> dockerExecutable = rawConfiguration.getDockerExecutable();
if (dockerExecutable.isPresent()) {
targetImage.setDockerExecutable(dockerExecutable.get());
}
targetImage.setDockerEnvironment(rawConfiguration.getDockerEnvironment());
Containerizer containerizer = Containerizer.to(targetImage);
Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties, containerizer);
JibContainerBuilder updatedContainerBuilder = projectProperties.runPluginExtensions(rawConfiguration.getPluginExtensions(), jibContainerBuilder).setFormat(ImageFormat.Docker);
return JibBuildRunner.forBuildToDockerDaemon(updatedContainerBuilder, containerizer, projectProperties::log, helpfulSuggestions, targetImageReference, rawConfiguration.getToTags()).writeImageDigest(rawConfiguration.getDigestOutputPath()).writeImageId(rawConfiguration.getImageIdOutputPath()).writeImageJson(rawConfiguration.getImageJsonOutputPath());
}
use of com.google.cloud.tools.jib.api.ImageReference in project jib by google.
the class PluginConfigurationProcessor method createJibBuildRunnerForTarImage.
/**
* Generate a runner for image builds to tar file.
*
* @param rawConfiguration the raw configuration from the plugin
* @param inferredAuthProvider the plugin specific auth provider
* @param projectProperties an plugin specific implementation of {@link ProjectProperties}
* @param globalConfig the Jib global config
* @param helpfulSuggestions a plugin specific instance of {@link HelpfulSuggestions}
* @return new {@link JibBuildRunner} to execute a build
* @throws InvalidImageReferenceException if the image reference is invalid
* @throws MainClassInferenceException if a main class could not be found
* @throws InvalidAppRootException if the specific path for application root is invalid
* @throws IOException if an error occurs creating the container builder
* @throws InvalidWorkingDirectoryException if the working directory specified for the build is
* invalid
* @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
* specified platforms list that is missing required fields or has invalid values
* @throws InvalidContainerVolumeException if a specific container volume is invalid
* @throws IncompatibleBaseImageJavaVersionException if the base image java version cannot support
* this build
* @throws NumberFormatException if a string to number conversion operation fails
* @throws InvalidContainerizingModeException if an invalid {@link ContainerizingMode} was
* specified
* @throws InvalidFilesModificationTimeException if configured modification time could not be
* parsed
* @throws InvalidCreationTimeException if configured creation time could not be parsed
* @throws JibPluginExtensionException if an error occurred while running plugin extensions
* @throws ExtraDirectoryNotFoundException if the extra directory specified for the build is not
* found
*/
public static JibBuildRunner createJibBuildRunnerForTarImage(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties, GlobalConfig globalConfig, HelpfulSuggestions helpfulSuggestions) throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, JibPluginExtensionException, ExtraDirectoryNotFoundException {
ImageReference targetImageReference = getGeneratedTargetDockerTag(rawConfiguration, projectProperties, helpfulSuggestions);
TarImage targetImage = TarImage.at(rawConfiguration.getTarOutputPath()).named(targetImageReference);
Containerizer containerizer = Containerizer.to(targetImage);
Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties, containerizer);
JibContainerBuilder updatedContainerBuilder = projectProperties.runPluginExtensions(rawConfiguration.getPluginExtensions(), jibContainerBuilder);
return JibBuildRunner.forBuildTar(updatedContainerBuilder, containerizer, projectProperties::log, helpfulSuggestions, rawConfiguration.getTarOutputPath()).writeImageDigest(rawConfiguration.getDigestOutputPath()).writeImageId(rawConfiguration.getImageIdOutputPath()).writeImageJson(rawConfiguration.getImageJsonOutputPath());
}
use of com.google.cloud.tools.jib.api.ImageReference in project jib by google.
the class PullBaseImageStepTest method testGetCachedBaseImages_v21ManifestCached.
@Test
public void testGetCachedBaseImages_v21ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException, DigestException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
DescriptorDigest layerDigest = DescriptorDigest.fromHash("1111111111111111111111111111111111111111111111111111111111111111");
V21ManifestTemplate v21Manifest = Mockito.mock(V21ManifestTemplate.class);
Mockito.when(v21Manifest.getLayerDigests()).thenReturn(Arrays.asList(layerDigest));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(new ManifestAndConfigTemplate(v21Manifest, null)));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals(1, images.get(0).getLayers().size());
Assert.assertEquals("1111111111111111111111111111111111111111111111111111111111111111", images.get(0).getLayers().get(0).getBlobDescriptor().getDigest().getHash());
}
use of com.google.cloud.tools.jib.api.ImageReference in project jib by google.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_partialMatches.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_partialMatches() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest1")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
}
use of com.google.cloud.tools.jib.api.ImageReference in project jib by google.
the class CacheStorageWriterTest method testWriteMetadata_v21.
@Test
public void testWriteMetadata_v21() throws IOException, URISyntaxException, InvalidImageReferenceException {
V21ManifestTemplate v21Manifest = loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class);
ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(v21Manifest, null);
cacheStorageWriter.writeMetadata(imageReference, new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)));
Path savedMetadataPath = cacheRoot.resolve("images/image.reference/project/thing!tag/manifests_configs.json");
Assert.assertTrue(Files.exists(savedMetadataPath));
ImageMetadataTemplate savedMetadata = JsonTemplateMapper.readJsonFromFile(savedMetadataPath, ImageMetadataTemplate.class);
Assert.assertNull(savedMetadata.getManifestList());
Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());
ManifestAndConfigTemplate savedManifestAndConfig = savedMetadata.getManifestsAndConfigs().get(0);
Assert.assertNull(savedManifestAndConfig.getConfig());
V21ManifestTemplate savedManifest = (V21ManifestTemplate) savedManifestAndConfig.getManifest();
Assert.assertEquals("ppc64le", savedManifest.getContainerConfiguration().get().getArchitecture());
}
Aggregations