From ab22479b2079973b0f6c99192b34a32b3e6d8780 Mon Sep 17 00:00:00 2001 From: Appu Date: Thu, 20 Jun 2019 15:20:10 -0400 Subject: [PATCH] Allow parsing of scratch as an image string (#1792) --- .../java/com/google/cloud/tools/jib/api/ImageReference.java | 4 ++++ .../cloud/tools/jib/configuration/BuildConfiguration.java | 4 +++- .../com/google/cloud/tools/jib/api/ImageReferenceTest.java | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageReference.java b/jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageReference.java index e9facae06f..46c23629e6 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageReference.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageReference.java @@ -92,6 +92,10 @@ public class ImageReference { * @throws InvalidImageReferenceException if {@code reference} is formatted incorrectly */ public static ImageReference parse(String reference) throws InvalidImageReferenceException { + if (reference.equals("scratch")) { + return ImageReference.scratch(); + } + Matcher matcher = REFERENCE_PATTERN.matcher(reference); if (!matcher.find() || matcher.groupCount() < 4) { diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildConfiguration.java b/jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildConfiguration.java index 1c9ca20b53..3723eae8a9 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildConfiguration.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildConfiguration.java @@ -244,7 +244,9 @@ public BuildConfiguration build() throws IOException { switch (missingFields.size()) { case 0: // No errors - if (Preconditions.checkNotNull(baseImageConfiguration).getImage().usesDefaultTag()) { + Preconditions.checkNotNull(baseImageConfiguration); + if (baseImageConfiguration.getImage().usesDefaultTag() + && !baseImageConfiguration.getImage().isScratch()) { eventHandlers.dispatch( LogEvent.warn( "Base image '" diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/api/ImageReferenceTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/api/ImageReferenceTest.java index 9519668f96..ef90c027a1 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/api/ImageReferenceTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/api/ImageReferenceTest.java @@ -181,7 +181,8 @@ public void testIsTagDigest() throws InvalidImageReferenceException { } @Test - public void testIsScratch() { + public void testIsScratch() throws InvalidImageReferenceException { + Assert.assertTrue(ImageReference.parse("scratch").isScratch()); Assert.assertTrue(ImageReference.scratch().isScratch()); Assert.assertFalse(ImageReference.of("", "scratch", "").isScratch()); Assert.assertFalse(ImageReference.of(null, "scratch", null).isScratch());