From 37dfb46f707cf4e31639a7d6e186610529d22159 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/c-9.2.Dockerfile | 7 +++++++ dockerfiles/go-1.13.Dockerfile | 7 +++++++ 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/nim-1.0.Dockerfile | 7 +++++++ dockerfiles/php-7.4.Dockerfile | 7 +++++++ dockerfiles/python-3.11.Dockerfile | 7 +++++++ dockerfiles/python-3.12.Dockerfile | 7 +++++++ dockerfiles/ruby-2.7.Dockerfile | 7 +++++++ dockerfiles/ruby-3.2.Dockerfile | 7 +++++++ dockerfiles/rust-1.43.Dockerfile | 9 ++++++--- dockerfiles/rust-1.54.Dockerfile | 9 ++++++--- 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 ++++++-- dockerfiles/swift-5.6.Dockerfile | 7 +++++++ 20 files changed, 130 insertions(+), 19 deletions(-) diff --git a/dockerfiles/c-9.2.Dockerfile b/dockerfiles/c-9.2.Dockerfile index 2e61bba..f0d3a96 100644 --- a/dockerfiles/c-9.2.Dockerfile +++ b/dockerfiles/c-9.2.Dockerfile @@ -1,5 +1,9 @@ +# syntax=docker/dockerfile:1.7-labs FROM n0madic/alpine-gcc:9.2.0 +# .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 'curl>=7.66' # For making HTTP requests using libcurl @@ -9,3 +13,6 @@ RUN apk add --no-cache --upgrade 'curl-dev>=7.66' ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 d2c01c9..c6e05b5 100644 --- a/dockerfiles/go-1.13.Dockerfile +++ b/dockerfiles/go-1.13.Dockerfile @@ -1,8 +1,15 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.13-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' # Download docker-explorer ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 410142a..a6f8fae 100644 --- a/dockerfiles/go-1.16.Dockerfile +++ b/dockerfiles/go-1.16.Dockerfile @@ -1,8 +1,15 @@ +# 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 --upgrade 'curl>=7.66' # Download docker-explorer ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 09964b6..7327b3c 100644 --- a/dockerfiles/go-1.19.Dockerfile +++ b/dockerfiles/go-1.19.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.19-alpine RUN apk add --no-cache 'curl>=7.66' @@ -11,6 +12,10 @@ 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 27ed6da..0ddbbbe 100644 --- a/dockerfiles/go-1.21.Dockerfile +++ b/dockerfiles/go-1.21.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM golang:1.21-alpine RUN apk add --no-cache 'curl>=7.66' @@ -11,10 +12,14 @@ 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 141ab9d..f09e7fd 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 RUN apk add --no-cache 'curl>=7.66' @@ -11,10 +12,14 @@ 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/nim-1.0.Dockerfile b/dockerfiles/nim-1.0.Dockerfile index 2924f78..2a837c4 100644 --- a/dockerfiles/nim-1.0.Dockerfile +++ b/dockerfiles/nim-1.0.Dockerfile @@ -1,8 +1,15 @@ +# syntax=docker/dockerfile:1.7-labs FROM nimlang/nim:1.0.6-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 'curl>=7.66' # Download docker-explorer ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/php-7.4.Dockerfile b/dockerfiles/php-7.4.Dockerfile index 24a6c87..d6e3715 100644 --- a/dockerfiles/php-7.4.Dockerfile +++ b/dockerfiles/php-7.4.Dockerfile @@ -1,5 +1,9 @@ +# syntax=docker/dockerfile:1.7-labs FROM php:7.4-cli-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' @@ -9,3 +13,6 @@ RUN docker-php-ext-install pcntl ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 b055817..2b8e7a0 100644 --- a/dockerfiles/python-3.11.Dockerfile +++ b/dockerfiles/python-3.11.Dockerfile @@ -1,8 +1,15 @@ +# 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 'curl>=7.66' # Download docker-explorer. ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 59ccedf..f511a54 100644 --- a/dockerfiles/python-3.12.Dockerfile +++ b/dockerfiles/python-3.12.Dockerfile @@ -1,8 +1,15 @@ +# 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 'curl>=7.66' # Download docker-explorer. ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 9616c19..9590dee 100644 --- a/dockerfiles/ruby-2.7.Dockerfile +++ b/dockerfiles/ruby-2.7.Dockerfile @@ -1,5 +1,9 @@ +# 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' @@ -7,3 +11,6 @@ RUN apk add --no-cache --upgrade 'curl-dev>=7.66' ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# 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 b7ce7db..8becadc 100644 --- a/dockerfiles/ruby-3.2.Dockerfile +++ b/dockerfiles/ruby-3.2.Dockerfile @@ -1,5 +1,9 @@ +# 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' @@ -7,3 +11,6 @@ RUN apk add --no-cache --upgrade 'curl-dev>=7.66' ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# Once the heave steps are done, we can copy all files back +COPY . /app diff --git a/dockerfiles/rust-1.43.Dockerfile b/dockerfiles/rust-1.43.Dockerfile index 2031ff4..72d120e 100644 --- a/dockerfiles/rust-1.43.Dockerfile +++ b/dockerfiles/rust-1.43.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.43-buster # Download docker-explorer @@ -5,17 +6,19 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target RUN rm -rf /app/src -ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" \ No newline at end of file +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.54.Dockerfile b/dockerfiles/rust-1.54.Dockerfile index fd70f0f..386db52 100644 --- a/dockerfiles/rust-1.54.Dockerfile +++ b/dockerfiles/rust-1.54.Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7-labs FROM rust:1.54-buster # Download docker-explorer @@ -5,13 +6,13 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target @@ -21,4 +22,6 @@ RUN rm -rf /app/src RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cargo build --release --target-dir=/tmp/codecrafters-docker-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh RUN chmod +x /codecrafters-precompile.sh -ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock" \ No newline at end of file +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.62.Dockerfile b/dockerfiles/rust-1.62.Dockerfile index 6a93ce3..3d783fb 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 # Download docker-explorer @@ -5,13 +6,13 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target @@ -23,3 +24,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 7af11cc..2fd1867 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 # Download docker-explorer @@ -5,13 +6,13 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target @@ -23,3 +24,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 103d0d3..bb0b39c 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 # Download docker-explorer @@ -5,13 +6,13 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target @@ -23,3 +24,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 2b9a65e..7e0c501 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 # Download docker-explorer @@ -5,13 +6,13 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target @@ -23,3 +24,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 5d54b28..05fe95e 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 # Download docker-explorer @@ -5,13 +6,13 @@ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer -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-docker-target RUN cargo clean -p docker-starter-rust --release --target-dir=/tmp/codecrafters-docker-target @@ -23,3 +24,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/swift-5.6.Dockerfile b/dockerfiles/swift-5.6.Dockerfile index d56f593..d7bff86 100644 --- a/dockerfiles/swift-5.6.Dockerfile +++ b/dockerfiles/swift-5.6.Dockerfile @@ -1,5 +1,9 @@ +# syntax=docker/dockerfile:1.7-labs FROM swift:5.6.1-focal +# .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 curl=7.68.* && \ apt-get clean && \ @@ -9,3 +13,6 @@ RUN apt-get update && \ ARG docker_explorer_version=v18 RUN curl --fail -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64 RUN chmod +x /usr/local/bin/docker-explorer + +# Once the heave steps are done, we can copy all files back +COPY . /app