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

Fix base image reproducibility warning #2004

Merged
merged 3 commits into from Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -245,7 +245,7 @@ public BuildConfiguration build() throws IOException {
switch (missingFields.size()) {
case 0: // No errors
Preconditions.checkNotNull(baseImageConfiguration);
if (baseImageConfiguration.getImage().usesDefaultTag()
if (!baseImageConfiguration.getImage().isTagDigest()
&& !baseImageConfiguration.getImage().isScratch()) {
eventHandlers.dispatch(
LogEvent.warn(
Expand Down
Expand Up @@ -21,8 +21,11 @@
import com.google.cloud.tools.jib.api.CredentialRetriever;
import com.google.cloud.tools.jib.api.ImageFormat;
import com.google.cloud.tools.jib.api.ImageReference;
import com.google.cloud.tools.jib.api.InvalidImageReferenceException;
import com.google.cloud.tools.jib.api.LayerConfiguration;
import com.google.cloud.tools.jib.api.LogEvent;
import com.google.cloud.tools.jib.api.Port;
import com.google.cloud.tools.jib.event.EventHandlers;
import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate;
import com.google.cloud.tools.jib.image.json.OCIManifestTemplate;
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;
Expand Down Expand Up @@ -246,4 +249,38 @@ public void testBuilder_missingValues() throws IOException {
ex.getMessage());
}
}

@Test
public void testBuilder_digestWarning() throws IOException, InvalidImageReferenceException {
EventHandlers mockEventHandlers = Mockito.mock(EventHandlers.class);
BuildConfiguration.Builder builder =
BuildConfiguration.builder()
.setEventHandlers(mockEventHandlers)
.setTargetImageConfiguration(
ImageConfiguration.builder(Mockito.mock(ImageReference.class)).build())
.setBaseImageLayersCacheDirectory(Paths.get("ignored"))
.setApplicationLayersCacheDirectory(Paths.get("ignored"))
.setExecutorService(MoreExecutors.newDirectExecutorService());

builder
.setBaseImageConfiguration(
ImageConfiguration.builder(
ImageReference.parse(
"image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
.build())
.build();
Mockito.verify(mockEventHandlers, Mockito.never())
.dispatch(
LogEvent.warn(
"Base image 'image:tag' does not use a specific image digest - build may not be reproducible"));
TadCordle marked this conversation as resolved.
Show resolved Hide resolved

builder
.setBaseImageConfiguration(
ImageConfiguration.builder(ImageReference.parse("image:tag")).build())
.build();
Mockito.verify(mockEventHandlers)
.dispatch(
LogEvent.warn(
"Base image 'image:tag' does not use a specific image digest - build may not be reproducible"));
}
}