Skip to content

Commit

Permalink
Add layer description to layer history (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
paivagustavo authored and TadCordle committed Oct 30, 2018
1 parent af00e2d commit 2bb8a52
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public ListenableFuture<CachedLayer> getFuture() {
return listenableFuture;
}

public String getLayerType() {
return layerType;
}

@Override
public CachedLayer call() throws IOException, CacheCorruptedException {
String description = "Building " + layerType + " layer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private Image<Layer> afterCachedLayerSteps()
.setCreationTimestamp(layerCreationTime)
.setAuthor("Jib")
.setCreatedBy(buildConfiguration.getToolName() + ":" + ProjectInfo.VERSION)
.setComment(buildAndCacheApplicationLayerStep.getLayerType())
.build());
}
if (containerConfiguration != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.time.Instant;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.stream.Stream;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -53,7 +54,10 @@ public class BuildImageStepTest {
@Mock private PullBaseImageStep mockPullBaseImageStep;
@Mock private PullAndCacheBaseImageLayersStep mockPullAndCacheBaseImageLayersStep;
@Mock private PullAndCacheBaseImageLayerStep mockPullAndCacheBaseImageLayerStep;
@Mock private BuildAndCacheApplicationLayerStep mockBuildAndCacheApplicationLayerStep;
@Mock private BuildAndCacheApplicationLayerStep mockBuildAndCacheApplicationLayerStepDependencies;
@Mock private BuildAndCacheApplicationLayerStep mockBuildAndCacheApplicationLayerStepResources;
@Mock private BuildAndCacheApplicationLayerStep mockBuildAndCacheApplicationLayerStepClasses;
@Mock private BuildAndCacheApplicationLayerStep mockBuildAndCacheApplicationLayerStepExtraFiles;

private DescriptorDigest testDescriptorDigest;
private HistoryEntry nonEmptyLayerHistory;
Expand Down Expand Up @@ -141,8 +145,24 @@ public BlobDescriptor getBlobDescriptor() {
.thenReturn(
Futures.immediateFuture(
new PullBaseImageStep.BaseImageWithAuthorization(baseImage, null)));
Mockito.when(mockBuildAndCacheApplicationLayerStep.getFuture())
.thenReturn(Futures.immediateFuture(testCachedLayer));

Stream.of(
mockBuildAndCacheApplicationLayerStepClasses,
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepExtraFiles,
mockBuildAndCacheApplicationLayerStepResources)
.forEach(
layerStep ->
Mockito.when(layerStep.getFuture())
.thenReturn(Futures.immediateFuture(testCachedLayer)));

Mockito.when(mockBuildAndCacheApplicationLayerStepClasses.getLayerType()).thenReturn("classes");
Mockito.when(mockBuildAndCacheApplicationLayerStepDependencies.getLayerType())
.thenReturn("dependencies");
Mockito.when(mockBuildAndCacheApplicationLayerStepExtraFiles.getLayerType())
.thenReturn("extra files");
Mockito.when(mockBuildAndCacheApplicationLayerStepResources.getLayerType())
.thenReturn("resources");
}

@Test
Expand All @@ -154,9 +174,9 @@ public void test_validateAsyncDependencies() throws ExecutionException, Interrup
mockPullBaseImageStep,
mockPullAndCacheBaseImageLayersStep,
ImmutableList.of(
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep));
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepResources,
mockBuildAndCacheApplicationLayerStepClasses));
Image<Layer> image = buildImageStep.getFuture().get().getFuture().get();
Assert.assertEquals(
testDescriptorDigest, image.getLayers().asList().get(0).getBlobDescriptor().getDigest());
Expand All @@ -176,9 +196,9 @@ public void test_propagateBaseImageConfiguration()
mockPullBaseImageStep,
mockPullAndCacheBaseImageLayersStep,
ImmutableList.of(
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep));
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepResources,
mockBuildAndCacheApplicationLayerStepClasses));
Image<Layer> image = buildImageStep.getFuture().get().getFuture().get();
Assert.assertEquals(
ImmutableMap.of("BASE_ENV", "BASE_ENV_VALUE", "MY_ENV", "MY_ENV_VALUE"),
Expand Down Expand Up @@ -209,9 +229,9 @@ public void test_inheritedEntrypoint() throws ExecutionException, InterruptedExc
mockPullBaseImageStep,
mockPullAndCacheBaseImageLayersStep,
ImmutableList.of(
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep));
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepResources,
mockBuildAndCacheApplicationLayerStepClasses));
Image<Layer> image = buildImageStep.getFuture().get().getFuture().get();

Assert.assertEquals(ImmutableList.of("baseImageEntrypoint"), image.getEntrypoint());
Expand All @@ -231,9 +251,9 @@ public void test_inheritedEntrypointAndProgramArguments()
mockPullBaseImageStep,
mockPullAndCacheBaseImageLayersStep,
ImmutableList.of(
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep));
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepResources,
mockBuildAndCacheApplicationLayerStepClasses));
Image<Layer> image = buildImageStep.getFuture().get().getFuture().get();

Assert.assertEquals(ImmutableList.of("baseImageEntrypoint"), image.getEntrypoint());
Expand All @@ -253,9 +273,9 @@ public void test_notInheritedProgramArguments() throws ExecutionException, Inter
mockPullBaseImageStep,
mockPullAndCacheBaseImageLayersStep,
ImmutableList.of(
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep));
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepResources,
mockBuildAndCacheApplicationLayerStepClasses));
Image<Layer> image = buildImageStep.getFuture().get().getFuture().get();

Assert.assertEquals(ImmutableList.of("myEntrypoint"), image.getEntrypoint());
Expand All @@ -271,9 +291,10 @@ public void test_generateHistoryObjects() throws ExecutionException, Interrupted
mockPullBaseImageStep,
mockPullAndCacheBaseImageLayersStep,
ImmutableList.of(
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep,
mockBuildAndCacheApplicationLayerStep));
mockBuildAndCacheApplicationLayerStepDependencies,
mockBuildAndCacheApplicationLayerStepResources,
mockBuildAndCacheApplicationLayerStepClasses,
mockBuildAndCacheApplicationLayerStepExtraFiles));
Image<Layer> image = buildImageStep.getFuture().get().getFuture().get();

// Make sure history is as expected
Expand All @@ -282,11 +303,37 @@ public void test_generateHistoryObjects() throws ExecutionException, Interrupted
.setCreationTimestamp(Instant.EPOCH)
.setComment("auto-generated by Jib")
.build();
HistoryEntry expectedApplicationLayerHistory =

HistoryEntry expectedApplicationLayerHistoryDependencies =
HistoryEntry.builder()
.setCreationTimestamp(Instant.EPOCH)
.setAuthor("Jib")
.setCreatedBy("jib:null")
.setComment("dependencies")
.build();

HistoryEntry expectedApplicationLayerHistoryResources =
HistoryEntry.builder()
.setCreationTimestamp(Instant.EPOCH)
.setAuthor("Jib")
.setCreatedBy("jib:null")
.setComment("resources")
.build();

HistoryEntry expectedApplicationLayerHistoryClasses =
HistoryEntry.builder()
.setCreationTimestamp(Instant.EPOCH)
.setAuthor("Jib")
.setCreatedBy("jib:null")
.setComment("classes")
.build();

HistoryEntry expectedApplicationLayerHistoryExtrafiles =
HistoryEntry.builder()
.setCreationTimestamp(Instant.EPOCH)
.setAuthor("Jib")
.setCreatedBy("jib:null")
.setComment("extra files")
.build();

// Base layers (1 non-empty propagated, 2 empty propagated, 2 non-empty generated)
Expand All @@ -296,12 +343,13 @@ public void test_generateHistoryObjects() throws ExecutionException, Interrupted
Assert.assertEquals(expectedAddedBaseLayerHistory, image.getHistory().get(3));
Assert.assertEquals(expectedAddedBaseLayerHistory, image.getHistory().get(4));

// Application layers (3 generated)
Assert.assertEquals(expectedApplicationLayerHistory, image.getHistory().get(5));
Assert.assertEquals(expectedApplicationLayerHistory, image.getHistory().get(6));
Assert.assertEquals(expectedApplicationLayerHistory, image.getHistory().get(7));
// Application layers (4 generated)
Assert.assertEquals(expectedApplicationLayerHistoryDependencies, image.getHistory().get(5));
Assert.assertEquals(expectedApplicationLayerHistoryResources, image.getHistory().get(6));
Assert.assertEquals(expectedApplicationLayerHistoryClasses, image.getHistory().get(7));
Assert.assertEquals(expectedApplicationLayerHistoryExtrafiles, image.getHistory().get(8));

// Should be exactly 8 total
Assert.assertEquals(8, image.getHistory().size());
// Should be exactly 9 total
Assert.assertEquals(9, image.getHistory().size());
}
}
3 changes: 2 additions & 1 deletion jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ All notable changes to this project will be documented in this file.
- `jib.extraDirectory.path` configures the extra layer directory (still also configurable via `jib.extraDirectory = file(...)`)
- `jib.extraDirectory.permissions` is a map from absolute path on container to the file's permission bits (represented as an octal string)
- Image digest is now written to `build/jib-image.digest` ([#933](https://github.com/GoogleContainerTools/jib/issues/933))

- Adds the layer type to the layer history as comments ([#1198](https://github.com/GoogleContainerTools/jib/issues/1198))

### Changed

- Removed deprecated `jib.jvmFlags`, `jib.mainClass`, `jib.args`, and `jib.format` in favor of the equivalents under `jib.container` ([#461](https://github.com/GoogleContainerTools/jib/issues/461))
Expand Down
1 change: 1 addition & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- `<extraDirectory><path>` configures the extra layer directory (still also configurable via `<extraDirectory>...</extraDirectory>`)
- `<extraDirectory><permissions>` is a list of `<permission>` objects, each with a `<file>` and `<mode>` field, used to map a file on the container to the file's permission bits (represented as an octal string)
- Image digest is now written to `build/jib-image.digest` ([#1155](https://github.com/GoogleContainerTools/jib/pull/1155))
- Adds the layer type to the layer history as comments ([#1198](https://github.com/GoogleContainerTools/jib/issues/1198))

### Changed

Expand Down

0 comments on commit 2bb8a52

Please sign in to comment.