-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (59 loc) · 2.38 KB
/
Copy pathDockerfile
File metadata and controls
74 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
############################# START SHARED LAYERS #############################
# IMPORTANT: This part of the build is shared between the test-runner and
# analyzer. It takes a relatively large amount of space: 850 MB for the Rust
# toolchain and 40 MB for the local cargo registry. Therefore, it's important
# to keep this in sync between the two images. A slight mismatch in these layers
# would lead to douple the storage requirement on Exercism's servers.
FROM rust:1.95.0-trixie AS build-local-registry
WORKDIR /work
COPY local-registry/Cargo.toml .
RUN <<EOF
set -eux
apt-get update
apt-get install -y gcc openssl cmake
cargo install --locked cargo-local-registry
cargo generate-lockfile
cargo local-registry sync Cargo.lock /local-registry
EOF
# As of April 2026, we need to use the nightly toolchain to get JSON test output
# tracking issue: https://github.com/rust-lang/rust/issues/49359
#
# The official docker image for the nightly Rust toolchain is updated every
# day. We don't want to invalidate the build cache that often, so we pin it
# to a specific hash. To update, go to the following page, then navigate to
# "nightly-slim", select "linux/amd64" and copy the manifest digest.
# https://hub.docker.com/r/rustlang/rust/tags
#
FROM docker.io/rustlang/rust@sha256:3444fefbb69afbff45c0722c8045404c8e7f369c5202e916bd94f665b69f1b1c AS rust-nightly-with-local-registry
# add local registry
COPY --from=build-local-registry /local-registry /local-registry
RUN <<EOF
echo "\
[source.crates-io]
registry = 'sparse+https://index.crates.io/'
replace-with = 'local-registry'
[source.local-registry]
local-registry = '/local-registry'" >> $CARGO_HOME/config.toml
EOF
############################## END SHARED LAYERS ##############################
FROM rust:1.95.0-trixie AS build
WORKDIR /work
COPY Cargo.* ./
# for caching, we want to download and build all the dependencies before copying
# any of the real source files. We therefore build an empty dummy library,
# then remove it.
RUN <<EOF
mkdir --parents src
touch src/lib.rs
cargo build --release
rm src/lib.rs
EOF
# now build the real test-runner
COPY src/* src/
RUN touch src/lib.rs && cargo build --release
FROM rust-nightly-with-local-registry
RUN apt-get update && apt-get install -y jq && rm -rf /var/lib/apt/lists/*
WORKDIR /opt/test-runner
COPY --from=build /work/target/release/rust_test_runner bin/
COPY bin/run.sh bin/
ENTRYPOINT ["bin/run.sh"]