From abc44017f7086d00f2e194a96284e191bb4387ee Mon Sep 17 00:00:00 2001 From: libmartinito Date: Wed, 26 Jun 2024 21:14:44 +0800 Subject: [PATCH] Add repository aware caching --- dockerfiles/bun-1.1.Dockerfile | 8 ++++++-- dockerfiles/cpp-20.Dockerfile | 7 +++++++ dockerfiles/dotnet-8.0.Dockerfile | 8 ++++++-- dockerfiles/go-1.13.Dockerfile | 8 +++++++- dockerfiles/go-1.16.Dockerfile | 7 +++++++ dockerfiles/go-1.19.Dockerfile | 7 ++++++- dockerfiles/go-1.21.Dockerfile | 7 ++++++- dockerfiles/go-1.22.Dockerfile | 7 ++++++- dockerfiles/haskell-9.4.Dockerfile | 10 ++++++---- dockerfiles/java-21.Dockerfile | 8 ++++++-- dockerfiles/kotlin-1.3.72.Dockerfile | 7 +++++++ dockerfiles/kotlin-1.4.Dockerfile | 7 +++++++ dockerfiles/nodejs-18.Dockerfile | 8 +++++++- dockerfiles/nodejs-21.Dockerfile | 8 ++++++-- dockerfiles/python-3.11.Dockerfile | 7 +++++++ dockerfiles/python-3.12.Dockerfile | 7 +++++++ dockerfiles/python-3.7.Dockerfile | 7 +++++++ dockerfiles/python-3.8.Dockerfile | 7 +++++++ dockerfiles/ruby-2.7.Dockerfile | 7 +++++++ dockerfiles/ruby-3.2.Dockerfile | 7 +++++++ dockerfiles/ruby-3.3.Dockerfile | 7 ++++++- dockerfiles/rust-1.62.Dockerfile | 8 ++++++-- dockerfiles/rust-1.68.Dockerfile | 8 ++++++-- dockerfiles/rust-1.70.Dockerfile | 8 ++++++-- dockerfiles/rust-1.76.Dockerfile | 8 ++++++-- dockerfiles/rust-1.77.Dockerfile | 8 ++++++-- 26 files changed, 168 insertions(+), 28 deletions(-) diff --git a/dockerfiles/bun-1.1.Dockerfile b/dockerfiles/bun-1.1.Dockerfile index 8750516..c8ccf1e 100644 --- a/dockerfiles/bun-1.1.Dockerfile +++ b/dockerfiles/bun-1.1.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM oven/bun:1.1.4-alpine RUN apk add --no-cache 'git>=2.40' @@ -6,8 +7,8 @@ ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb" WORKDIR /app -COPY package.json ./ -COPY bun.lockb ./ +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app # For reproducible builds. # This will install the exact versions of each package specified in the lockfile. @@ -17,3 +18,6 @@ RUN bun install --frozen-lockfile RUN mkdir -p /app-cached # If the node_modules directory exists, move it to /app-cached RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/cpp-20.Dockerfile b/dockerfiles/cpp-20.Dockerfile index f397ddc..ae010c5 100644 --- a/dockerfiles/cpp-20.Dockerfile +++ b/dockerfiles/cpp-20.Dockerfile @@ -1,5 +1,9 @@ +# syntax=docker/dockerfile:1.7-labs FROM gcc:12.2.0-bullseye +# .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 apt-get update && \ apt-get install --no-install-recommends -y cmake=3.18.* && \ apt-get clean && \ @@ -7,3 +11,6 @@ RUN apt-get update && \ # TODO: Clean this up when we move to CPP23 RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && cmake . && make && (echo '#!/bin/sh\nexec \${CODECRAFTERS_SUBMISSION_DIR}/server \"\$@\"' > your_git.sh) && chmod +x your_git.sh" > /codecrafters-precompile.sh + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/dotnet-8.0.Dockerfile b/dockerfiles/dotnet-8.0.Dockerfile index 82b6585..bcad7bc 100644 --- a/dockerfiles/dotnet-8.0.Dockerfile +++ b/dockerfiles/dotnet-8.0.Dockerfile @@ -1,14 +1,15 @@ +# syntax=docker/dockerfile:1.7-labs FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine RUN apk add --no-cache 'git>=2.40' -COPY codecrafters-git.csproj /app/codecrafters-git.csproj -COPY codecrafters-git.sln /app/codecrafters-git.sln RUN mkdir /app/src 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 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 # This saves nuget packages to ~/.nuget RUN dotnet build --configuration Release . @@ -24,3 +25,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && dotnet build --configuration Rel RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-git.csproj,codecrafters-git.sln" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/go-1.13.Dockerfile b/dockerfiles/go-1.13.Dockerfile index 50cd354..aa83fc2 100644 --- a/dockerfiles/go-1.13.Dockerfile +++ b/dockerfiles/go-1.13.Dockerfile @@ -1,3 +1,9 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.13-alpine -RUN apk add --no-cache 'git>=2.43' \ No newline at end of file +# .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 apk add --no-cache 'git>=2.43' +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/go-1.16.Dockerfile b/dockerfiles/go-1.16.Dockerfile index e25106f..cf8ed59 100644 --- a/dockerfiles/go-1.16.Dockerfile +++ b/dockerfiles/go-1.16.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.16-alpine +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/go-1.19.Dockerfile b/dockerfiles/go-1.19.Dockerfile index ef2f55c..34fce41 100644 --- a/dockerfiles/go-1.19.Dockerfile +++ b/dockerfiles/go-1.19.Dockerfile @@ -1,11 +1,16 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.19-alpine ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" WORKDIR /app -COPY go.mod go.sum ./ +# .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 ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get" RUN apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/go-1.21.Dockerfile b/dockerfiles/go-1.21.Dockerfile index e1a9bb0..b3cc7fb 100644 --- a/dockerfiles/go-1.21.Dockerfile +++ b/dockerfiles/go-1.21.Dockerfile @@ -1,10 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.21-alpine ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" WORKDIR /app -COPY go.mod go.sum ./ +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app # Starting from Go 1.20, the go standard library is no loger compiled # setting the GODEBUG environment to "installgoroot=all" restores the old behavior @@ -13,3 +15,6 @@ RUN GODEBUG="installgoroot=all" go install std RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get" RUN apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/go-1.22.Dockerfile b/dockerfiles/go-1.22.Dockerfile index 9d9cad7..a20bf10 100644 --- a/dockerfiles/go-1.22.Dockerfile +++ b/dockerfiles/go-1.22.Dockerfile @@ -1,10 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.22-alpine ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" WORKDIR /app -COPY go.mod go.sum ./ +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app # Starting from Go 1.20, the go standard library is no loger compiled # setting the GODEBUG environment to "installgoroot=all" restores the old behavior @@ -13,3 +15,6 @@ RUN GODEBUG="installgoroot=all" go install std RUN ash -c "set -exo pipefail; go mod graph | awk '{if (\$1 !~ \"@\") {print \$2}}' | xargs -r go get" RUN apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/haskell-9.4.Dockerfile b/dockerfiles/haskell-9.4.Dockerfile index 458967a..9b69309 100644 --- a/dockerfiles/haskell-9.4.Dockerfile +++ b/dockerfiles/haskell-9.4.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM haskell:9.4.6-buster WORKDIR /app @@ -11,13 +12,11 @@ RUN echo "allow-different-user: true" >> /etc/stack/config.yaml RUN echo "install-ghc: false" >> /etc/stack/config.yaml RUN echo "system-ghc: true" >> /etc/stack/config.yaml -COPY stack.yaml package.yaml stack.yaml.lock /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 # Dummy static content to circumvent the /app doesn't exist warning RUN mkdir /app/src -RUN mkdir /app/app -RUN echo 'main :: IO ()' >> /app/app/Main.hs -RUN echo 'main = putStrLn "Hello, World!"' >> /app/app/Main.hs RUN stack build RUN stack clean hs-git-clone @@ -30,3 +29,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cp -r /tmp/.stack-work . && stac RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/java-21.Dockerfile b/dockerfiles/java-21.Dockerfile index 042c8ec..1e1d4e7 100644 --- a/dockerfiles/java-21.Dockerfile +++ b/dockerfiles/java-21.Dockerfile @@ -1,8 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM maven:3.9.5-eclipse-temurin-21-alpine -COPY pom.xml /app/pom.xml 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 # Download the dependencies RUN mvn -B package -Ddir=/tmp/codecrafters-git-target @@ -13,4 +15,6 @@ RUN mv /app/target /app-cached # Is this needed? # Pre-compile steps RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-git-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_git.sh" > /codecrafters-precompile.sh -RUN chmod +x /codecrafters-precompile.sh \ No newline at end of file +RUN chmod +x /codecrafters-precompile.sh +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/kotlin-1.3.72.Dockerfile b/dockerfiles/kotlin-1.3.72.Dockerfile index c56686f..73a3a7b 100644 --- a/dockerfiles/kotlin-1.3.72.Dockerfile +++ b/dockerfiles/kotlin-1.3.72.Dockerfile @@ -1,6 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM zenika/kotlin:1.3.72-jdk11-slim +# .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 apt-get update && \ apt-get install --no-install-recommends -y git=1:2.* && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/kotlin-1.4.Dockerfile b/dockerfiles/kotlin-1.4.Dockerfile index c3bfdbf..14351e2 100644 --- a/dockerfiles/kotlin-1.4.Dockerfile +++ b/dockerfiles/kotlin-1.4.Dockerfile @@ -1,6 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM zenika/kotlin:1.4.20-jdk11-slim +# .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 apt-get update && \ apt-get install --no-install-recommends -y git=1:2.* && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/nodejs-18.Dockerfile b/dockerfiles/nodejs-18.Dockerfile index 330bf0b..278c40c 100644 --- a/dockerfiles/nodejs-18.Dockerfile +++ b/dockerfiles/nodejs-18.Dockerfile @@ -1 +1,7 @@ -FROM node:18.18.0-alpine3.17 \ No newline at end of file +# syntax=docker/dockerfile:1.7-labs +FROM node:18.18.0-alpine3.17 +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/nodejs-21.Dockerfile b/dockerfiles/nodejs-21.Dockerfile index 435b41e..8f634f5 100644 --- a/dockerfiles/nodejs-21.Dockerfile +++ b/dockerfiles/nodejs-21.Dockerfile @@ -1,11 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM node:21.7-alpine3.19 ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,package-lock.json" WORKDIR /app -COPY package.json ./ -COPY package-lock.json ./ +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app # 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. RUN npm ci @@ -13,3 +14,6 @@ RUN npm ci RUN mkdir -p /app-cached # If the node_modules directory exists, move it to /app-cached RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/python-3.11.Dockerfile b/dockerfiles/python-3.11.Dockerfile index f0f5f76..9e97cfd 100644 --- a/dockerfiles/python-3.11.Dockerfile +++ b/dockerfiles/python-3.11.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM python:3.11-alpine +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/python-3.12.Dockerfile b/dockerfiles/python-3.12.Dockerfile index 8bec1f8..41e7e85 100644 --- a/dockerfiles/python-3.12.Dockerfile +++ b/dockerfiles/python-3.12.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM python:3.12-alpine +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/python-3.7.Dockerfile b/dockerfiles/python-3.7.Dockerfile index 3de9d1f..d34e0cd 100644 --- a/dockerfiles/python-3.7.Dockerfile +++ b/dockerfiles/python-3.7.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM jfloff/alpine-python:3.7 +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/python-3.8.Dockerfile b/dockerfiles/python-3.8.Dockerfile index 4f669db..a0ecae8 100644 --- a/dockerfiles/python-3.8.Dockerfile +++ b/dockerfiles/python-3.8.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM jfloff/alpine-python:3.8 +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/ruby-2.7.Dockerfile b/dockerfiles/ruby-2.7.Dockerfile index c7ced25..411e254 100644 --- a/dockerfiles/ruby-2.7.Dockerfile +++ b/dockerfiles/ruby-2.7.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM ruby:2.7-alpine +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/ruby-3.2.Dockerfile b/dockerfiles/ruby-3.2.Dockerfile index 24052e3..82747a3 100644 --- a/dockerfiles/ruby-3.2.Dockerfile +++ b/dockerfiles/ruby-3.2.Dockerfile @@ -1,3 +1,10 @@ +# syntax=docker/dockerfile:1.7-labs FROM ruby:3.2-alpine +# .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 apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/ruby-3.3.Dockerfile b/dockerfiles/ruby-3.3.Dockerfile index 6014b40..4f0a882 100644 --- a/dockerfiles/ruby-3.3.Dockerfile +++ b/dockerfiles/ruby-3.3.Dockerfile @@ -1,11 +1,16 @@ +# syntax=docker/dockerfile:1.7-labs FROM ruby:3.3-alpine ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Gemfile,Gemfile.lock" WORKDIR /app -COPY Gemfile Gemfile.lock ./ +# .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 bundle install --verbose RUN apk add --no-cache 'git>=2.40' + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/rust-1.62.Dockerfile b/dockerfiles/rust-1.62.Dockerfile index 0ebdd89..0dd49fd 100644 --- a/dockerfiles/rust-1.62.Dockerfile +++ b/dockerfiles/rust-1.62.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.62-buster RUN apt-get update && \ @@ -5,13 +6,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -COPY Cargo.toml /app/Cargo.toml -COPY Cargo.lock /app/Cargo.lock RUN mkdir /app/src RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 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 cargo build --release --target-dir=/tmp/codecrafters-git-target RUN rm /tmp/codecrafters-git-target/release/git-starter-rust @@ -30,3 +31,6 @@ RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/rust-1.68.Dockerfile b/dockerfiles/rust-1.68.Dockerfile index 357722e..f26073b 100644 --- a/dockerfiles/rust-1.68.Dockerfile +++ b/dockerfiles/rust-1.68.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.68-buster RUN apt-get update && \ @@ -5,13 +6,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -COPY Cargo.toml /app/Cargo.toml -COPY Cargo.lock /app/Cargo.lock RUN mkdir /app/src RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 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 cargo build --release --target-dir=/tmp/codecrafters-git-target RUN rm /tmp/codecrafters-git-target/release/git-starter-rust @@ -30,3 +31,6 @@ RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/rust-1.70.Dockerfile b/dockerfiles/rust-1.70.Dockerfile index d7c3d39..aa33705 100644 --- a/dockerfiles/rust-1.70.Dockerfile +++ b/dockerfiles/rust-1.70.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.70-buster RUN apt-get update && \ @@ -5,13 +6,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -COPY Cargo.toml /app/Cargo.toml -COPY Cargo.lock /app/Cargo.lock RUN mkdir /app/src RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 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 cargo build --release --target-dir=/tmp/codecrafters-git-target RUN rm /tmp/codecrafters-git-target/release/git-starter-rust @@ -30,3 +31,6 @@ RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/rust-1.76.Dockerfile b/dockerfiles/rust-1.76.Dockerfile index f6e138b..ca78041 100644 --- a/dockerfiles/rust-1.76.Dockerfile +++ b/dockerfiles/rust-1.76.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.76-buster RUN apt-get update && \ @@ -5,13 +6,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -COPY Cargo.toml /app/Cargo.toml -COPY Cargo.lock /app/Cargo.lock RUN mkdir /app/src RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 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 cargo build --release --target-dir=/tmp/codecrafters-git-target RUN rm /tmp/codecrafters-git-target/release/git-starter-rust @@ -30,3 +31,6 @@ RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/rust-1.77.Dockerfile b/dockerfiles/rust-1.77.Dockerfile index e81a70a..4bb77f4 100644 --- a/dockerfiles/rust-1.77.Dockerfile +++ b/dockerfiles/rust-1.77.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.77-buster RUN apt-get update && \ @@ -5,13 +6,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -COPY Cargo.toml /app/Cargo.toml -COPY Cargo.lock /app/Cargo.lock RUN mkdir /app/src RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs 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 cargo build --release --target-dir=/tmp/codecrafters-git-target RUN rm /tmp/codecrafters-git-target/release/git-starter-rust @@ -30,3 +31,6 @@ RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" + +# Once the heave steps are done, we can copy all files back +COPY . /app