Skip to content

CC-1333 Add repository aware caching #16

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

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
9 changes: 6 additions & 3 deletions dockerfiles/bun-1.1.Dockerfile
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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
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
7 changes: 6 additions & 1 deletion dockerfiles/go-1.22.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.7-labs
FROM golang:1.22-alpine

ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
Expand All @@ -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
8 changes: 6 additions & 2 deletions dockerfiles/java-21.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
RUN chmod +x /codecrafters-precompile.sh
# Once the heave steps are done, we can copy all files back
COPY . /app
9 changes: 6 additions & 3 deletions dockerfiles/nodejs-21.Dockerfile
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
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
9 changes: 6 additions & 3 deletions dockerfiles/python-3.12.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# syntax=docker/dockerfile:1.7-labs
FROM python:3.12-alpine

# We need to install Go to build the custom executable.
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

Expand All @@ -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"
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Pipfile,Pipfile.lock"
# Once the heave steps are done, we can copy all files back
COPY . /app
8 changes: 6 additions & 2 deletions dockerfiles/rust-1.77.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Loading