Skip to content

Commit 0995862

Browse files
committed
Add repository aware caching
1 parent d9d1fb7 commit 0995862

21 files changed

+131
-32
lines changed

dockerfiles/bun-1.1.Dockerfile

Lines changed: 6 additions & 2 deletions
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/cpp-20.Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM gcc:12.2.0-bullseye
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
RUN apt-get update && \
48
apt-get install --no-install-recommends -y cmake=3.18.* && \
59
apt-get clean && \
610
rm -rf /var/lib/apt/lists/*
11+
12+
# Once the heave steps are done, we can copy all files back
13+
COPY . /app

dockerfiles/dotnet-8.0.Dockerfile

Lines changed: 6 additions & 2 deletions
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-grep.csproj /app/codecrafters-grep.csproj
4-
COPY codecrafters-grep.sln /app/codecrafters-grep.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 echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && dotnet build --configuration Rel
2223
RUN chmod +x /codecrafters-precompile.sh
2324

2425
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-grep.csproj,codecrafters-grep.sln"
26+
27+
# Once the heave steps are done, we can copy all files back
28+
COPY . /app

dockerfiles/gleam-1.0.Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-alpine
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
# Pre-compile steps
48
RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && gleam build" > /codecrafters-precompile.sh
59
RUN chmod +x /codecrafters-precompile.sh
10+
11+
# Once the heave steps are done, we can copy all files back
12+
COPY . /app

dockerfiles/go-1.19.Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.19-alpine
23

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
45

56
WORKDIR /app
67

7-
COPY go.mod go.sum ./
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 ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get"
12+
13+
# Once the heave steps are done, we can copy all files back
14+
COPY . /app

dockerfiles/go-1.21.Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.21-alpine
23

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
45

56
WORKDIR /app
67

7-
COPY go.mod go.sum ./
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
# Starting from Go 1.20, the go standard library is no loger compiled
1012
# setting the GODEBUG environment to "installgoroot=all" restores the old behavior
1113
RUN GODEBUG="installgoroot=all" go install std
1214

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

dockerfiles/go-1.22.Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM golang:1.22-alpine
23

34
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
45

56
WORKDIR /app
67

7-
COPY go.mod go.sum ./
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
# Starting from Go 1.20, the go standard library is no loger compiled
1012
# setting the GODEBUG environment to "installgoroot=all" restores the old behavior
1113
RUN GODEBUG="installgoroot=all" go install std
1214

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

dockerfiles/haskell-9.2.Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM haskell:9.2.5-buster
23

34
WORKDIR /app
@@ -11,13 +12,11 @@ RUN echo "allow-different-user: true" >> /etc/stack/config.yaml
1112
RUN echo "install-ghc: false" >> /etc/stack/config.yaml
1213
RUN echo "system-ghc: true" >> /etc/stack/config.yaml
1314

14-
COPY stack.yaml package.yaml stack.yaml.lock /app/
15+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
16+
COPY --exclude=.git --exclude=README.md . /app
1517

1618
# Dummy static content to circumvent the /app doesn't exist warning
1719
RUN mkdir /app/src
18-
RUN mkdir /app/app
19-
RUN echo 'main :: IO ()' >> /app/app/Main.hs
20-
RUN echo 'main = putStrLn "Hello, World!"' >> /app/app/Main.hs
2120

2221
RUN stack build
2322
RUN stack clean hs-grep-clone
@@ -29,4 +28,6 @@ RUN rm -rf /app/src
2928
RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cp -r /tmp/.stack-work . && stack build" > /codecrafters-precompile.sh
3029
RUN chmod +x /codecrafters-precompile.sh
3130

32-
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock"
31+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock"
32+
# Once the heave steps are done, we can copy all files back
33+
COPY . /app

dockerfiles/nodejs-18.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
FROM node:18.18.0-alpine3.17
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM node:18.18.0-alpine3.17
3+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
4+
COPY --exclude=.git --exclude=README.md . /app
5+
6+
# Once the heave steps are done, we can copy all files back
7+
COPY . /app

dockerfiles/nodejs-21.Dockerfile

Lines changed: 6 additions & 2 deletions
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.10.Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM python:3.10-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 WORKON_HOME=/venvs
1112

@@ -15,3 +16,6 @@ RUN pipenv install
1516
RUN pipenv run python3 -c "1+1"
1617

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

dockerfiles/python-3.11.Dockerfile

Lines changed: 6 additions & 2 deletions
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 WORKON_HOME=/venvs
1112

@@ -15,3 +16,6 @@ RUN pipenv install
1516
RUN pipenv run python3 -c "1+1"
1617

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

dockerfiles/python-3.12.Dockerfile

Lines changed: 6 additions & 2 deletions
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 WORKON_HOME=/venvs
1112

@@ -15,3 +16,6 @@ RUN pipenv install
1516
RUN pipenv run python3 -c "1+1"
1617

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

dockerfiles/ruby-2.7.Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM ruby:2.7-alpine
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
RUN apk add --no-cache --upgrade 'curl>=7.66'
48
RUN apk add --no-cache --upgrade 'curl-dev>=7.66'
59

610
WORKDIR /app
11+
12+
# Once the heave steps are done, we can copy all files back
13+
COPY . /app

dockerfiles/ruby-3.2.Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM ruby:3.2-alpine
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
RUN apk add --no-cache --upgrade 'curl>=7.66'
48
RUN apk add --no-cache --upgrade 'curl-dev>=7.66'
59

610
WORKDIR /app
11+
12+
# Once the heave steps are done, we can copy all files back
13+
COPY . /app

dockerfiles/ruby-3.3.Dockerfile

Lines changed: 6 additions & 1 deletion
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.62.Dockerfile

Lines changed: 6 additions & 2 deletions
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-grep-target
1112

1213
RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target
@@ -18,3 +19,6 @@ RUN chmod +x /codecrafters-precompile.sh
1819

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

22+
23+
# Once the heave steps are done, we can copy all files back
24+
COPY . /app

dockerfiles/rust-1.68.Dockerfile

Lines changed: 6 additions & 2 deletions
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-grep-target
1112

1213
RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target
@@ -18,3 +19,6 @@ RUN chmod +x /codecrafters-precompile.sh
1819

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

22+
23+
# Once the heave steps are done, we can copy all files back
24+
COPY . /app

dockerfiles/rust-1.70.Dockerfile

Lines changed: 6 additions & 2 deletions
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-grep-target
1112

1213
RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target
@@ -18,3 +19,6 @@ RUN chmod +x /codecrafters-precompile.sh
1819

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

22+
23+
# Once the heave steps are done, we can copy all files back
24+
COPY . /app

dockerfiles/rust-1.76.Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM rust:1.76-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-grep-target
1112

1213
RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target
@@ -18,3 +19,6 @@ RUN chmod +x /codecrafters-precompile.sh
1819

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

22+
23+
# Once the heave steps are done, we can copy all files back
24+
COPY . /app

0 commit comments

Comments
 (0)