Skip to content

Commit b7a1ac5

Browse files
dnestorofniephaus
andauthored
Adjust docker and grype tasks (#355)
* Change the way DockerUtils fetch allowed images * Remove AllowedDockerImages.txt * Update the extending docker images list documentation * Remove unnecessary print * Update CONTRIBUTING.md Co-authored-by: Fabio Niephaus <[email protected]> * Update CONTRIBUTING.md Co-authored-by: Fabio Niephaus <[email protected]> * Update CONTRIBUTING.md Co-authored-by: Fabio Niephaus <[email protected]> * Update CONTRIBUTING.md Co-authored-by: Fabio Niephaus <[email protected]> * Assert that dockerfiles will contain only one line * Replace bulk add with single element add * Add missing space Co-authored-by: Fabio Niephaus <[email protected]> --------- Co-authored-by: Fabio Niephaus <[email protected]>
1 parent b752f73 commit b7a1ac5

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,29 @@ In this example this can be done by invoking following command from the reposito
239239

240240
### Providing the tests that use docker
241241

242-
If your tests use docker (either with explicit docker process invocation or through some library method call), all images
243-
have to be declared in `required-docker-images.txt` file. This file must be placed under `/tests/src/<groupId>/<artifactId>/<versionId>`.
242+
If your tests use Docker (either with explicit Docker process invocation or through some library method call), all images have to be declared in `required-docker-images` file.
243+
This file must be placed under `/tests/src/<groupId>/<artifactId>/<versionId>`.
244244

245-
Only docker images that are listed [here](https://github.com/oracle/graalvm-reachability-metadata/blob/master/tests/tck-build-logic/src/main/resources/AllowedDockerImages.txt)
246-
can be executed. If you want to extend this list, please create separate pull request to do that, and post the result of the following command on your pull request:
245+
Only Docker images that are listed in the [`allowed-docker-images` directory](https://github.com/oracle/graalvm-reachability-metadata/blob/master/tests/tck-build-logic/src/main/resources/allowed-docker-images) can be used for testing.
246+
If you want to extend this list, please create separate pull request to do that.
247+
That pull request should add a new file in the [`allowed-docker-images` directory](https://github.com/oracle/graalvm-reachability-metadata/blob/master/tests/tck-build-logic/src/main/resources/allowed-docker-images)
248+
with the name in the format `Dockerfile-<dockerImageName>` (replace all occurrence of `/` with `_`) .
249+
The only line that this file needs to contain is `FROM <dockerImageName>`.
250+
Once you have opened such a pull request, please post the result of the following command in your pull request description:
247251

248252
```shell
249253
grype <dockerImageName>
250254
```
251255

252256
Possible scenarios:
253-
* If your test uses docker image, and you didn't specify it in the `required-docker-images.txt` file, the test will fail.
254-
* If your test uses docker image that is not listed in [allowed docker images list](https://github.com/oracle/graalvm-reachability-metadata/blob/master/tests/tck-build-logic/src/main/resources/AllowedDockerImages.txt),
257+
* If your test uses Docker image, and you didn't specify it in the `required-docker-images.txt` file, the test will fail.
258+
* If your test uses Docker image that is not listed in [allowed docker images list](https://github.com/oracle/graalvm-reachability-metadata/blob/master/tests/tck-build-logic/src/main/resources/AllowedDockerImages.txt),
255259
the test will fail
256260
* Only docker images that are in both `required-docker-images.txt` and in the `allowed docker images list`
257261
can be executed.
258262

263+
**Note:** For images that comes from Oracle, please consider using them from the official [Oracle Container Registry](https://container-registry.oracle.com).
264+
See an [example](https://github.com/oracle/graalvm-reachability-metadata/blob/master/tests/tck-build-logic/src/main/resources/allowed-docker-images/Dockerfile-mysql_mysql-server).
259265

260266
## Tested Libraries and Frameworks
261267

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
package org.graalvm.internal.tck;
22

3+
import java.io.File;
34
import java.io.IOException;
5+
import java.net.URI;
6+
import java.net.URISyntaxException;
47
import java.nio.file.Files;
8+
import java.nio.file.Path;
59
import java.nio.file.Paths;
610
import java.util.HashSet;
11+
import java.util.List;
712
import java.util.Set;
13+
import java.util.stream.Collectors;
814

915
public class DockerUtils {
1016

11-
public static Set<String> getAllowedImages() throws IOException {
12-
return new HashSet<>(Files.readAllLines(Paths.get("./tests/tck-build-logic/src/main/resources/AllowedDockerImages.txt")));
17+
public static Set<String> getAllowedImages() throws IOException, URISyntaxException {
18+
String dockerfileDirectory = Paths.get("./tests/tck-build-logic/src/main/resources/allowed-docker-images").toString();
19+
File[] dockerFiles = new File(dockerfileDirectory).listFiles();
20+
if (dockerFiles == null) {
21+
throw new RuntimeException("Cannot find allowed-docker-images directory content");
22+
}
23+
24+
final String FROM = "FROM";
25+
Set<String> allowedImages = new HashSet<>();
26+
for (File dockerFile : dockerFiles) {
27+
List<String> images = Files.readAllLines(dockerFile.toPath())
28+
.stream()
29+
.filter(line -> line.startsWith(FROM))
30+
.map(line -> line.substring(FROM.length()).trim())
31+
.toList();
32+
if (images.size() != 1) {
33+
throw new RuntimeException("Dockerfile: " + dockerFile.getName() + " must contain only one FROM line, got '" + images.size() + "' (" + images + "). Please read our documentation: "
34+
+ new URI("https://github.com/oracle/graalvm-reachability-metadata/blob/master/CONTRIBUTING.md#providing-the-tests-that-use-docker"));
35+
}
36+
37+
allowedImages.add(images.get(0));
38+
}
39+
40+
return allowedImages;
1341
}
1442

1543
}

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/GrypeTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import javax.inject.Inject;
1010
import java.io.*;
11+
import java.net.URISyntaxException;
1112
import java.util.*;
1213
import java.util.function.Predicate;
1314

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

2324
@TaskAction
24-
void run() throws IllegalStateException, IOException {
25+
void run() throws IllegalStateException, IOException, URISyntaxException {
2526
List<String> vulnerableImages = new ArrayList<>();
2627
Set<String> allowedImages = getAllowedImages();
2728
boolean shouldFail = false;

tests/tck-build-logic/src/main/resources/AllowedDockerImages.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)