Skip to content

Commit e4d4bda

Browse files
committed
CC-1333 Add repository aware caching
1 parent e8014c5 commit e4d4bda

20 files changed

+120
-38
lines changed

dockerfiles/bun-1.1.Dockerfile

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

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb"
45

56
WORKDIR /app
67

7-
COPY package.json ./
8-
COPY bun.lockb ./
8+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
9+
COPY --exclude=.git --exclude=README.md . /app
910

1011
# For reproducible builds.
1112
# This will install the exact versions of each package specified in the lockfile.
@@ -15,3 +16,6 @@ RUN bun install --frozen-lockfile
1516
RUN mkdir -p /app-cached
1617
# If the node_modules directory exists, move it to /app-cached
1718
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
19+
20+
# Once the heave steps are done, we can copy all files back
21+
COPY . /app

dockerfiles/dotnet-6.0.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim
23

3-
COPY codecrafters-sqlite.csproj /app/codecrafters-sqlite.csproj
4-
COPY codecrafters-sqlite.sln /app/codecrafters-sqlite.sln
54

65
RUN mkdir /app/src
76
RUN (echo 'System.Console.WriteLine("If you are seeing this, there is something wrong with our caching mechanism! Please contact us at [email protected].");' > /app/src/Program.cs) > /dev/null
87

98
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
1011

1112
# This saves nuget packages to ~/.nuget
1213
RUN dotnet build --configuration Release .
@@ -22,3 +23,6 @@ RUN chmod +x /codecrafters-precompile.sh
2223

2324
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-sqlite.csproj,codecrafters-sqlite.sln"
2425

26+
27+
# Once the heave steps are done, we can copy all files back
28+
COPY . /app

dockerfiles/dotnet-8.0.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine
23

3-
COPY codecrafters-sqlite.csproj /app/codecrafters-sqlite.csproj
4-
COPY codecrafters-sqlite.sln /app/codecrafters-sqlite.sln
54

65
RUN mkdir /app/src
76
RUN (echo 'System.Console.WriteLine("If you are seeing this, there is something wrong with our caching mechanism! Please contact us at [email protected].");' > /app/src/Program.cs) > /dev/null
87

98
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
1011

1112
# This saves nuget packages to ~/.nuget
1213
RUN dotnet build --configuration Release .
@@ -22,3 +23,6 @@ RUN chmod +x /codecrafters-precompile.sh
2223

2324
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-sqlite.csproj,codecrafters-sqlite.sln"
2425

26+
27+
# Once the heave steps are done, we can copy all files back
28+
COPY . /app

dockerfiles/go-1.16.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.16-alpine
23

3-
COPY go.mod /app/go.mod
4-
COPY go.sum /app/go.sum
54

65
WORKDIR /app
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
78

89
RUN go mod download
910

@@ -13,3 +14,6 @@ RUN go mod download
1314
RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get"
1415

1516
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
17+
18+
# Once the heave steps are done, we can copy all files back
19+
COPY . /app

dockerfiles/go-1.19.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.19-alpine
23

3-
COPY go.mod /app/go.mod
4-
COPY go.sum /app/go.sum
54

65
WORKDIR /app
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
78

89
RUN go mod download
910

@@ -13,3 +14,6 @@ RUN go mod download
1314
RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get"
1415

1516
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
17+
18+
# Once the heave steps are done, we can copy all files back
19+
COPY . /app

dockerfiles/go-1.21.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.19-alpine
23

3-
COPY go.mod /app/go.mod
4-
COPY go.sum /app/go.sum
54

65
WORKDIR /app
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
78

89
RUN go mod download
910

@@ -17,3 +18,6 @@ RUN GODEBUG="installgoroot=all" go install std
1718
RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get"
1819

1920
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
21+
22+
# Once the heave steps are done, we can copy all files back
23+
COPY . /app

dockerfiles/go-1.22.Dockerfile

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

3-
COPY go.mod /app/go.mod
4-
COPY go.sum /app/go.sum
54

65
WORKDIR /app
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
78

89
RUN go mod download
910

@@ -17,3 +18,6 @@ RUN GODEBUG="installgoroot=all" go install std
1718
RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get"
1819

1920
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
21+
22+
# Once the heave steps are done, we can copy all files back
23+
COPY . /app

dockerfiles/java-21.Dockerfile

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

3-
COPY pom.xml /app/pom.xml
44

55
WORKDIR /app
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
68

79
# Download the dependencies
810
RUN mvn -B package -Ddir=/tmp/codecrafters-sqlite-target
@@ -14,3 +16,6 @@ RUN mv /app/target /app-cached # Is this needed?
1416
# Pre-compile steps
1517
RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-sqlite-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_sqlite3.sh" > /codecrafters-precompile.sh
1618
RUN chmod +x /codecrafters-precompile.sh
19+
20+
# Once the heave steps are done, we can copy all files back
21+
COPY . /app

dockerfiles/nodejs-21.Dockerfile

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

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,package-lock.json"
45

56
WORKDIR /app
67

7-
COPY package.json ./
8-
COPY package-lock.json ./
8+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
9+
COPY --exclude=.git --exclude=README.md . /app
910

1011
# 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.
1112
RUN npm ci
1213

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

dockerfiles/python-3.11.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM python:3.11-alpine
23

34
RUN pip install --no-cache-dir "pipenv>=2023.12.1"
45

5-
COPY Pipfile /app/Pipfile
6-
COPY Pipfile.lock /app/Pipfile.lock
76

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

1011
ENV LANG="en_US.UTF-8"
1112
ENV PIPENV_VENV_IN_PROJECT=1
@@ -20,3 +21,6 @@ RUN mkdir -p /app-cached
2021
RUN mv /app/.venv /app-cached/.venv
2122

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

dockerfiles/python-3.12.Dockerfile

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

34
RUN pip install --no-cache-dir "pipenv>=2023.12.1"
45

5-
COPY Pipfile /app/Pipfile
6-
COPY Pipfile.lock /app/Pipfile.lock
76

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

1011
ENV LANG="en_US.UTF-8"
1112
ENV PIPENV_VENV_IN_PROJECT=1
@@ -20,3 +21,6 @@ RUN mkdir -p /app-cached
2021
RUN mv /app/.venv /app-cached/.venv
2122

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

dockerfiles/python-3.8.Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM jfloff/alpine-python:3.8
23

34
RUN pip install --no-cache-dir "pipenv>=2023.12.1"
45

5-
COPY Pipfile /app/Pipfile
6-
COPY Pipfile.lock /app/Pipfile.lock
76

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

1011
ENV LANG="en_US.UTF-8"
1112
ENV PIPENV_VENV_IN_PROJECT=1
@@ -20,3 +21,6 @@ RUN mkdir -p /app-cached
2021
RUN mv /app/.venv /app-cached/.venv
2122

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

dockerfiles/ruby-3.3.Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM ruby:3.3-alpine
23

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Gemfile,Gemfile.lock"
45

56
WORKDIR /app
67

7-
COPY Gemfile Gemfile.lock ./
8+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
9+
COPY --exclude=.git --exclude=README.md . /app
810

911
RUN bundle install --verbose
12+
13+
# Once the heave steps are done, we can copy all files back
14+
COPY . /app

dockerfiles/rust-1.43.Dockerfile

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

3-
COPY Cargo.toml /app/Cargo.toml
4-
COPY Cargo.lock /app/Cargo.lock
54

65
RUN mkdir /app/src
76
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
87

98
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
1011
RUN cargo build --release --target-dir=/tmp/codecrafters-sqlite-target
1112

1213
RUN rm /tmp/codecrafters-sqlite-target/release/sqlite-starter-rust
@@ -22,3 +23,6 @@ RUN rm -rf /app/src
2223

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

26+
27+
# Once the heave steps are done, we can copy all files back
28+
COPY . /app

dockerfiles/rust-1.54.Dockerfile

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

3-
COPY Cargo.toml /app/Cargo.toml
4-
COPY Cargo.lock /app/Cargo.lock
54

65
RUN mkdir /app/src
76
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
87

98
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
1011
RUN cargo build --release --target-dir=/tmp/codecrafters-sqlite-target
1112

1213
RUN rm /tmp/codecrafters-sqlite-target/release/sqlite-starter-rust
@@ -25,3 +26,6 @@ RUN chmod +x /codecrafters-precompile.sh
2526

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

29+
30+
# Once the heave steps are done, we can copy all files back
31+
COPY . /app

dockerfiles/rust-1.62.Dockerfile

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

3-
COPY Cargo.toml /app/Cargo.toml
4-
COPY Cargo.lock /app/Cargo.lock
54

65
RUN mkdir /app/src
76
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
87

98
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
1011
RUN cargo build --release --target-dir=/tmp/codecrafters-sqlite-target
1112

1213
RUN rm /tmp/codecrafters-sqlite-target/release/sqlite-starter-rust
@@ -25,3 +26,6 @@ RUN chmod +x /codecrafters-precompile.sh
2526

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

29+
30+
# Once the heave steps are done, we can copy all files back
31+
COPY . /app

dockerfiles/rust-1.68.Dockerfile

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

3-
COPY Cargo.toml /app/Cargo.toml
4-
COPY Cargo.lock /app/Cargo.lock
54

65
RUN mkdir /app/src
76
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
87

98
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
1011
RUN cargo build --release --target-dir=/tmp/codecrafters-sqlite-target
1112

1213
RUN rm /tmp/codecrafters-sqlite-target/release/sqlite-starter-rust
@@ -25,3 +26,6 @@ RUN chmod +x /codecrafters-precompile.sh
2526

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

29+
30+
# Once the heave steps are done, we can copy all files back
31+
COPY . /app

dockerfiles/rust-1.70.Dockerfile

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

3-
COPY Cargo.toml /app/Cargo.toml
4-
COPY Cargo.lock /app/Cargo.lock
54

65
RUN mkdir /app/src
76
RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
87

98
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
1011
RUN cargo build --release --target-dir=/tmp/codecrafters-sqlite-target
1112

1213
RUN rm /tmp/codecrafters-sqlite-target/release/sqlite-starter-rust
@@ -25,3 +26,6 @@ RUN chmod +x /codecrafters-precompile.sh
2526

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

29+
30+
# Once the heave steps are done, we can copy all files back
31+
COPY . /app

0 commit comments

Comments
 (0)