vinxi cache in docker build

This commit is contained in:
2025-07-31 23:15:51 -04:00
parent 6edbaa7a68
commit 27d47764f8
3 changed files with 46 additions and 9 deletions

View File

@@ -1,12 +1,45 @@
# === STAGE 1: Build & Dependencies ===
FROM node:22 AS builder
WORKDIR /app
# Install pnpm and enable corepack
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy the lockfile and package.json to leverage caching
COPY package.json pnpm-lock.yaml ./
# Use a cache mount to persist the pnpm store across builds.
# The 'pnpm install' command will use this persistent cache.
RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \
pnpm install --frozen-lockfile
# Copy the rest of the application files
COPY . .
# Use a second cache mount for the Vinxi build artifacts.
# This tells Docker to mount a persistent cache directory to a build-cache location.
# The `pnpm run build` command will now use this cache for incremental builds.
# We'll assume a `.vinxi` or `.cache` directory for this example.
RUN --mount=type=cache,target=/app/.vinxi \
pnpm run build
# === STAGE 2: Production Final Image ===
FROM node:22-alpine
WORKDIR /app
# Enable corepack and install only production dependencies
RUN corepack enable && corepack prepare pnpm@latest --activate
COPY package.json pnpm-lock.yaml ./
# This install can also use the cache mount to avoid re-downloading
RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \
pnpm install --frozen-lockfile --prod
# Copy the compiled assets and lockfile from the builder stage
COPY --from=builder /app/.output ./.output
COPY --from=builder /app/package.json ./package.json
EXPOSE 3000
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "run", "start"]
CMD ["pnpm", "start"]