From 63e619eab6dacc2353026168205b7ef4e44af1a8 Mon Sep 17 00:00:00 2001 From: Maxim Snesarev Date: Fri, 3 Apr 2026 00:44:24 +0300 Subject: [PATCH] Refactor .dockerignore and Dockerfile for optimized build context and caching - Updated .dockerignore to ignore everything by default while allowing necessary files and directories for the Docker build. - Enhanced Dockerfile to utilize caching for pnpm installation and Turbo build process, improving build performance and efficiency. --- .dockerignore | 22 ++++++++++++++++------ docker/Dockerfile | 6 ++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index 0f8abf9..7935cf4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,17 @@ -node_modules -.next -.turbo -.git -*.log +# Ignore everything by default +* -docker/backups +# Allow only what the Dockerfile needs +!package.json +!pnpm-lock.yaml +!pnpm-workspace.yaml +!turbo.json +!.npmrc +!apps/web/ +!packages/ + +# Re-exclude build artifacts that snuck in +apps/web/.next +apps/web/node_modules +packages/*/node_modules +packages/*/dist diff --git a/docker/Dockerfile b/docker/Dockerfile index fa14f41..8b02c9b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,12 +15,14 @@ RUN turbo prune @advdoors/web --docker FROM base AS builder COPY --from=pruner /app/out/json/ . COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml -RUN pnpm install --frozen-lockfile +RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ + pnpm install --frozen-lockfile # Copy pruned source and build via Turbo COPY --from=pruner /app/out/full/ . ENV NEXT_TELEMETRY_DISABLED=1 -RUN pnpm turbo build --filter=@advdoors/web +RUN --mount=type=cache,target=/app/apps/web/.next/cache \ + pnpm turbo build --filter=@advdoors/web # Production FROM base AS runner