Skip to content

Commit cb76caa

Browse files
committed
Add repository aware caching
1 parent ea84352 commit cb76caa

7 files changed

+43
-15
lines changed

dockerfiles/bun-1.1.Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM oven/bun:1.1.4-alpine
23

34
# We need to install Go to build the custom executable.
@@ -7,8 +8,8 @@ ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb"
78

89
WORKDIR /app
910

10-
COPY package.json ./
11-
COPY bun.lockb ./
11+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
12+
COPY --exclude=.git --exclude=README.md . /app
1213

1314
# For reproducible builds.
1415
# This will install the exact versions of each package specified in the lockfile.
@@ -17,4 +18,6 @@ RUN bun install --frozen-lockfile
1718

1819
RUN mkdir -p /app-cached
1920
# If the node_modules directory exists, move it to /app-cached
20-
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
21+
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
22+
# Once the heave steps are done, we can copy all files back
23+
COPY . /app

dockerfiles/c-9.2.Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM n0madic/alpine-gcc:9.2.0
23

4+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
5+
COPY --exclude=.git --exclude=README.md . /app
6+
37
# We need to install Go to build the custom executable.
4-
RUN apk add --no-cache "go>=1.12"
8+
RUN apk add --no-cache "go>=1.12"
9+
# Once the heave steps are done, we can copy all files back
10+
COPY . /app

dockerfiles/go-1.22.Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.22-alpine
23

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
@@ -9,10 +10,14 @@ ENV GOCACHE=/cache
910

1011
WORKDIR /app
1112

12-
COPY go.mod go.sum ./
13+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
14+
COPY --exclude=.git --exclude=README.md . /app
1315

1416
# Starting from Go 1.20, the go standard library is no loger compiled
1517
# setting the GODEBUG environment to "installgoroot=all" restores the old behavior
1618
RUN GODEBUG="installgoroot=all" go install std
1719

1820
RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get"
21+
22+
# Once the heave steps are done, we can copy all files back
23+
COPY . /app

dockerfiles/java-21.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM maven:3.9.5-eclipse-temurin-21-alpine
23

34
# We need to install Go to build the custom executable.
45
RUN apk add --no-cache "go>=1.20"
56

6-
COPY pom.xml /app/pom.xml
77

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

1012
# Download the dependencies
1113
RUN mvn -B package -Ddir=/tmp/codecrafters-shell-target
@@ -16,4 +18,6 @@ RUN mv /app/target /app-cached # Is this needed?
1618

1719
# Pre-compile steps
1820
RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-shell-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_shell.sh" > /codecrafters-precompile.sh
19-
RUN chmod +x /codecrafters-precompile.sh
21+
RUN chmod +x /codecrafters-precompile.sh
22+
# Once the heave steps are done, we can copy all files back
23+
COPY . /app

dockerfiles/nodejs-21.Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM node:21.7-alpine3.19
23

34
# We need to install Go to build the custom executable.
@@ -7,12 +8,14 @@ ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,package-lock.json"
78

89
WORKDIR /app
910

10-
COPY package.json ./
11-
COPY package-lock.json ./
11+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
12+
COPY --exclude=.git --exclude=README.md . /app
1213

1314
# If dependencies in the package lock do not match those in package.json, instead of updating the package lock, npm ci will exit with an error.
1415
RUN npm ci
1516

1617
RUN mkdir -p /app-cached
1718
# If the node_modules directory exists, move it to /app-cached
18-
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
19+
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
20+
# Once the heave steps are done, we can copy all files back
21+
COPY . /app

dockerfiles/python-3.12.Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM python:3.12-alpine
23

34
# We need to install Go to build the custom executable.
45
RUN apk add --no-cache "go>=1.20"
56

67
RUN pip install --no-cache-dir "pipenv>=2023.12.1"
78

8-
COPY Pipfile /app/Pipfile
9-
COPY Pipfile.lock /app/Pipfile.lock
109

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

1314
ENV WORKON_HOME=/venvs
1415

@@ -17,4 +18,6 @@ RUN pipenv install
1718
# Force environment creation
1819
RUN pipenv run python3 -c "1+1"
1920

20-
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock"
21+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock"
22+
# Once the heave steps are done, we can copy all files back
23+
COPY . /app

dockerfiles/rust-1.77.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM rust:1.77-buster
23

34
# We need to install Go to build the custom executable.
45
RUN apt-get update && apt-get install -y --no-install-recommends golang-go=2:* && rm -rf /var/lib/apt/lists/*
56

6-
COPY Cargo.toml /app/Cargo.toml
7-
COPY Cargo.lock /app/Cargo.lock
87

98
RUN mkdir /app/src
109
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
1110

1211
WORKDIR /app
12+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
13+
COPY --exclude=.git --exclude=README.md . /app
1314
RUN cargo build --release --target-dir=/tmp/codecrafters-shell-target
1415

1516
RUN cargo clean -p shell-starter-rust --release --target-dir=/tmp/codecrafters-shell-target
@@ -20,3 +21,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cargo build --release --target-d
2021
RUN chmod +x /codecrafters-precompile.sh
2122

2223
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
24+
25+
# Once the heave steps are done, we can copy all files back
26+
COPY . /app

0 commit comments

Comments
 (0)