Skip to content

Commit

Permalink
Assert that dockerfiles will contain only one line
Browse files Browse the repository at this point in the history
  • Loading branch information
dnestoro committed Jul 25, 2023
1 parent 68b588c commit 3ba5c62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -12,7 +14,7 @@

public class DockerUtils {

public static Set<String> getAllowedImages() throws IOException {
public static Set<String> getAllowedImages() throws IOException, URISyntaxException {
String dockerfileDirectory = Paths.get("./tests/tck-build-logic/src/main/resources/allowed-docker-images").toString();
File[] dockerFiles = new File(dockerfileDirectory).listFiles();
if (dockerFiles == null) {
Expand All @@ -27,6 +29,10 @@ public static Set<String> getAllowedImages() throws IOException {
.filter(line -> line.startsWith(FROM))
.map(line -> line.substring(FROM.length()).trim())
.toList();
if (images.size() != 1) {
throw new RuntimeException("Dockerfile: " + dockerFile.getName() + " must contain only one FROM line, got '" + images.size() + "' (" + images+ "). Please read our documentation: "
+ new URI("https://github.com/oracle/graalvm-reachability-metadata/blob/master/CONTRIBUTING.md#providing-the-tests-that-use-docker"));
}

allowedImages.addAll(images);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.inject.Inject;
import java.io.*;
import java.net.URISyntaxException;
import java.util.*;
import java.util.function.Predicate;

Expand All @@ -21,7 +22,7 @@ public abstract class GrypeTask extends DefaultTask {
private final String jqMatcher = " | jq -c '.matches | .[] | .vulnerability | select(.severity | (contains(\"High\") or contains(\"Critical\")))'";

@TaskAction
void run() throws IllegalStateException, IOException {
void run() throws IllegalStateException, IOException, URISyntaxException {
List<String> vulnerableImages = new ArrayList<>();
Set<String> allowedImages = getAllowedImages();
boolean shouldFail = false;
Expand Down

0 comments on commit 3ba5c62

Please sign in to comment.