Skip to content

Commit 020c813

Browse files
committed
Fold create-checkpoint.sh into build-crac-checkpoint-image.sh and add docs
1 parent 22c00c1 commit 020c813

File tree

3 files changed

+66
-45
lines changed

3 files changed

+66
-45
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ An [Exercism test runner][test-runner-docs] automatically verifies if a submissi
44

55
This repository contains the Java test runner, which implements the V3 spec of the [test runner interface][test-runner-interface-docs].
66

7+
This test runner uses [CRaC (Coordinated Restore at Checkpoint)](https://crac.org/) to speed up execution.
8+
The build logic is implemented and documented in [bin/build-crac-checkpoint-image.sh](bin/build-crac-checkpoint-image.sh).
9+
If you change this logic you might also have to adjust the GitHub [deploy action](.github/workflows/deploy.yml).
10+
711
## Run the test runner
812

913
To run the tests of an arbitrary exercise, do the following:
@@ -31,11 +35,11 @@ To run the tests to verify the behavior of the test runner, do the following:
3135
1. Open a terminal in the project's root
3236
2. Run `./bin/run-tests.sh`
3337

34-
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code
38+
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code
3539
against the "known good" `tests/<test-name>/expected_results.json`.
3640
All files created during the test run itself are discarded.
3741

38-
When you've made modifications to the code that will result in a new "golden" state,
42+
When you've made modifications to the code that will result in a new "golden" state,
3943
you'll need to generate and commit a new `tests/<test-name>/expected_results.json` file.
4044

4145
## Run the tests using Docker
@@ -47,11 +51,11 @@ To run the tests to verify the behavior of the test runner using the Docker imag
4751
1. Open a terminal in the project's root
4852
2. Run `./bin/run-tests-in-docker.sh`
4953

50-
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code
51-
against the "known good" `tests/<test-name>/expected_results.json`.
54+
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code
55+
against the "known good" `tests/<test-name>/expected_results.json`.
5256
All files created during the test run itself are discarded.
5357

54-
When you've made modifications to the code that will result in a new "golden" state,
58+
When you've made modifications to the code that will result in a new "golden" state,
5559
you'll need to generate and commit a new `tests/<test-name>/expected_results.json` file.
5660

5761
[test-runner-docs]: https://exercism.org/docs/building/tooling/test-runners

bin/build-crac-checkpoint-image.sh

+57-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,66 @@
33
# Synopsis:
44
# Build a Docker image containing a CraC checkpoint to restart from.
55
# An initial image is built. A container is created from that image
6-
# and tests are run to warm up the JVM. Then a checkpoint is created.
7-
# The final image is created by committing the containiner
8-
# containing the checkpoint.
6+
# and tests are run to warm up the JVM. Once the runner has finished running
7+
# all the tests it creates a checkpoint of the VM process before exiting.
8+
# This checkpoint is written to the host file system, so it can be copied
9+
# into the final image.
10+
# Then the final image is created, which restores from the checkpoint
11+
# instead of starting a new JVM
12+
# This avoids slow JVM start up and JVM warm up costs.
13+
#
14+
# Example:
15+
# ./bin/build-crac-checkpoint-image.sh
916

10-
# build outside of Docker container, so we can copy jar into both images
17+
create_checkpoint() {
18+
# Copy all tests into one merged project, so we can warm up the JVM
19+
# TODO(FAP): this is missing some tests as most tests use the same filenames
20+
mkdir -p tests/merged
21+
for dir in tests/*; do
22+
if [ -d "$dir" ] && [ "$dir" != "tests/merged/" ]; then
23+
rsync -a "$dir"/ tests/merged/
24+
fi
25+
done
26+
27+
real_path() {
28+
echo "$(cd "$(dirname -- "$1")" >/dev/null; pwd -P)/$(basename -- "$1")";
29+
}
30+
31+
mkdir -p build/cr
32+
33+
image_tag="$1"
34+
slug="merged"
35+
solution_dir=$(realpath "tests/merged/")
36+
output_dir=$(realpath "tests/merged/")
37+
38+
docker run --cap-add CHECKPOINT_RESTORE \
39+
--cap-add SYS_PTRACE \
40+
--name java-test-runner-crac \
41+
--network none \
42+
--mount type=bind,src="${solution_dir}",dst=/solution \
43+
--mount type=bind,src="${output_dir}",dst=/output \
44+
--mount type=bind,src="$(real_path build/cr)",dst=/opt/test-runner/crac-checkpoint \
45+
--mount type=tmpfs,dst=/tmp \
46+
"${image_tag}" "${slug}" /solution /output
47+
48+
docker rm -f java-test-runner-crac
49+
rm -rf tests/merged/
50+
}
51+
52+
# 1. Build jar outside of Docker, so we can copy the jar into both images
53+
echo "build-crac-checkpoint-image.sh: Building jar with Gradle"
1154
./gradlew build
1255

13-
docker build -t exercism/java-test-runner-crac-checkpoint -f Dockerfile.createCheckpoint .
56+
image_tag="exercism/java-test-runner-crac-checkpoint"
57+
58+
# 2. Build first image with an entrypoint that will create a CraC checkpoint
59+
echo "build-crac-checkpoint-image.sh: Building image that creates CraC checkpoint"
60+
docker build -t "$image_tag" -f Dockerfile.createCheckpoint .
1461

15-
bin/create-checkpoint.sh
62+
# 3. Run a container from image created in step 2 and create CraC checkpoint
63+
echo "build-crac-checkpoint-image.sh: Creating CraC checkpoint"
64+
create_checkpoint "$image_tag"
1665

66+
# Build final test runner image, includes the jar and the checkpoint created in step 1 and 3
67+
echo "build-crac-checkpoint-image.sh: Building final test runner image"
1768
docker build -t exercism/java-test-runner -f Dockerfile .

bin/create-checkpoint.sh

-34
This file was deleted.

0 commit comments

Comments
 (0)