Search in sources :

Example 71 with FileEntriesLayer

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

the class BuildAndCacheApplicationLayerStepTest method testRun_emptyLayersIgnored.

@Test
public void testRun_emptyLayersIgnored() throws IOException, CacheCorruptedException {
    ImmutableList<FileEntriesLayer> fakeLayerConfigurations = ImmutableList.of(fakeDependenciesLayerConfiguration, emptyLayerConfiguration, fakeResourcesLayerConfiguration, fakeClassesLayerConfiguration, emptyLayerConfiguration);
    Mockito.when(mockBuildContext.getLayerConfigurations()).thenReturn(fakeLayerConfigurations);
    // Populates the cache.
    List<Layer> applicationLayers = buildFakeLayersToCache();
    Assert.assertEquals(3, applicationLayers.size());
    ImmutableList<FileEntry> dependenciesLayerEntries = ImmutableList.copyOf(fakeLayerConfigurations.get(0).getEntries());
    ImmutableList<FileEntry> resourcesLayerEntries = ImmutableList.copyOf(fakeLayerConfigurations.get(2).getEntries());
    ImmutableList<FileEntry> classesLayerEntries = ImmutableList.copyOf(fakeLayerConfigurations.get(3).getEntries());
    CachedLayer dependenciesCachedLayer = cache.retrieve(dependenciesLayerEntries).orElseThrow(AssertionError::new);
    CachedLayer resourcesCachedLayer = cache.retrieve(resourcesLayerEntries).orElseThrow(AssertionError::new);
    CachedLayer classesCachedLayer = cache.retrieve(classesLayerEntries).orElseThrow(AssertionError::new);
    // Verifies that the cached layers are up-to-date.
    Assert.assertEquals(applicationLayers.get(0).getBlobDescriptor().getDigest(), dependenciesCachedLayer.getDigest());
    Assert.assertEquals(applicationLayers.get(1).getBlobDescriptor().getDigest(), resourcesCachedLayer.getDigest());
    Assert.assertEquals(applicationLayers.get(2).getBlobDescriptor().getDigest(), classesCachedLayer.getDigest());
    // Verifies that the cache reader gets the same layers as the newest application layers.
    assertBlobsEqual(applicationLayers.get(0).getBlob(), dependenciesCachedLayer.getBlob());
    assertBlobsEqual(applicationLayers.get(1).getBlob(), resourcesCachedLayer.getBlob());
    assertBlobsEqual(applicationLayers.get(2).getBlob(), classesCachedLayer.getBlob());
}
Also used : FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Layer(com.google.cloud.tools.jib.image.Layer) CachedLayer(com.google.cloud.tools.jib.cache.CachedLayer) Test(org.junit.Test)

Example 72 with FileEntriesLayer

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

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)

Example 73 with FileEntriesLayer

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

the class LayersTest method testToLayers_includeExcludes.

@Test
public void testToLayers_includeExcludes() throws IOException, URISyntaxException {
    Path testRoot = getLayersTestRoot("includesExcludesTest");
    List<FileEntriesLayer> layers = parseLayers(testRoot, 6);
    checkLayer(layers.get(0), "includes and excludes", ImmutableSet.of(newEntry(testRoot, "project", "/target/ie", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/", "/target/ie/includedDir/", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/include.me", "/target/ie/includedDir/include.me", "644", 0, "0:0")));
    checkLayer(layers.get(1), "includes only", ImmutableSet.of(newEntry(testRoot, "project", "/target/io", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/", "/target/io/includedDir/", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/include.me", "/target/io/includedDir/include.me", "644", 0, "0:0")));
    checkLayer(layers.get(2), "excludes only", ImmutableSet.of(newEntry(testRoot, "project", "/target/eo", "755", 0, "0:0"), newEntry(testRoot, "project/excludedDir", "/target/eo/excludedDir", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir", "/target/eo/includedDir", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/include.me", "/target/eo/includedDir/include.me", "644", 0, "0:0"), newEntry(testRoot, "project/wild.card", "/target/eo/wild.card", "644", 0, "0:0")));
    checkLayer(layers.get(3), "excludes only shortcut", ImmutableSet.of(newEntry(testRoot, "project", "/target/eo", "755", 0, "0:0"), newEntry(testRoot, "project/excludedDir", "/target/eo/excludedDir", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir", "/target/eo/includedDir", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/include.me", "/target/eo/includedDir/include.me", "644", 0, "0:0"), newEntry(testRoot, "project/wild.card", "/target/eo/wild.card", "644", 0, "0:0")));
    checkLayer(layers.get(4), "exclude dir and contents", ImmutableSet.of(newEntry(testRoot, "project", "/target/edac", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/", "/target/edac/includedDir/", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/include.me", "/target/edac/includedDir/include.me", "644", 0, "0:0"), newEntry(testRoot, "project/wild.card", "/target/edac/wild.card", "644", 0, "0:0")));
    checkLayer(layers.get(5), "excludes only wrong", ImmutableSet.of(newEntry(testRoot, "project", "/target/eo", "755", 0, "0:0"), newEntry(testRoot, "project/excludedDir", "/target/eo/excludedDir", "755", 0, "0:0"), newEntry(testRoot, "project/excludedDir/exclude.me", "/target/eo/excludedDir/exclude.me", "644", 0, "0:0"), newEntry(testRoot, "project/includedDir", "/target/eo/includedDir", "755", 0, "0:0"), newEntry(testRoot, "project/includedDir/include.me", "/target/eo/includedDir/include.me", "644", 0, "0:0"), newEntry(testRoot, "project/wild.card", "/target/eo/wild.card", "644", 0, "0:0")));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 74 with FileEntriesLayer

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

the class LayersTest method testToLayers_writeToRoot.

@Test
public void testToLayers_writeToRoot() throws IOException, URISyntaxException {
    // this test defines the current behavior of writing to root, perhaps we should ignore
    // root at this level or we should ignore it at the builder level
    Path testRoot = getLayersTestRoot("writeToRoot");
    List<FileEntriesLayer> layers = parseLayers(testRoot, 2);
    checkLayer(layers.get(0), "root writer", ImmutableSet.of(newEntry(testRoot, "dir", "/", "755", 1000, ""), newEntry(testRoot, "dir/file.txt", "/file.txt", "644", 1000, "")));
    checkLayer(layers.get(1), "root parent fill", ImmutableSet.of(newEntry(testRoot, ".", "/", "755", 1000, ""), newEntry(testRoot, "./dir", "/dir", "755", 1000, ""), newEntry(testRoot, "./dir/file.txt", "/dir/file.txt", "644", 1000, "")));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 75 with FileEntriesLayer

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

the class LayersTest method parseLayers.

public static List<FileEntriesLayer> parseLayers(Path testDir, int expectedLayerCount) throws IOException {
    Path layersSpecYaml = testDir.resolve("layers.yaml");
    List<FileEntriesLayer> layers = Layers.toLayers(layersSpecYaml.getParent(), new ObjectMapper(new YAMLFactory()).readValue(Files.newBufferedReader(layersSpecYaml, Charsets.UTF_8), LayersSpec.class));
    Assert.assertEquals(expectedLayerCount, layers.size());
    return layers;
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)154 Test (org.junit.Test)111 Path (java.nio.file.Path)92 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)85 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)55 List (java.util.List)29 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)24 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)23 Map (java.util.Map)23 Files (java.nio.file.Files)21 Predicate (java.util.function.Predicate)20 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)16 Collectors (java.util.stream.Collectors)16 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)13 Paths (java.nio.file.Paths)13 Optional (java.util.Optional)13 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)12 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)12