diff --git a/dockerfiles/bun-1.1.Dockerfile b/dockerfiles/bun-1.1.Dockerfile index 4db1041..3622634 100644 --- a/dockerfiles/bun-1.1.Dockerfile +++ b/dockerfiles/bun-1.1.Dockerfile @@ -1,11 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM oven/bun:1.1.4-alpine 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. @@ -15,3 +16,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 dd2cc64..a33529d 100644 --- a/dockerfiles/cpp-20.Dockerfile +++ b/dockerfiles/cpp-20.Dockerfile @@ -1,6 +1,13 @@ +# 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 && \ rm -rf /var/lib/apt/lists/* + +# 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 5e9822a..9bbd1c5 100644 --- a/dockerfiles/dotnet-8.0.Dockerfile +++ b/dockerfiles/dotnet-8.0.Dockerfile @@ -1,12 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine -COPY codecrafters-grep.csproj /app/codecrafters-grep.csproj -COPY codecrafters-grep.sln /app/codecrafters-grep.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 . @@ -22,3 +23,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && dotnet build --configuration Rel RUN chmod +x /codecrafters-precompile.sh ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-grep.csproj,codecrafters-grep.sln" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/gleam-1.0.Dockerfile b/dockerfiles/gleam-1.0.Dockerfile index 2d62298..04850d0 100644 --- a/dockerfiles/gleam-1.0.Dockerfile +++ b/dockerfiles/gleam-1.0.Dockerfile @@ -1,5 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-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 + # Pre-compile steps RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && gleam build" > /codecrafters-precompile.sh RUN chmod +x /codecrafters-precompile.sh + +# 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 23ced9c..145398d 100644 --- a/dockerfiles/go-1.19.Dockerfile +++ b/dockerfiles/go-1.19.Dockerfile @@ -1,9 +1,14 @@ +# 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" + +# 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 d92cb87..c883c1c 100644 --- a/dockerfiles/go-1.21.Dockerfile +++ b/dockerfiles/go-1.21.Dockerfile @@ -1,13 +1,18 @@ +# 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 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" + +# 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 ec4d2bd..85cb5ca 100644 --- a/dockerfiles/go-1.22.Dockerfile +++ b/dockerfiles/go-1.22.Dockerfile @@ -1,13 +1,18 @@ +# 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 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" + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/haskell-9.2.Dockerfile b/dockerfiles/haskell-9.2.Dockerfile index ef0be62..1f4ea11 100644 --- a/dockerfiles/haskell-9.2.Dockerfile +++ b/dockerfiles/haskell-9.2.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM haskell:9.2.5-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-grep-clone @@ -29,4 +28,6 @@ RUN rm -rf /app/src RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cp -r /tmp/.stack-work . && stack build" > /codecrafters-precompile.sh RUN chmod +x /codecrafters-precompile.sh -ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock" \ No newline at end of file +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/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.10.Dockerfile b/dockerfiles/python-3.10.Dockerfile index 071947e..f2e99c3 100644 --- a/dockerfiles/python-3.10.Dockerfile +++ b/dockerfiles/python-3.10.Dockerfile @@ -1,11 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM python:3.10-alpine RUN pip install --no-cache-dir "pipenv>=2023.12.1" -COPY Pipfile /app/Pipfile -COPY Pipfile.lock /app/Pipfile.lock 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 ENV WORKON_HOME=/venvs @@ -15,3 +16,6 @@ RUN pipenv install RUN pipenv run python3 -c "1+1" ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" + +# 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 e377bca..3ec85c5 100644 --- a/dockerfiles/python-3.11.Dockerfile +++ b/dockerfiles/python-3.11.Dockerfile @@ -1,11 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM python:3.11-alpine RUN pip install --no-cache-dir "pipenv>=2023.12.1" -COPY Pipfile /app/Pipfile -COPY Pipfile.lock /app/Pipfile.lock 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 ENV WORKON_HOME=/venvs @@ -15,3 +16,6 @@ RUN pipenv install RUN pipenv run python3 -c "1+1" ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" + +# 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 9d4f14c..45c632b 100644 --- a/dockerfiles/python-3.12.Dockerfile +++ b/dockerfiles/python-3.12.Dockerfile @@ -1,11 +1,12 @@ +# syntax=docker/dockerfile:1.7-labs FROM python:3.12-alpine RUN pip install --no-cache-dir "pipenv>=2023.12.1" -COPY Pipfile /app/Pipfile -COPY Pipfile.lock /app/Pipfile.lock 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 ENV WORKON_HOME=/venvs @@ -15,3 +16,6 @@ RUN pipenv install RUN pipenv run python3 -c "1+1" ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" + +# 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 9204142..9658506 100644 --- a/dockerfiles/ruby-2.7.Dockerfile +++ b/dockerfiles/ruby-2.7.Dockerfile @@ -1,6 +1,13 @@ +# 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 --upgrade 'curl>=7.66' RUN apk add --no-cache --upgrade 'curl-dev>=7.66' WORKDIR /app + +# 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 3c9465c..8348c80 100644 --- a/dockerfiles/ruby-3.2.Dockerfile +++ b/dockerfiles/ruby-3.2.Dockerfile @@ -1,6 +1,13 @@ +# 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 --upgrade 'curl>=7.66' RUN apk add --no-cache --upgrade 'curl-dev>=7.66' WORKDIR /app + +# 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 2c92211..9accaf4 100644 --- a/dockerfiles/ruby-3.3.Dockerfile +++ b/dockerfiles/ruby-3.3.Dockerfile @@ -1,9 +1,14 @@ +# 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 + +# 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 d0293b1..05fb007 100644 --- a/dockerfiles/rust-1.62.Dockerfile +++ b/dockerfiles/rust-1.62.Dockerfile @@ -1,12 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.62-buster -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-grep-target RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target @@ -18,3 +19,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 f6d848b..4936cfc 100644 --- a/dockerfiles/rust-1.68.Dockerfile +++ b/dockerfiles/rust-1.68.Dockerfile @@ -1,12 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.68-buster -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-grep-target RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target @@ -18,3 +19,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 28e4d8b..e1ccca1 100644 --- a/dockerfiles/rust-1.70.Dockerfile +++ b/dockerfiles/rust-1.70.Dockerfile @@ -1,12 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.70-buster -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-grep-target RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target @@ -18,3 +19,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 aa5baab..e1e5421 100644 --- a/dockerfiles/rust-1.76.Dockerfile +++ b/dockerfiles/rust-1.76.Dockerfile @@ -1,12 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.76-buster -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-grep-target RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target @@ -18,3 +19,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 fc5e596..1c75196 100644 --- a/dockerfiles/rust-1.77.Dockerfile +++ b/dockerfiles/rust-1.77.Dockerfile @@ -1,12 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.77-buster -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-grep-target RUN cargo clean -p grep-starter-rust --release --target-dir=/tmp/codecrafters-grep-target @@ -18,3 +19,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