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.
This commit is contained in:
Maxim Snesarev 2026-04-03 00:44:24 +03:00
parent 3b3c88ed64
commit 63e619eab6
2 changed files with 20 additions and 8 deletions

View File

@ -1,7 +1,17 @@
node_modules # Ignore everything by default
.next *
.turbo
.git
*.log
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

View File

@ -15,12 +15,14 @@ RUN turbo prune @advdoors/web --docker
FROM base AS builder FROM base AS builder
COPY --from=pruner /app/out/json/ . COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml 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 pruned source and build via Turbo
COPY --from=pruner /app/out/full/ . COPY --from=pruner /app/out/full/ .
ENV NEXT_TELEMETRY_DISABLED=1 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 # Production
FROM base AS runner FROM base AS runner