Search in sources :

Example 41 with Platform

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

the class PluginConfigurationProcessor method getPlatformsSet.

/**
 * Parses the list of platforms to a set of {@link Platform}.
 *
 * @param rawConfiguration raw configuration data
 * @return the set of parsed platforms
 * @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
 *     specified platforms list that is missing required fields or has invalid values
 */
@VisibleForTesting
static Set<Platform> getPlatformsSet(RawConfiguration rawConfiguration) throws InvalidPlatformException {
    Set<Platform> platforms = new LinkedHashSet<>();
    for (PlatformConfiguration platformConfiguration : rawConfiguration.getPlatforms()) {
        Optional<String> architecture = platformConfiguration.getArchitectureName();
        Optional<String> os = platformConfiguration.getOsName();
        String platformToString = "architecture=" + architecture.orElse("<missing>") + ", os=" + os.orElse("<missing>");
        if (!architecture.isPresent()) {
            throw new InvalidPlatformException("platform configuration is missing an architecture value", platformToString);
        }
        if (!os.isPresent()) {
            throw new InvalidPlatformException("platform configuration is missing an OS value", platformToString);
        }
        platforms.add(new Platform(architecture.get(), os.get()));
    }
    return platforms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 42 with Platform

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

the class PlatformCheckerTest method testCheckManifestPlatform_multiplePlatformsConfigured.

@Test
public void testCheckManifestPlatform_multiplePlatformsConfigured() {
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os")));
    PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate());
    Mockito.verify(eventHandlers).dispatch(LogEvent.warn("platforms configured, but 'scratch' is not a manifest list"));
}
Also used : ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

Example 43 with Platform

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

the class PlatformCheckerTest method testCheckManifestPlatform_mismatch.

@Test
public void testCheckManifestPlatform_mismatch() {
    Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("configured arch", "configured OS")));
    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("actual arch");
    containerConfigJson.setOs("actual OS");
    PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson);
    Mockito.verify(eventHandlers).dispatch(LogEvent.warn("the configured platform (configured arch/configured OS) doesn't match the " + "platform (actual arch/actual OS) of the base image (scratch)"));
}
Also used : ContainerConfigurationTemplate(com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

Example 44 with Platform

use of com.google.cloud.tools.jib.api.buildplan.Platform 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());
}
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 45 with Platform

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

the class PullBaseImageStepTest method testLookUpPlatformSpecificImageManifest.

@Test
public void testLookUpPlatformSpecificImageManifest() throws IOException, UnlistedPlatformInManifestListException {
    String manifestListJson = " {\n" + "   \"schemaVersion\": 2,\n" + "   \"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",\n" + "   \"manifests\": [\n" + "      {\n" + "         \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + "         \"size\": 424,\n" + "         \"digest\": \"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\n" + "         \"platform\": {\n" + "            \"architecture\": \"arm64\",\n" + "            \"os\": \"linux\"\n" + "         }\n" + "      },\n" + "      {\n" + "         \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n" + "         \"size\": 425,\n" + "         \"digest\": \"sha256:2222222222222222222222222222222222222222222222222222222222222222\",\n" + "         \"platform\": {\n" + "            \"architecture\": \"targetArchitecture\",\n" + "            \"os\": \"targetOS\"\n" + "         }\n" + "      }\n" + "   ]\n" + "}";
    V22ManifestListTemplate manifestList = JsonTemplateMapper.readJson(manifestListJson, V22ManifestListTemplate.class);
    String manifestDigest = pullBaseImageStep.lookUpPlatformSpecificImageManifest(manifestList, new Platform("targetArchitecture", "targetOS"));
    Assert.assertEquals("sha256:2222222222222222222222222222222222222222222222222222222222222222", manifestDigest);
}
Also used : V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Test(org.junit.Test)

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