Skip to content

Commit

Permalink
Allow parsing of scratch as an image string (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
loosebazooka authored Jun 20, 2019
1 parent 23beaa1 commit ab22479
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit ab22479

Please sign in to comment.