Search in sources :

Example 21 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class ContainerBuildersTest method testCreate_platforms.

@Test
public void testCreate_platforms() throws IOException, InvalidImageReferenceException {
    JibContainerBuilder containerBuilder = ContainerBuilders.create("registry://registry-image-ref", ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")), mockCommonCliOptions, mockLogger);
    assertThat(containerBuilder.toContainerBuildPlan().getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Test(org.junit.Test)

Example 22 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class PluginConfigurationProcessorTest method testGetPlatformsSet.

@Test
public void testGetPlatformsSet() throws InvalidPlatformException {
    Mockito.<List<?>>when(rawConfiguration.getPlatforms()).thenReturn(Arrays.asList(new TestPlatformConfiguration("testArchitecture", "testOs")));
    assertThat(PluginConfigurationProcessor.getPlatformsSet(rawConfiguration)).containsExactly(new Platform("testArchitecture", "testOs"));
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

Example 23 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class BuildFilesTest method testToJibContainerBuilder_allProperties.

@Test
public void testToJibContainerBuilder_allProperties() throws URISyntaxException, IOException, InvalidImageReferenceException {
    Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/allProperties/jib.yaml").toURI());
    Path projectRoot = buildfile.getParent();
    JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(projectRoot, buildfile, buildCli, commonCliOptions, consoleLogger);
    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals("ubuntu", resolved.getBaseImage());
    Assert.assertEquals(Instant.ofEpochMilli(2000), resolved.getCreationTime());
    Assert.assertEquals(ImageFormat.OCI, resolved.getFormat());
    Assert.assertEquals(ImmutableSet.of(new Platform("arm", "linux"), new Platform("amd64", "darwin")), resolved.getPlatforms());
    Assert.assertEquals(ImmutableMap.of("KEY1", "v1", "KEY2", "v2"), resolved.getEnvironment());
    Assert.assertEquals(ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")), resolved.getVolumes());
    Assert.assertEquals(ImmutableMap.of("label1", "l1", "label2", "l2"), resolved.getLabels());
    Assert.assertEquals(ImmutableSet.of(Port.udp(123), Port.tcp(456), Port.tcp(789)), resolved.getExposedPorts());
    Assert.assertEquals("customUser", resolved.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/home"), resolved.getWorkingDirectory());
    Assert.assertEquals(ImmutableList.of("sh", "script.sh"), resolved.getEntrypoint());
    Assert.assertEquals(ImmutableList.of("--param", "param"), resolved.getCmd());
    Assert.assertEquals(1, resolved.getLayers().size());
    FileEntriesLayer resolvedLayer = (FileEntriesLayer) resolved.getLayers().get(0);
    Assert.assertEquals("scripts", resolvedLayer.getName());
    Assert.assertEquals(FileEntriesLayer.builder().addEntry(projectRoot.resolve("project/script.sh"), AbsoluteUnixPath.get("/home/script.sh")).build().getEntries(), resolvedLayer.getEntries());
    Assert.assertEquals(LayerObject.Type.FILE_ENTRIES, resolvedLayer.getType());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 24 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform in project jib by google.

the class BuildFilesTest method testToJibContainerBuilder_requiredProperties.

@Test
public void testToJibContainerBuilder_requiredProperties() throws URISyntaxException, IOException, InvalidImageReferenceException {
    Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/allDefaults/jib.yaml").toURI());
    JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(buildfile.getParent(), buildfile, buildCli, commonCliOptions, consoleLogger);
    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals("scratch", resolved.getBaseImage());
    Assert.assertEquals(ImmutableSet.of(new Platform("amd64", "linux")), resolved.getPlatforms());
    Assert.assertEquals(Instant.EPOCH, resolved.getCreationTime());
    Assert.assertEquals(ImageFormat.Docker, resolved.getFormat());
    Assert.assertTrue(resolved.getEnvironment().isEmpty());
    Assert.assertTrue(resolved.getLabels().isEmpty());
    Assert.assertTrue(resolved.getVolumes().isEmpty());
    Assert.assertTrue(resolved.getExposedPorts().isEmpty());
    Assert.assertNull(resolved.getUser());
    Assert.assertNull(resolved.getWorkingDirectory());
    Assert.assertNull(resolved.getEntrypoint());
    Assert.assertTrue(resolved.getLayers().isEmpty());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 25 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform 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();
}
Also used : TimerEventDispatcher(com.google.cloud.tools.jib.builder.TimerEventDispatcher) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) Callable(java.util.concurrent.Callable) LayerPropertyNotFoundException(com.google.cloud.tools.jib.image.LayerPropertyNotFoundException) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) UnknownManifestFormatException(com.google.cloud.tools.jib.image.json.UnknownManifestFormatException) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) Credential(com.google.cloud.tools.jib.api.Credential) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Nullable(javax.annotation.Nullable) Verify(com.google.common.base.Verify) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) UnlistedPlatformInManifestListException(com.google.cloud.tools.jib.image.json.UnlistedPlatformInManifestListException) Collection(java.util.Collection) JsonTemplateMapper(com.google.cloud.tools.jib.json.JsonTemplateMapper) Set(java.util.Set) IOException(java.io.IOException) RegistryUnauthorizedException(com.google.cloud.tools.jib.api.RegistryUnauthorizedException) RegistryException(com.google.cloud.tools.jib.api.RegistryException) CredentialRetrievalException(com.google.cloud.tools.jib.registry.credentials.CredentialRetrievalException) Cache(com.google.cloud.tools.jib.cache.Cache) CacheCorruptedException(com.google.cloud.tools.jib.cache.CacheCorruptedException) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) LogEvent(com.google.cloud.tools.jib.api.LogEvent) ManifestAndDigest(com.google.cloud.tools.jib.registry.ManifestAndDigest) List(java.util.List) JsonToImageTranslator(com.google.cloud.tools.jib.image.json.JsonToImageTranslator) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) ProgressEventDispatcher(com.google.cloud.tools.jib.builder.ProgressEventDispatcher) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Optional(java.util.Optional) Blobs(com.google.cloud.tools.jib.blob.Blobs) BadContainerConfigurationFormatException(com.google.cloud.tools.jib.image.json.BadContainerConfigurationFormatException) Preconditions(com.google.common.base.Preconditions) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LayerCountMismatchException(com.google.cloud.tools.jib.image.LayerCountMismatchException) Collections(java.util.Collections) Image(com.google.cloud.tools.jib.image.Image) ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImmutableList(com.google.common.collect.ImmutableList) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) ManifestAndConfigTemplate(com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate) Image(com.google.cloud.tools.jib.image.Image) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ImageMetadataTemplate(com.google.cloud.tools.jib.image.json.ImageMetadataTemplate) BuildableManifestTemplate(com.google.cloud.tools.jib.image.json.BuildableManifestTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Platform (com.google.cloud.tools.jib.api.buildplan.Platform)65 Test (org.junit.Test)50 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)18 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)18 V22ManifestListTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate)18 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)16 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)14 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)14 ImageReference (com.google.cloud.tools.jib.api.ImageReference)12 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)12 Path (java.nio.file.Path)12 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)10 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)10 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)10 Image (com.google.cloud.tools.jib.image.Image)9 BuildContext (com.google.cloud.tools.jib.configuration.BuildContext)8 ManifestDescriptorTemplate (com.google.cloud.tools.jib.image.json.V22ManifestListTemplate.ManifestDescriptorTemplate)8 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)7 IOException (java.io.IOException)7 Blobs (com.google.cloud.tools.jib.blob.Blobs)6