From d9c07c1387ebf8f8d5b30a30d73bcd14d70b6d55 Mon Sep 17 00:00:00 2001 From: Danyal Prout Date: Wed, 24 Sep 2025 13:31:16 -0500 Subject: [PATCH] chore: speed up docker --- crates/audit/Dockerfile | 25 ++++++++++++++++++++----- crates/ingress-rpc/Dockerfile | 28 +++++++++++++++++++++------- crates/ingress-writer/Dockerfile | 28 +++++++++++++++++++++------- crates/maintenance/Dockerfile | 28 +++++++++++++++++++++------- justfile | 2 +- ui/Dockerfile | 7 ++++--- 6 files changed, 88 insertions(+), 30 deletions(-) diff --git a/crates/audit/Dockerfile b/crates/audit/Dockerfile index 2c72e9d..b09a0fd 100644 --- a/crates/audit/Dockerfile +++ b/crates/audit/Dockerfile @@ -1,11 +1,26 @@ -FROM rust:1-bookworm AS builder +FROM rust:1-bookworm AS base +RUN cargo install cargo-chef --locked WORKDIR /app -COPY Cargo.toml Cargo.lock ./ -COPY crates/ ./crates/ +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN cargo build --bin tips-audit +FROM base AS builder +COPY --from=planner /app/recipe.json recipe.json + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo chef cook --recipe-path recipe.json + +COPY . . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo build --bin tips-audit && \ + cp target/debug/tips-audit /tmp/tips-audit FROM debian:bookworm @@ -13,7 +28,7 @@ RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/ WORKDIR /app -COPY --from=builder /app/target/debug/tips-audit /app/tips-audit +COPY --from=builder /tmp/tips-audit /app/tips-audit EXPOSE 3001 diff --git a/crates/ingress-rpc/Dockerfile b/crates/ingress-rpc/Dockerfile index 48f8669..97c27d0 100644 --- a/crates/ingress-rpc/Dockerfile +++ b/crates/ingress-rpc/Dockerfile @@ -1,20 +1,34 @@ -FROM rust:1-bookworm AS builder +FROM rust:1-bookworm AS base +RUN cargo install cargo-chef --locked WORKDIR /app -COPY Cargo.toml Cargo.lock ./ -COPY crates/ ./crates/ -COPY .sqlx/ ./.sqlx/ +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN cargo build --bin tips-ingress-rpc +FROM base AS builder +COPY --from=planner /app/recipe.json recipe.json + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo chef cook --recipe-path recipe.json + +COPY . . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo build --bin tips-ingress-rpc && \ + cp target/debug/tips-ingress-rpc /tmp/tips-ingress-rpc FROM debian:bookworm -RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY --from=builder /app/target/debug/tips-ingress-rpc /app/tips-ingress-rpc +COPY --from=builder /tmp/tips-ingress-rpc /app/tips-ingress-rpc EXPOSE 3000 diff --git a/crates/ingress-writer/Dockerfile b/crates/ingress-writer/Dockerfile index 96f1abd..d44fe80 100644 --- a/crates/ingress-writer/Dockerfile +++ b/crates/ingress-writer/Dockerfile @@ -1,19 +1,33 @@ -FROM rust:1-bookworm AS builder +FROM rust:1-bookworm AS base +RUN cargo install cargo-chef --locked WORKDIR /app -COPY Cargo.toml Cargo.lock ./ -COPY crates/ ./crates/ -COPY .sqlx/ ./.sqlx/ +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN cargo build --bin tips-ingress-writer +FROM base AS builder +COPY --from=planner /app/recipe.json recipe.json + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo chef cook --recipe-path recipe.json + +COPY . . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo build --bin tips-ingress-writer && \ + cp target/debug/tips-ingress-writer /tmp/tips-ingress-writer FROM debian:bookworm -RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY --from=builder /app/target/debug/tips-ingress-writer /app/tips-ingress-writer +COPY --from=builder /tmp/tips-ingress-writer /app/tips-ingress-writer CMD ["/app/tips-ingress-writer"] \ No newline at end of file diff --git a/crates/maintenance/Dockerfile b/crates/maintenance/Dockerfile index 2b77800..b3e080f 100644 --- a/crates/maintenance/Dockerfile +++ b/crates/maintenance/Dockerfile @@ -1,19 +1,33 @@ -FROM rust:1-bookworm AS builder +FROM rust:1-bookworm AS base +RUN cargo install cargo-chef --locked WORKDIR /app -COPY Cargo.toml Cargo.lock ./ -COPY crates/ ./crates/ -COPY .sqlx/ ./.sqlx/ +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN cargo build --bin tips-maintenance +FROM base AS builder +COPY --from=planner /app/recipe.json recipe.json + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo chef cook --recipe-path recipe.json + +COPY . . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/app/target \ + cargo build --bin tips-maintenance && \ + cp target/debug/tips-maintenance /tmp/tips-maintenance FROM debian:bookworm -RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY --from=builder /app/target/debug/tips-maintenance /app/tips-maintenance +COPY --from=builder /tmp/tips-maintenance /app/tips-maintenance CMD ["/app/tips-maintenance"] \ No newline at end of file diff --git a/justfile b/justfile index 00e158f..4c959b6 100644 --- a/justfile +++ b/justfile @@ -50,7 +50,7 @@ start-all: stop-all # Start every service in docker, except the one you're currently working on. e.g. just start-except ui ingress-rpc start-except programs: stop-all #!/bin/bash - all_services=(postgres kafka kafka-setup minio minio-setup ingress-rpc audit maintenance ui) + all_services=(postgres kafka kafka-setup minio minio-setup ingress-rpc ingres-writer audit maintenance ui) exclude_services=({{ programs }}) # Create result array with services not in exclude list diff --git a/ui/Dockerfile b/ui/Dockerfile index 0fe1d58..8615be8 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -1,7 +1,8 @@ FROM node:20-alpine AS deps WORKDIR /app COPY ui/package.json ui/yarn.lock ./ -RUN yarn install --frozen-lockfile +RUN --mount=type=cache,target=/root/.yarn \ + yarn install --frozen-lockfile FROM node:20-alpine AS builder WORKDIR /app @@ -10,7 +11,8 @@ COPY ./ui . ENV NEXT_TELEMETRY_DISABLED=1 -RUN yarn build +RUN --mount=type=cache,target=/app/.next/cache \ + yarn build FROM node:20-alpine AS runner WORKDIR /app @@ -21,7 +23,6 @@ ENV NEXT_TELEMETRY_DISABLED=1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs - RUN mkdir .next RUN chown nextjs:nodejs .next