Search in sources :

Example 6 with ContainerConfiguration

use of com.google.cloud.tools.jib.configuration.ContainerConfiguration in project jib by google.

the class JibContainerBuilderTest method setApplyContainerBuildPlan.

@Test
public void setApplyContainerBuildPlan() throws InvalidImageReferenceException, CacheDirectoryCreationException {
    FileEntriesLayer layer = FileEntriesLayer.builder().addEntry(Paths.get("/src/file/foo"), AbsoluteUnixPath.get("/path/in/container")).build();
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().setBaseImage("some/base").setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setFormat(ImageFormat.OCI).setCreationTime(Instant.ofEpochMilli(30)).setEnvironment(ImmutableMap.of("env", "var")).setVolumes(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/foo"), AbsoluteUnixPath.get("/bar"))).setLabels(ImmutableMap.of("com.example.label", "cool")).setExposedPorts(ImmutableSet.of(Port.tcp(443))).setLayers(Arrays.asList(layer)).setUser(":").setWorkingDirectory(AbsoluteUnixPath.get("/workspace")).setEntrypoint(Arrays.asList("foo", "entrypoint")).setCmd(Arrays.asList("bar", "cmd")).build();
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("initial/base")).build();
    JibContainerBuilder containerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).applyContainerBuildPlan(buildPlan);
    BuildContext buildContext = containerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
    Assert.assertEquals("some/base", buildContext.getBaseImageConfiguration().getImage().toString());
    Assert.assertEquals(OciManifestTemplate.class, buildContext.getTargetFormat());
    Assert.assertEquals(1, buildContext.getLayerConfigurations().size());
    Assert.assertEquals(1, buildContext.getLayerConfigurations().get(0).getEntries().size());
    Assert.assertEquals(Arrays.asList(new FileEntry(Paths.get("/src/file/foo"), AbsoluteUnixPath.get("/path/in/container"), FilePermissions.fromOctalString("644"), Instant.ofEpochSecond(1))), buildContext.getLayerConfigurations().get(0).getEntries());
    ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
    Assert.assertEquals(Instant.ofEpochMilli(30), containerConfiguration.getCreationTime());
    Assert.assertEquals(ImmutableMap.of("env", "var"), containerConfiguration.getEnvironmentMap());
    Assert.assertEquals(ImmutableMap.of("com.example.label", "cool"), containerConfiguration.getLabels());
    Assert.assertEquals(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/foo"), AbsoluteUnixPath.get("/bar")), containerConfiguration.getVolumes());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(443)), containerConfiguration.getExposedPorts());
    Assert.assertEquals(":", containerConfiguration.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/workspace"), containerConfiguration.getWorkingDirectory());
    Assert.assertEquals(Arrays.asList("foo", "entrypoint"), containerConfiguration.getEntrypoint());
    Assert.assertEquals(Arrays.asList("bar", "cmd"), containerConfiguration.getProgramArguments());
    ContainerBuildPlan convertedPlan = containerBuilder.toContainerBuildPlan();
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), convertedPlan.getPlatforms());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerConfiguration(com.google.cloud.tools.jib.configuration.ContainerConfiguration) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 7 with ContainerConfiguration

use of com.google.cloud.tools.jib.configuration.ContainerConfiguration in project jib by GoogleContainerTools.

the class JibContainerBuilderTest method setApplyContainerBuildPlan.

@Test
public void setApplyContainerBuildPlan() throws InvalidImageReferenceException, CacheDirectoryCreationException {
    FileEntriesLayer layer = FileEntriesLayer.builder().addEntry(Paths.get("/src/file/foo"), AbsoluteUnixPath.get("/path/in/container")).build();
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().setBaseImage("some/base").setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setFormat(ImageFormat.OCI).setCreationTime(Instant.ofEpochMilli(30)).setEnvironment(ImmutableMap.of("env", "var")).setVolumes(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/foo"), AbsoluteUnixPath.get("/bar"))).setLabels(ImmutableMap.of("com.example.label", "cool")).setExposedPorts(ImmutableSet.of(Port.tcp(443))).setLayers(Arrays.asList(layer)).setUser(":").setWorkingDirectory(AbsoluteUnixPath.get("/workspace")).setEntrypoint(Arrays.asList("foo", "entrypoint")).setCmd(Arrays.asList("bar", "cmd")).build();
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("initial/base")).build();
    JibContainerBuilder containerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).applyContainerBuildPlan(buildPlan);
    BuildContext buildContext = containerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
    Assert.assertEquals("some/base", buildContext.getBaseImageConfiguration().getImage().toString());
    Assert.assertEquals(OciManifestTemplate.class, buildContext.getTargetFormat());
    Assert.assertEquals(1, buildContext.getLayerConfigurations().size());
    Assert.assertEquals(1, buildContext.getLayerConfigurations().get(0).getEntries().size());
    Assert.assertEquals(Arrays.asList(new FileEntry(Paths.get("/src/file/foo"), AbsoluteUnixPath.get("/path/in/container"), FilePermissions.fromOctalString("644"), Instant.ofEpochSecond(1))), buildContext.getLayerConfigurations().get(0).getEntries());
    ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
    Assert.assertEquals(Instant.ofEpochMilli(30), containerConfiguration.getCreationTime());
    Assert.assertEquals(ImmutableMap.of("env", "var"), containerConfiguration.getEnvironmentMap());
    Assert.assertEquals(ImmutableMap.of("com.example.label", "cool"), containerConfiguration.getLabels());
    Assert.assertEquals(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/foo"), AbsoluteUnixPath.get("/bar")), containerConfiguration.getVolumes());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(443)), containerConfiguration.getExposedPorts());
    Assert.assertEquals(":", containerConfiguration.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/workspace"), containerConfiguration.getWorkingDirectory());
    Assert.assertEquals(Arrays.asList("foo", "entrypoint"), containerConfiguration.getEntrypoint());
    Assert.assertEquals(Arrays.asList("bar", "cmd"), containerConfiguration.getProgramArguments());
    ContainerBuildPlan convertedPlan = containerBuilder.toContainerBuildPlan();
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), convertedPlan.getPlatforms());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerConfiguration(com.google.cloud.tools.jib.configuration.ContainerConfiguration) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 8 with ContainerConfiguration

use of com.google.cloud.tools.jib.configuration.ContainerConfiguration in project jib by GoogleContainerTools.

the class JibContainerBuilderTest method testToBuildContext_containerConfigurationAdd.

@Test
public void testToBuildContext_containerConfigurationAdd() throws InvalidImageReferenceException, CacheDirectoryCreationException {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
    JibContainerBuilder jibContainerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).addPlatform("testArchitecture", "testOS").setEntrypoint("entry", "point").setEnvironment(ImmutableMap.of("name", "value")).addEnvironmentVariable("environment", "variable").setExposedPorts(Port.tcp(1234), Port.udp(5678)).addExposedPort(Port.tcp(1337)).setLabels(ImmutableMap.of("key", "value")).addLabel("added", "label").setProgramArguments("program", "arguments");
    BuildContext buildContext = jibContainerBuilder.toBuildContext(Containerizer.to(RegistryImage.named("target/image")));
    ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS"), new Platform("amd64", "linux")), containerConfiguration.getPlatforms());
    Assert.assertEquals(Arrays.asList("entry", "point"), containerConfiguration.getEntrypoint());
    Assert.assertEquals(ImmutableMap.of("name", "value", "environment", "variable"), containerConfiguration.getEnvironmentMap());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678), Port.tcp(1337)), containerConfiguration.getExposedPorts());
    Assert.assertEquals(ImmutableMap.of("key", "value", "added", "label"), containerConfiguration.getLabels());
    Assert.assertEquals(Arrays.asList("program", "arguments"), containerConfiguration.getProgramArguments());
    Assert.assertEquals(Instant.EPOCH, containerConfiguration.getCreationTime());
}
Also used : BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ContainerConfiguration(com.google.cloud.tools.jib.configuration.ContainerConfiguration) Test(org.junit.Test)

Aggregations

ContainerConfiguration (com.google.cloud.tools.jib.configuration.ContainerConfiguration)8 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)6 BuildContext (com.google.cloud.tools.jib.configuration.BuildContext)6 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)6 Test (org.junit.Test)6 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)2 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)2 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)2 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)2 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)2 Image (com.google.cloud.tools.jib.image.Image)2 HistoryEntry (com.google.cloud.tools.jib.image.json.HistoryEntry)2 Instant (java.time.Instant)2