diff --git a/dockerfiles/bun-1.1.Dockerfile b/dockerfiles/bun-1.1.Dockerfile index afcdfbb..499e126 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 # We need to install Go to build the custom executable. @@ -7,8 +8,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,4 +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 \ No newline at end of file +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/go-1.22.Dockerfile b/dockerfiles/go-1.22.Dockerfile index 0602f12..73f8885 100644 --- a/dockerfiles/go-1.22.Dockerfile +++ b/dockerfiles/go-1.22.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.22-alpine ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum" @@ -9,10 +10,14 @@ ENV GOCACHE=/cache 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/java-21.Dockerfile b/dockerfiles/java-21.Dockerfile index d338748..8c553d9 100644 --- a/dockerfiles/java-21.Dockerfile +++ b/dockerfiles/java-21.Dockerfile @@ -1,11 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs FROM maven:3.9.5-eclipse-temurin-21-alpine # We need to install Go to build the custom executable. RUN apk add --no-cache "go>=1.20" -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-shell-target @@ -16,4 +18,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-shell-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_shell.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/nodejs-21.Dockerfile b/dockerfiles/nodejs-21.Dockerfile index 316b28b..0608aa8 100644 --- a/dockerfiles/nodejs-21.Dockerfile +++ b/dockerfiles/nodejs-21.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM node:21.7-alpine3.19 # We need to install Go to build the custom executable. @@ -7,12 +8,14 @@ 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 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 \ No newline at end of file +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.12.Dockerfile b/dockerfiles/python-3.12.Dockerfile index 354f5a5..8167c70 100644 --- a/dockerfiles/python-3.12.Dockerfile +++ b/dockerfiles/python-3.12.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM python:3.12-alpine # We need to install Go to build the custom executable. @@ -5,10 +6,10 @@ RUN apk add --no-cache "go>=1.20" 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 @@ -17,4 +18,6 @@ RUN pipenv install # Force environment creation RUN pipenv run python3 -c "1+1" -ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock" \ No newline at end of file +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/rust-1.77.Dockerfile b/dockerfiles/rust-1.77.Dockerfile index 5070a1c..f3b5296 100644 --- a/dockerfiles/rust-1.77.Dockerfile +++ b/dockerfiles/rust-1.77.Dockerfile @@ -1,15 +1,16 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.77-buster # We need to install Go to build the custom executable. RUN apt-get update && apt-get install -y --no-install-recommends golang-go=2:* && 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-shell-target RUN cargo clean -p shell-starter-rust --release --target-dir=/tmp/codecrafters-shell-target @@ -20,3 +21,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cargo build --release --target-d 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