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")));
}
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"));
}
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());
}
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());
}
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();
}
Aggregations