Skip to content

Commit ab4e646

Browse files
authoredJun 10, 2024··
Merge pull request #219 from codecrafters-io/fix-rust
Use repository-aware caching for Redis/Rust
2 parents 3c98095 + 8dade18 commit ab4e646

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
 

‎dockerfiles/rust-1.77.Dockerfile

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM rust:1.77-buster
23

3-
COPY Cargo.toml /app/Cargo.toml
4-
COPY Cargo.lock /app/Cargo.lock
4+
WORKDIR /app
55

6-
RUN mkdir /app/src
7-
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
6+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
7+
COPY --exclude=.git --exclude=README.md . /app
88

9-
WORKDIR /app
109
RUN cargo build --release --target-dir=/tmp/codecrafters-redis-target
1110

1211
RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
1312
RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust.d
1413

14+
# Build caching schenanigans, see if this can be simplified
1515
RUN find /tmp/codecrafters-redis-target/release -type f -maxdepth 1 -delete
1616
RUN rm -f /tmp/codecrafters-redis-target/release/deps/*redis_starter_rust*
1717
RUN rm -f /tmp/codecrafters-redis-target/release/deps/redis_starter_rust*
@@ -25,3 +25,5 @@ RUN chmod +x /codecrafters-precompile.sh
2525

2626
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
2727

28+
# Once the heavy steps are done, we can copy all files back
29+
COPY . /app

‎dockerfiles/zig-0.12.Dockerfile

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM alpine:3.19
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM alpine:3.20
23

34
# Add the testing repository
45
RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
@@ -17,5 +18,15 @@ RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /et
1718
# Update the package list and install Zig
1819
RUN apk add --no-cache zig@community=0.12.0-r0
1920

21+
WORKDIR /app
22+
23+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
24+
COPY --exclude=.git --exclude=README.md . /app
25+
26+
RUN zig build
27+
2028
RUN printf "set -e \ncd \${CODECRAFTERS_SUBMISSION_DIR} \necho 'Running zig build' \nzig build \necho 'zig build completed.' \n" > /codecrafters-precompile.sh
2129
RUN chmod +x /codecrafters-precompile.sh
30+
31+
# Once the heavy steps are done, we can copy all files back
32+
COPY . /app

0 commit comments

Comments
 (0)
Please sign in to comment.