Skip to content

Commit

Permalink
Merge pull request #219 from codecrafters-io/fix-rust
Browse files Browse the repository at this point in the history
Use repository-aware caching for Redis/Rust
  • Loading branch information
rohitpaulk authored Jun 10, 2024
2 parents 3c98095 + 8dade18 commit ab4e646
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 7 additions & 5 deletions dockerfiles/rust-1.77.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# syntax=docker/dockerfile:1.7-labs
FROM rust:1.77-buster

COPY Cargo.toml /app/Cargo.toml
COPY Cargo.lock /app/Cargo.lock
WORKDIR /app

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

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

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

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

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

# Once the heavy steps are done, we can copy all files back
COPY . /app
13 changes: 12 additions & 1 deletion dockerfiles/zig-0.12.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM alpine:3.19
# syntax=docker/dockerfile:1.7-labs
FROM alpine:3.20

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

WORKDIR /app

# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
COPY --exclude=.git --exclude=README.md . /app

RUN zig build

RUN printf "set -e \ncd \${CODECRAFTERS_SUBMISSION_DIR} \necho 'Running zig build' \nzig build \necho 'zig build completed.' \n" > /codecrafters-precompile.sh
RUN chmod +x /codecrafters-precompile.sh

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

0 comments on commit ab4e646

Please sign in to comment.