Search in sources :

Example 1 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class Containerizers method create.

private static Containerizer create(CommonCliOptions commonCliOptions, ConsoleLogger logger) throws InvalidImageReferenceException, FileNotFoundException {
    String imageSpec = commonCliOptions.getTargetImage();
    if (imageSpec.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
        // TODO: allow setting docker env and docker executable (along with path/env)
        return Containerizer.to(DockerDaemonImage.named(imageSpec.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (imageSpec.startsWith(TAR_IMAGE_PREFIX)) {
        return Containerizer.to(TarImage.at(Paths.get(imageSpec.replaceFirst(TAR_IMAGE_PREFIX, ""))).named(commonCliOptions.getName()));
    }
    ImageReference imageReference = ImageReference.parse(imageSpec.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers = DefaultCredentialRetrievers.init(CredentialRetrieverFactory.forImage(imageReference, logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getToCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers).forEach(registryImage::addCredentialRetriever);
    return Containerizer.to(registryImage);
}
Also used : DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) ImageReference(com.google.cloud.tools.jib.api.ImageReference) TAR_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.TAR_IMAGE_PREFIX) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) TarImage(com.google.cloud.tools.jib.api.TarImage) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) DOCKER_DAEMON_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.DOCKER_DAEMON_IMAGE_PREFIX) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) ProgressEventHandler(com.google.cloud.tools.jib.event.progress.ProgressEventHandler) FileNotFoundException(java.io.FileNotFoundException) REGISTRY_IMAGE_PREFIX(com.google.cloud.tools.jib.api.Jib.REGISTRY_IMAGE_PREFIX) LogEvent(com.google.cloud.tools.jib.api.LogEvent) List(java.util.List) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) JibSystemProperties(com.google.cloud.tools.jib.global.JibSystemProperties) ProgressDisplayGenerator(com.google.cloud.tools.jib.plugins.common.logging.ProgressDisplayGenerator) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ConsoleLogger(com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger) ImageReference(com.google.cloud.tools.jib.api.ImageReference) DefaultCredentialRetrievers(com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage)

Example 2 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms.

@Test
public void testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms() 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("target-arch", "target-os")).thenReturn(Arrays.asList("sha256:target-digest"));
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setContainerUser("target-user");
    ManifestAndConfigTemplate targetManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:target-digest");
    ManifestAndConfigTemplate unrelatedManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:unrelated-digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(unrelatedManifestAndConfig, targetManifestAndConfig, unrelatedManifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("target-arch", "target-os")));
    List<Image> images = pullBaseImageStep.getCachedBaseImages();
    Assert.assertEquals(1, images.size());
    Assert.assertEquals("target-user", images.get(0).getUser());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Image(com.google.cloud.tools.jib.image.Image) Test(org.junit.Test)

Example 3 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestCached.

@Test
public void testGetCachedBaseImages_v22ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
    ImageReference imageReference = ImageReference.parse("cat");
    Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("slim arch");
    containerConfigJson.setOs("fat system");
    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
    ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
    Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
    List<Image> images = pullBaseImageStep.getCachedBaseImages();
    Assert.assertEquals(1, images.size());
    Assert.assertEquals("slim arch", images.get(0).getArchitecture());
    Assert.assertEquals("fat system", images.get(0).getOs());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) Image(com.google.cloud.tools.jib.image.Image) Test(org.junit.Test)

Example 4 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

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());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) Test(org.junit.Test)

Example 5 with ImageReference

use of com.google.cloud.tools.jib.api.ImageReference in project jib by GoogleContainerTools.

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());
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) Image(com.google.cloud.tools.jib.image.Image) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

Aggregations

ImageReference (com.google.cloud.tools.jib.api.ImageReference)46 Test (org.junit.Test)26 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)22 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)22 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)14 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)12 Image (com.google.cloud.tools.jib.image.Image)12 Path (java.nio.file.Path)12 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)10 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)10 Containerizer (com.google.cloud.tools.jib.api.Containerizer)9 DockerDaemonImage (com.google.cloud.tools.jib.api.DockerDaemonImage)9 ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)8 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)7 TarImage (com.google.cloud.tools.jib.api.TarImage)6 V21ManifestTemplate (com.google.cloud.tools.jib.image.json.V21ManifestTemplate)6 List (java.util.List)6 Credential (com.google.cloud.tools.jib.api.Credential)4 LogEvent (com.google.cloud.tools.jib.api.LogEvent)4