Skip to content

Commit 82b56af

Browse files
authored
.dockerignore, Dockerfile: add a zig cache (#59)
It took Exercism much longer to run the tests for a Zig exercise than it should. This was because Zig had never been run in the container before test time, and there was no compilation cache in the image. Let's try an initial simple approach: run `zig test` once (for `tests/example-success`) and copy the resulting zig cache into the image. This seems like a 2.2x speedup when later testing a typical exercise, at the cost of adding a 41 MB zig cache to the image: 33 MB /root/.cache/zig/z/ 8 MB /root/.cache/zig/o/ 22 kB /root/.cache/zig/h/ Later, I believe we can speed up further by caching the result of compiling more functions from e.g. std.testing. Closes: #28
1 parent 9d7c3f2 commit 82b56af

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ Dockerfile
1111
bin/run-in-docker.sh
1212
bin/run-tests-in-docker.sh
1313
bin/run-tests.sh
14-
tests/

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ RUN tar -xvf ${RELEASE}.tar.xz \
1616
&& rm -rf /tmp/${RELEASE}/doc \
1717
&& mv /tmp/${RELEASE} /opt/zig
1818

19+
# Initialize a zig cache
20+
ENV PATH=$PATH:/opt/zig
21+
WORKDIR /opt/test-runner
22+
COPY tests/example-success/example_success.zig init-zig-cache/
23+
COPY tests/example-success/test_example_success.zig init-zig-cache/
24+
RUN zig test init-zig-cache/test_example_success.zig \
25+
&& rm -rf init-zig-cache/
26+
1927
FROM ${REPO}:${IMAGE} AS runner
2028

2129
# install packages required to run the tests
2230
# hadolint ignore=DL3018
2331
RUN apk add --no-cache bash jq
2432

2533
COPY --from=builder /opt/zig/ /opt/zig/
34+
COPY --from=builder /root/.cache/zig/ /root/.cache/zig/
2635
ENV PATH=$PATH:/opt/zig
2736

2837
WORKDIR /opt/test-runner
29-
COPY . .
38+
COPY bin/run.sh bin/run.sh
3039
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]

0 commit comments

Comments
 (0)