maybe this works
This commit is contained in:
55
Dockerfile
55
Dockerfile
@@ -1,68 +1,43 @@
|
||||
# === STAGE 1: Build & Dependencies ===
|
||||
FROM arm64v8/node:22 AS builder
|
||||
FROM arm64v8/node:22 AS base
|
||||
ENV SHARP_IGNORE_GLOBAL_CLI_BINARIES=1
|
||||
ENV VIPS_DISABLE_DEPS=1
|
||||
|
||||
ENV PNPM_SCRIPT_RUNNER_ALLOW_BUILD=true
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm and enable corepack
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
|
||||
# Copy the lockfile and package.json to leverage caching
|
||||
FROM base AS builder
|
||||
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 source code
|
||||
COPY . .
|
||||
|
||||
# Use a second cache mount for the Vinxi build artifacts.
|
||||
RUN --mount=type=cache,target=/app/.vinxi \
|
||||
pnpm run build
|
||||
|
||||
# ^ produces .output (build artifact) and .vinxi (build cache)
|
||||
|
||||
# === STAGE 2: Generate Production-only Files ===
|
||||
FROM arm64v8/node:22 AS production_builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Enable corepack and install jq as a system-level dependency.
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate && \
|
||||
apt-get update && apt-get install -y jq
|
||||
|
||||
# Copy the original lockfile and package.json from the builder stage.
|
||||
# take only the artifacts we need from the build
|
||||
FROM base AS production_builder
|
||||
RUN apt-get update && apt-get install -y jq
|
||||
COPY --from=builder /app/package.json ./
|
||||
COPY --from=builder /app/pnpm-lock.yaml ./
|
||||
|
||||
# Create a new, production-only package.json file.
|
||||
# Create a new, production-only package files
|
||||
RUN jq 'del(.devDependencies)' package.json > package.prod.json
|
||||
|
||||
# Now, generate a production-only pnpm-lock.yaml
|
||||
# We use a single, efficient command for this.
|
||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \
|
||||
pnpm install --prod --lockfile-only
|
||||
# === STAGE 3: Final Production Image ===
|
||||
FROM arm64v8/node:22-alpine
|
||||
|
||||
# Prod image
|
||||
FROM arm64v8/node:22-alpine
|
||||
ENV SHARP_IGNORE_GLOBAL_CLI_BINARIES=1
|
||||
ENV VIPS_DISABLE_DEPS=1
|
||||
ENV PNPM_SCRIPT_RUNNER_ALLOW_BUILD=true
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
WORKDIR /app
|
||||
|
||||
# Enable corepack
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
|
||||
# Copy the production-only files from the production_builder stage.
|
||||
COPY --from=production_builder /app/package.prod.json ./package.json
|
||||
COPY --from=production_builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
|
||||
# Now pnpm install will be very fast, as the cache is not invalidated by devDependency changes.
|
||||
# It uses the production-only package.json and lockfile.
|
||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \
|
||||
pnpm install --frozen-lockfile --prod
|
||||
|
||||
# Copy the compiled assets from the original builder stage.
|
||||
COPY --from=builder /app/.output ./.output
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
Reference in New Issue
Block a user