Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ImageLayers in Image #1814

Merged
merged 3 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.cloud.tools.jib.image.ReproducibleLayerBuilder;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;

Expand All @@ -43,31 +44,25 @@ class BuildAndCacheApplicationLayerStep implements Callable<CachedLayerAndName>
static ImmutableList<BuildAndCacheApplicationLayerStep> makeList(
BuildConfiguration buildConfiguration,
ProgressEventDispatcher.Factory progressEventDispatcherFactory) {
int layerCount = buildConfiguration.getLayerConfigurations().size();
List<LayerConfiguration> layerConfigurations = buildConfiguration.getLayerConfigurations();

try (ProgressEventDispatcher progressEventDispatcher =
progressEventDispatcherFactory.create(
"preparing application layer builders", layerCount);
"preparing application layer builders", layerConfigurations.size());
TimerEventDispatcher ignored =
new TimerEventDispatcher(buildConfiguration.getEventHandlers(), DESCRIPTION)) {
ImmutableList.Builder<BuildAndCacheApplicationLayerStep> buildAndCacheApplicationLayerSteps =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is a simple cleanup, unrelated to this issue.

ImmutableList.builderWithExpectedSize(layerCount);
for (LayerConfiguration layerConfiguration : buildConfiguration.getLayerConfigurations()) {
// Skips the layer if empty.
if (layerConfiguration.getLayerEntries().isEmpty()) {
continue;
}

buildAndCacheApplicationLayerSteps.add(
new BuildAndCacheApplicationLayerStep(
buildConfiguration,
progressEventDispatcher.newChildProducer(),
layerConfiguration.getName(),
layerConfiguration));
}
ImmutableList<BuildAndCacheApplicationLayerStep> steps =
buildAndCacheApplicationLayerSteps.build();
return steps;
return layerConfigurations
.stream()
// Skips the layer if empty.
.filter(layerConfiguration -> !layerConfiguration.getLayerEntries().isEmpty())
.map(
layerConfiguration ->
new BuildAndCacheApplicationLayerStep(
buildConfiguration,
progressEventDispatcher.newChildProducer(),
layerConfiguration.getName(),
layerConfiguration))
.collect(ImmutableList.toImmutableList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Image {
public static class Builder {

private final Class<? extends ManifestTemplate> imageFormat;
private final ImageLayers.Builder imageLayersBuilder = ImageLayers.builder();
private final ImmutableList.Builder<Layer> imageLayersBuilder = ImmutableList.builder();
private final ImmutableList.Builder<HistoryEntry> historyBuilder = ImmutableList.builder();

// Don't use ImmutableMap.Builder because it does not allow for replacing existing keys with new
Expand Down Expand Up @@ -287,7 +287,7 @@ public static Builder builder(Class<? extends ManifestTemplate> imageFormat) {
private final String os;

/** The layers of the image, in the order in which they are applied. */
private final ImageLayers layers;
private final ImmutableList<Layer> layers;

/** The commands used to build each layer of the image */
private final ImmutableList<HistoryEntry> history;
Expand Down Expand Up @@ -324,7 +324,7 @@ private Image(
@Nullable Instant created,
String architecture,
String os,
ImageLayers layers,
ImmutableList<Layer> layers,
ImmutableList<HistoryEntry> history,
@Nullable ImmutableMap<String, String> environment,
@Nullable ImmutableList<String> entrypoint,
Expand Down Expand Up @@ -415,7 +415,7 @@ public String getUser() {
}

public ImmutableList<Layer> getLayers() {
return layers.getLayers();
return layers;
}

public ImmutableList<HistoryEntry> getHistory() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.google.cloud.tools.jib.cache.CachedLayer;
import com.google.cloud.tools.jib.configuration.BuildConfiguration;
import com.google.cloud.tools.jib.event.EventHandlers;
import com.google.cloud.tools.jib.image.ImageLayers;
import com.google.cloud.tools.jib.image.Layer;
import com.google.cloud.tools.jib.image.LayerPropertyNotFoundException;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Resources;
Expand All @@ -36,6 +36,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -79,12 +81,11 @@ private static void assertBlobsEqual(Blob expectedBlob, Blob blob) throws IOExce
Assert.assertArrayEquals(Blobs.writeToByteArray(expectedBlob), Blobs.writeToByteArray(blob));
}

@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();

@Mock private BuildConfiguration mockBuildConfiguration;

private Cache cache;
@Mock private EventHandlers mockEventHandlers;

private LayerConfiguration fakeDependenciesLayerConfiguration;
private LayerConfiguration fakeSnapshotDependenciesLayerConfiguration;
Expand Down Expand Up @@ -119,25 +120,25 @@ public void setUp() throws IOException, URISyntaxException {

cache = Cache.withDirectory(temporaryFolder.newFolder().toPath());

Mockito.when(mockBuildConfiguration.getEventHandlers()).thenReturn(mockEventHandlers);
Mockito.when(mockBuildConfiguration.getEventHandlers()).thenReturn(EventHandlers.NONE);
Mockito.when(mockBuildConfiguration.getApplicationLayersCache()).thenReturn(cache);
}

private ImageLayers buildFakeLayersToCache()
private List<Layer> buildFakeLayersToCache()
throws LayerPropertyNotFoundException, IOException, CacheCorruptedException {
ImageLayers.Builder applicationLayersBuilder = ImageLayers.builder();
List<Layer> applicationLayers = new ArrayList<>();

ImmutableList<BuildAndCacheApplicationLayerStep> buildAndCacheApplicationLayerSteps =
BuildAndCacheApplicationLayerStep.makeList(
mockBuildConfiguration,
ProgressEventDispatcher.newRoot(mockEventHandlers, "ignored", 1).newChildProducer());
ProgressEventDispatcher.newRoot(EventHandlers.NONE, "ignored", 1).newChildProducer());

for (BuildAndCacheApplicationLayerStep buildAndCacheApplicationLayerStep :
buildAndCacheApplicationLayerSteps) {
applicationLayersBuilder.add(buildAndCacheApplicationLayerStep.call().getCachedLayer());
applicationLayers.add(buildAndCacheApplicationLayerStep.call().getCachedLayer());
}

return applicationLayersBuilder.build();
return applicationLayers;
}

@Test
Expand All @@ -154,7 +155,7 @@ public void testRun()
.thenReturn(fakeLayerConfigurations);

// Populates the cache.
ImageLayers applicationLayers = buildFakeLayersToCache();
List<Layer> applicationLayers = buildFakeLayersToCache();
Assert.assertEquals(5, applicationLayers.size());

ImmutableList<LayerEntry> dependenciesLayerEntries =
Expand Down Expand Up @@ -215,7 +216,7 @@ public void testRun_emptyLayersIgnored() throws IOException, CacheCorruptedExcep
.thenReturn(fakeLayerConfigurations);

// Populates the cache.
ImageLayers applicationLayers = buildFakeLayersToCache();
List<Layer> applicationLayers = buildFakeLayersToCache();
Assert.assertEquals(3, applicationLayers.size());

ImmutableList<LayerEntry> dependenciesLayerEntries =
Expand Down
Loading