Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-1333 Add repository aware caching #228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dockerfiles/bun-1.1.Dockerfile
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COPY . /app
7 changes: 6 additions & 1 deletion dockerfiles/clojure-1.10.3.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# syntax=docker/dockerfile:1.7-labs
FROM clojure:openjdk-18-lein-alpine

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="project.clj"

WORKDIR /app
COPY project.clj ./
# .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 lein deps

RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && lein deps && lein uberjar && sed -i 's/^\(lein .*\)/#\1/' ./spawn_redis_server.sh\n" > /codecrafters-precompile.sh
RUN chmod +x /codecrafters-precompile.sh

# Once the heave steps are done, we can copy all files back
COPY . /app
7 changes: 6 additions & 1 deletion dockerfiles/clojure-1.11.3.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# syntax=docker/dockerfile:1.7-labs
FROM clojure:openjdk-19-lein-alpine

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="project.clj"

WORKDIR /app
COPY project.clj ./
# .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 lein deps

RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && lein deps && lein uberjar && sed -i 's/^\(lein .*\)/#\1/' ./spawn_redis_server.sh\n" > /codecrafters-precompile.sh
RUN chmod +x /codecrafters-precompile.sh

# Once the heave steps are done, we can copy all files back
COPY . /app
8 changes: 6 additions & 2 deletions dockerfiles/cpp-23.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.7-labs
FROM gcc:13.2.0-bookworm

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="vcpkg.json,vcpkg-configuration.json"
Expand Down Expand Up @@ -25,8 +26,8 @@ ENV PATH="${VCPKG_ROOT}:$PATH"

WORKDIR /app

COPY vcpkg.json ./
COPY vcpkg-configuration.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

RUN vcpkg install --no-print-usage
RUN sed -i '1s/^/set(VCPKG_INSTALL_OPTIONS --no-print-usage)\n/' ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
Expand All @@ -37,3 +38,6 @@ RUN if [ -d "/app/vcpkg_installed" ]; then mv /app/vcpkg_installed /app-cached/b

RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake && cmake --build ./build && sed -i '/^cmake/ s/^/# /' ./spawn_redis_server.sh" > /codecrafters-precompile.sh
RUN chmod +x /codecrafters-precompile.sh

# Once the heave steps are done, we can copy all files back
COPY . /app
8 changes: 6 additions & 2 deletions dockerfiles/dotnet-6.0.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# syntax=docker/dockerfile:1.7-labs
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim

COPY codecrafters-redis.csproj /app/codecrafters-redis.csproj
COPY codecrafters-redis.sln /app/codecrafters-redis.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 .
Expand All @@ -22,3 +23,6 @@ RUN chmod +x /codecrafters-precompile.sh

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-redis.csproj,codecrafters-redis.sln"


# Once the heave steps are done, we can copy all files back
COPY . /app
7 changes: 6 additions & 1 deletion dockerfiles/go-1.19.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion dockerfiles/go-1.21.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion dockerfiles/go-1.22.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions dockerfiles/haskell-9.4.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.7-labs
FROM haskell:9.4.6-buster

WORKDIR /app
Expand All @@ -11,12 +12,9 @@ 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/app
RUN echo 'main :: IO ()' >> /app/app/Main.hs
RUN echo 'main = putStrLn "Hello, World!"' >> /app/app/Main.hs

ENV STACK_ROOT=/app/.stack

Expand All @@ -32,3 +30,6 @@ RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && stack build" > /codecrafters-pre
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
8 changes: 6 additions & 2 deletions dockerfiles/java-21.Dockerfile
Original file line number Diff line number Diff line change
@@ -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-redis-target
Expand All @@ -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-redis-target && sed -i 's/^\(mvn .*\)/#\1/' ./spawn_redis_server.sh\n" > /codecrafters-precompile.sh
RUN chmod +x /codecrafters-precompile.sh
RUN chmod +x /codecrafters-precompile.sh
# Once the heave steps are done, we can copy all files back
COPY . /app
8 changes: 6 additions & 2 deletions dockerfiles/nodejs-21.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# 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

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
8 changes: 6 additions & 2 deletions dockerfiles/ruby-3.3.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# 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 ./
RUN bundle install --verbose
# .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
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.43.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# syntax=docker/dockerfile:1.7-labs
FROM rust:1.43-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-redis-target

RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
Expand All @@ -22,3 +23,6 @@ RUN rm -rf /app/src

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@libmartinito what's the script you used to generate this? The spacing seems very inconsistent - in some files there are 2 empty lines between blocks, in some there are none - looks very haphazard

# Once the heave steps are done, we can copy all files back
COPY . /app
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.54.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# syntax=docker/dockerfile:1.7-labs
FROM rust:1.54-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-redis-target

RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
Expand All @@ -25,3 +26,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
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.62.Dockerfile
Original file line number Diff line number Diff line change
@@ -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-redis-target

RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
Expand All @@ -25,3 +26,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
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.68.Dockerfile
Original file line number Diff line number Diff line change
@@ -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-redis-target

RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
Expand All @@ -25,3 +26,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
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.70.Dockerfile
Original file line number Diff line number Diff line change
@@ -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-redis-target

RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
Expand All @@ -25,3 +26,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
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.76.Dockerfile
Original file line number Diff line number Diff line change
@@ -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-redis-target

RUN rm /tmp/codecrafters-redis-target/release/redis-starter-rust
Expand All @@ -25,3 +26,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
Loading
Loading