Search in sources :

Example 91 with ContainerBuildPlan

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

the class BuildFilesTest method testToBuildFileSpec_templateMultiLineBehavior.

@Test
public void testToBuildFileSpec_templateMultiLineBehavior() throws URISyntaxException, InvalidImageReferenceException, IOException {
    Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/templating/multiLine.yaml").toURI());
    Mockito.when(buildCli.getTemplateParameters()).thenReturn(ImmutableMap.of("replace" + System.lineSeparator() + "this", "creationTime: 1234"));
    JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(buildfile.getParent(), buildfile, buildCli, commonCliOptions, consoleLogger);
    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals(Instant.ofEpochMilli(1234), resolved.getCreationTime());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 92 with ContainerBuildPlan

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

the class BuildFilesTest method testToBuildFileSpec_alternativeRootContext.

@Test
public void testToBuildFileSpec_alternativeRootContext() throws URISyntaxException, InvalidImageReferenceException, IOException {
    Path buildfile = Paths.get(Resources.getResource("buildfiles/projects/allProperties/altYamls/alt-jib.yaml").toURI());
    Path projectRoot = buildfile.getParent().getParent();
    JibContainerBuilder jibContainerBuilder = BuildFiles.toJibContainerBuilder(projectRoot, buildfile, buildCli, commonCliOptions, consoleLogger);
    ContainerBuildPlan resolved = jibContainerBuilder.toContainerBuildPlan();
    Assert.assertEquals(FileEntriesLayer.builder().addEntry(projectRoot.resolve("project/script.sh"), AbsoluteUnixPath.get("/home/script.sh")).build().getEntries(), ((FileEntriesLayer) resolved.getLayers().get(0)).getEntries());
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 93 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan 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 94 with ContainerBuildPlan

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

the class JibContainerBuilderTest method testToContainerBuildPlan_default.

@Test
public void testToContainerBuildPlan_default() throws InvalidImageReferenceException {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
    JibContainerBuilder containerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder);
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
    Assert.assertEquals("base/image", buildPlan.getBaseImage());
    Assert.assertEquals(ImmutableSet.of(new Platform("amd64", "linux")), buildPlan.getPlatforms());
    Assert.assertEquals(Instant.EPOCH, buildPlan.getCreationTime());
    Assert.assertEquals(ImageFormat.Docker, buildPlan.getFormat());
    Assert.assertEquals(Collections.emptyMap(), buildPlan.getEnvironment());
    Assert.assertEquals(Collections.emptyMap(), buildPlan.getLabels());
    Assert.assertEquals(Collections.emptySet(), buildPlan.getVolumes());
    Assert.assertEquals(Collections.emptySet(), buildPlan.getExposedPorts());
    Assert.assertNull(buildPlan.getUser());
    Assert.assertNull(buildPlan.getWorkingDirectory());
    Assert.assertNull(buildPlan.getEntrypoint());
    Assert.assertNull(buildPlan.getCmd());
    Assert.assertEquals(Collections.emptyList(), buildPlan.getLayers());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 95 with ContainerBuildPlan

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

the class JibContainerBuilderTest method testToContainerBuildPlan.

@Test
public void testToContainerBuildPlan() throws InvalidImageReferenceException, IOException {
    ImageConfiguration imageConfiguration = ImageConfiguration.builder(ImageReference.parse("base/image")).build();
    JibContainerBuilder containerBuilder = new JibContainerBuilder(imageConfiguration, spyBuildContextBuilder).setPlatforms(ImmutableSet.of(new Platform("testArchitecture", "testOS"))).setCreationTime(Instant.ofEpochMilli(1000)).setFormat(ImageFormat.OCI).setEnvironment(ImmutableMap.of("env", "var")).setLabels(ImmutableMap.of("com.example.label", "value")).setVolumes(AbsoluteUnixPath.get("/mnt/vol"), AbsoluteUnixPath.get("/media/data")).setExposedPorts(ImmutableSet.of(Port.tcp(1234), Port.udp(5678))).setUser("user").setWorkingDirectory(AbsoluteUnixPath.get("/working/directory")).setEntrypoint(Arrays.asList("entry", "point")).setProgramArguments(Arrays.asList("program", "arguments")).addLayer(Arrays.asList(Paths.get("/non/existing/foo")), "/into/this");
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();
    Assert.assertEquals("base/image", buildPlan.getBaseImage());
    Assert.assertEquals(ImmutableSet.of(new Platform("testArchitecture", "testOS")), buildPlan.getPlatforms());
    Assert.assertEquals(Instant.ofEpochMilli(1000), buildPlan.getCreationTime());
    Assert.assertEquals(ImageFormat.OCI, buildPlan.getFormat());
    Assert.assertEquals(ImmutableMap.of("env", "var"), buildPlan.getEnvironment());
    Assert.assertEquals(ImmutableMap.of("com.example.label", "value"), buildPlan.getLabels());
    Assert.assertEquals(ImmutableSet.of(AbsoluteUnixPath.get("/mnt/vol"), AbsoluteUnixPath.get("/media/data")), buildPlan.getVolumes());
    Assert.assertEquals(ImmutableSet.of(Port.tcp(1234), Port.udp(5678)), buildPlan.getExposedPorts());
    Assert.assertEquals("user", buildPlan.getUser());
    Assert.assertEquals(AbsoluteUnixPath.get("/working/directory"), buildPlan.getWorkingDirectory());
    Assert.assertEquals(Arrays.asList("entry", "point"), buildPlan.getEntrypoint());
    Assert.assertEquals(Arrays.asList("program", "arguments"), buildPlan.getCmd());
    Assert.assertEquals(1, buildPlan.getLayers().size());
    MatcherAssert.assertThat(buildPlan.getLayers().get(0), CoreMatchers.instanceOf(FileEntriesLayer.class));
    Assert.assertEquals(Arrays.asList(new FileEntry(Paths.get("/non/existing/foo"), AbsoluteUnixPath.get("/into/this/foo"), FilePermissions.fromOctalString("644"), Instant.ofEpochSecond(1))), ((FileEntriesLayer) buildPlan.getLayers().get(0)).getEntries());
}
Also used : Platform(com.google.cloud.tools.jib.api.buildplan.Platform) 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) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Aggregations

ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)130 Test (org.junit.Test)120 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)61 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)38 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)26 Path (java.nio.file.Path)24 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)22 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)21 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)20 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)14 Collections (java.util.Collections)14 Optional (java.util.Optional)14 Paths (java.nio.file.Paths)13 List (java.util.List)13 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)12 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)11 Files (java.nio.file.Files)11 File (java.io.File)10 IOException (java.io.IOException)10 Parameters (junitparams.Parameters)10