Skip to content

Commit ed3316a

Browse files
committed
Add repository aware caching
1 parent c2d1bbe commit ed3316a

18 files changed

+112
-31
lines changed

dockerfiles/bun-1.1.Dockerfile

Lines changed: 6 additions & 3 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.
@@ -14,4 +15,6 @@ RUN bun install --frozen-lockfile
1415

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

dockerfiles/c-9.2.Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM n0madic/alpine-gcc:9.2.0
3+
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
26
RUN apk add --no-cache --upgrade 'curl>=7.66'
37
RUN apk add --no-cache --upgrade 'curl-dev>=7.66'
48

9+
10+
# Once the heave steps are done, we can copy all files back
11+
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-6.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:6.0-bullseye-slim
23

3-
COPY codecrafters-http-server.csproj /app/codecrafters-http-server.csproj
4-
COPY codecrafters-http-server.sln /app/codecrafters-http-server.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 hello@codecrafters.io.");' > /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-http-server.csproj,codecrafters-http-server.sln"
26+
27+
# Once the heave steps are done, we can copy all files back
28+
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-http-server.csproj /app/codecrafters-http-server.csproj
4-
COPY codecrafters-http-server.sln /app/codecrafters-http-server.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 hello@codecrafters.io.");' > /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-http-server.csproj,codecrafters-http-server.sln"
26+
27+
# Once the heave steps are done, we can copy all files back
28+
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.4.Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM haskell:9.4.6-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-http-server-clone
@@ -30,3 +29,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cp -r /tmp/.stack-work . && stac
3029
RUN chmod +x /codecrafters-precompile.sh
3130

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

dockerfiles/java-21.Dockerfile

Lines changed: 6 additions & 2 deletions
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-http-target
@@ -13,4 +15,6 @@ RUN mv /app/target /app-cached # Is this needed?
1315

1416
# Pre-compile steps
1517
RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-http-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_server.sh" > /codecrafters-precompile.sh
16-
RUN chmod +x /codecrafters-precompile.sh
18+
RUN chmod +x /codecrafters-precompile.sh
19+
# Once the heave steps are done, we can copy all files back
20+
COPY . /app

0 commit comments

Comments
 (0)