Skip to content

Commit 3f2c0c2

Browse files
authored
Dockerfile: create zig cache later (#69)
Two recent commits [1][2] tried to speed up running user solutions in production, but weren't sufficient. Make the `ziggy` user, rather than the user in the earlier stage, create the cache. This is a worse Dockerfile pattern [3], but it might help Zig to use the cache. A zig cache directory like `~/.cache/zig` contains an `h` subdirectory, with `.txt` files like: 0 18137 11111111 1692020106000000000 0d5def4e330aca188b4480e29786a6c0 1 c.zig 18137 11111111 1692020106000000000 0d5def4e330aca188b4480e29786a6c0 1 c.zig 9163 22222222 1692020106000000000 514b9d62f95db9ea86d2cd5008c5d946 1 std/std.zig 9163 22222222 1692020106000000000 514b9d62f95db9ea86d2cd5008c5d946 1 std/std.zig 22609 33333333 1692020106000000000 0538267a6cdadf6d7dadf7693fce1bed 1 std/start.zig [...] It looks like the format is [4]: manifest header (0), then rows of: {size} {inode} {mtime_ns}, {crypto.auth.siphash.SipHash128 hash} {prefix} {sub_path} where the prefixes are commented as: /// A set of strings such as the zig library directory or project source root, which /// are stripped from the file paths before putting into the cache. They /// are replaced with single-character indicators. This is not to save /// space but to eliminate absolute file paths. This improves portability /// and usefulness of the cache for advanced use cases. but maybe the cache didn't allow what we were doing before this commit: creating it with one user at some location, then moving it to another location to be used by a different user. If this commit still isn't sufficient, we could try updating Zig. Exercism currently uses the Zig 0.11.0 release, which doesn't include a recent commit for the zig cache system [5]. Refs: #63 [1] 82b56af, 2023-08-23, ".dockerignore, Dockerfile: add a zig cache" [2] b8b9d02, 2023-08-27, "Dockerfile, bin(run-tests), tests: set USER" [3] https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#use-multi-stage-builds [4] https://github.com/ziglang/zig/blob/0.11.0/lib/std/Build/Cache.zig#L840-L851 [5] ziglang/zig@020105d0dde6 2023-08-20, "Cache: Fix findPrefix when paths are slightly out of the ordinary"
1 parent b8b9d02 commit 3f2c0c2

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

Dockerfile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ RUN tar -xvf ${RELEASE}.tar.xz \
1717
&& rm -rf /tmp/${RELEASE}/lib/libc/include/any-windows-any \
1818
&& mv /tmp/${RELEASE} /opt/zig
1919

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

3022
# install packages required to run the tests
@@ -34,10 +26,14 @@ RUN apk add --no-cache jq
3426
RUN addgroup ziggroup \
3527
&& adduser --disabled-password --gecos ziggy --ingroup ziggroup ziggy
3628
COPY --from=builder --chown=ziggy:ziggroup /opt/zig/ /opt/zig/
37-
COPY --from=builder --chown=ziggy:ziggroup /root/.cache/zig/ /home/ziggy/.cache/zig/
3829
ENV PATH=$PATH:/opt/zig
3930

4031
USER ziggy:ziggroup
4132
WORKDIR /opt/test-runner
4233
COPY --chown=ziggy:ziggroup bin/run.sh bin/run.sh
34+
# Initialize a zig cache
35+
COPY --chown=ziggy:ziggroup tests/example-success/example_success.zig init-zig-cache/
36+
COPY --chown=ziggy:ziggroup tests/example-success/test_example_success.zig init-zig-cache/
37+
RUN zig test init-zig-cache/test_example_success.zig \
38+
&& rm -rf init-zig-cache/
4339
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]

0 commit comments

Comments
 (0)