use of com.google.cloud.tools.jib.image.json.HistoryEntry in project jib by GoogleContainerTools.
the class BuildImageStepTest method test_generateHistoryObjects.
@Test
public void test_generateHistoryObjects() {
Image image = new BuildImageStep(mockBuildContext, mockProgressEventDispatcherFactory, baseImage, baseImageLayers, applicationLayers).call();
// Make sure history is as expected
HistoryEntry expectedAddedBaseLayerHistory = HistoryEntry.builder().setCreationTimestamp(Instant.EPOCH).setComment("auto-generated by Jib").build();
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)
Assert.assertEquals(nonEmptyLayerHistory, image.getHistory().get(0));
Assert.assertEquals(emptyLayerHistory, image.getHistory().get(1));
Assert.assertEquals(emptyLayerHistory, image.getHistory().get(2));
Assert.assertEquals(expectedAddedBaseLayerHistory, image.getHistory().get(3));
Assert.assertEquals(expectedAddedBaseLayerHistory, image.getHistory().get(4));
// 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 9 total
Assert.assertEquals(9, image.getHistory().size());
}
use of com.google.cloud.tools.jib.image.json.HistoryEntry in project jib by GoogleContainerTools.
the class BuildImageStep method call.
@Override
public Image call() throws LayerPropertyNotFoundException {
try (ProgressEventDispatcher ignored = progressEventDispatcherFactory.create("building image format", 1);
TimerEventDispatcher ignored2 = new TimerEventDispatcher(buildContext.getEventHandlers(), DESCRIPTION)) {
// Constructs the image.
Image.Builder imageBuilder = Image.builder(buildContext.getTargetFormat());
// Base image layers
baseImageLayers.forEach(imageBuilder::addLayer);
// Passthrough config and count non-empty history entries
int nonEmptyLayerCount = 0;
for (HistoryEntry historyObject : baseImage.getHistory()) {
imageBuilder.addHistory(historyObject);
if (!historyObject.hasCorrespondingLayer()) {
nonEmptyLayerCount++;
}
}
imageBuilder.setArchitecture(baseImage.getArchitecture()).setOs(baseImage.getOs()).addEnvironment(baseImage.getEnvironment()).addLabels(baseImage.getLabels()).setHealthCheck(baseImage.getHealthCheck()).addExposedPorts(baseImage.getExposedPorts()).addVolumes(baseImage.getVolumes()).setUser(baseImage.getUser()).setWorkingDirectory(baseImage.getWorkingDirectory());
ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
// Add history elements for non-empty layers that don't have one yet
Instant layerCreationTime = containerConfiguration.getCreationTime();
for (int count = 0; count < baseImageLayers.size() - nonEmptyLayerCount; count++) {
imageBuilder.addHistory(HistoryEntry.builder().setCreationTimestamp(layerCreationTime).setComment("auto-generated by Jib").build());
}
// Add built layers/configuration
for (PreparedLayer applicationLayer : applicationLayers) {
imageBuilder.addLayer(applicationLayer).addHistory(HistoryEntry.builder().setCreationTimestamp(layerCreationTime).setAuthor("Jib").setCreatedBy(buildContext.getToolName() + ":" + buildContext.getToolVersion()).setComment(applicationLayer.getName()).build());
}
imageBuilder.addEnvironment(containerConfiguration.getEnvironmentMap()).setCreated(containerConfiguration.getCreationTime()).setEntrypoint(computeEntrypoint(baseImage, containerConfiguration)).setProgramArguments(computeProgramArguments(baseImage, containerConfiguration)).addExposedPorts(containerConfiguration.getExposedPorts()).addVolumes(containerConfiguration.getVolumes()).addLabels(containerConfiguration.getLabels());
if (containerConfiguration.getUser() != null) {
imageBuilder.setUser(containerConfiguration.getUser());
}
if (containerConfiguration.getWorkingDirectory() != null) {
imageBuilder.setWorkingDirectory(containerConfiguration.getWorkingDirectory().toString());
}
// Gets the container configuration content descriptor.
return imageBuilder.build();
}
}
use of com.google.cloud.tools.jib.image.json.HistoryEntry in project jib by google.
the class BuildImageStep method call.
@Override
public Image call() throws LayerPropertyNotFoundException {
try (ProgressEventDispatcher ignored = progressEventDispatcherFactory.create("building image format", 1);
TimerEventDispatcher ignored2 = new TimerEventDispatcher(buildContext.getEventHandlers(), DESCRIPTION)) {
// Constructs the image.
Image.Builder imageBuilder = Image.builder(buildContext.getTargetFormat());
// Base image layers
baseImageLayers.forEach(imageBuilder::addLayer);
// Passthrough config and count non-empty history entries
int nonEmptyLayerCount = 0;
for (HistoryEntry historyObject : baseImage.getHistory()) {
imageBuilder.addHistory(historyObject);
if (!historyObject.hasCorrespondingLayer()) {
nonEmptyLayerCount++;
}
}
imageBuilder.setArchitecture(baseImage.getArchitecture()).setOs(baseImage.getOs()).addEnvironment(baseImage.getEnvironment()).addLabels(baseImage.getLabels()).setHealthCheck(baseImage.getHealthCheck()).addExposedPorts(baseImage.getExposedPorts()).addVolumes(baseImage.getVolumes()).setUser(baseImage.getUser()).setWorkingDirectory(baseImage.getWorkingDirectory());
ContainerConfiguration containerConfiguration = buildContext.getContainerConfiguration();
// Add history elements for non-empty layers that don't have one yet
Instant layerCreationTime = containerConfiguration.getCreationTime();
for (int count = 0; count < baseImageLayers.size() - nonEmptyLayerCount; count++) {
imageBuilder.addHistory(HistoryEntry.builder().setCreationTimestamp(layerCreationTime).setComment("auto-generated by Jib").build());
}
// Add built layers/configuration
for (PreparedLayer applicationLayer : applicationLayers) {
imageBuilder.addLayer(applicationLayer).addHistory(HistoryEntry.builder().setCreationTimestamp(layerCreationTime).setAuthor("Jib").setCreatedBy(buildContext.getToolName() + ":" + buildContext.getToolVersion()).setComment(applicationLayer.getName()).build());
}
imageBuilder.addEnvironment(containerConfiguration.getEnvironmentMap()).setCreated(containerConfiguration.getCreationTime()).setEntrypoint(computeEntrypoint(baseImage, containerConfiguration)).setProgramArguments(computeProgramArguments(baseImage, containerConfiguration)).addExposedPorts(containerConfiguration.getExposedPorts()).addVolumes(containerConfiguration.getVolumes()).addLabels(containerConfiguration.getLabels());
if (containerConfiguration.getUser() != null) {
imageBuilder.setUser(containerConfiguration.getUser());
}
if (containerConfiguration.getWorkingDirectory() != null) {
imageBuilder.setWorkingDirectory(containerConfiguration.getWorkingDirectory().toString());
}
// Gets the container configuration content descriptor.
return imageBuilder.build();
}
}
use of com.google.cloud.tools.jib.image.json.HistoryEntry in project jib by google.
the class BuildImageStepTest method test_generateHistoryObjects.
@Test
public void test_generateHistoryObjects() {
Image image = new BuildImageStep(mockBuildContext, mockProgressEventDispatcherFactory, baseImage, baseImageLayers, applicationLayers).call();
// Make sure history is as expected
HistoryEntry expectedAddedBaseLayerHistory = HistoryEntry.builder().setCreationTimestamp(Instant.EPOCH).setComment("auto-generated by Jib").build();
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)
Assert.assertEquals(nonEmptyLayerHistory, image.getHistory().get(0));
Assert.assertEquals(emptyLayerHistory, image.getHistory().get(1));
Assert.assertEquals(emptyLayerHistory, image.getHistory().get(2));
Assert.assertEquals(expectedAddedBaseLayerHistory, image.getHistory().get(3));
Assert.assertEquals(expectedAddedBaseLayerHistory, image.getHistory().get(4));
// 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 9 total
Assert.assertEquals(9, image.getHistory().size());
}
Aggregations