rda-v3/Dockerfile
Calum Muir a00b337703 Store studio index.html outside dist/client/ to avoid static serving
Astro didn't include the deleted public/studio/index.html in dist/client/
so the SSR route couldn't find it. Now we copy it from the studio build
stage to dist/studio-index.html after the Astro build — accessible to
the SSR route but invisible to the static file middleware.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 13:01:10 +00:00

51 lines
2.3 KiB
Docker

FROM node:20-alpine AS base
WORKDIR /app
# ── 1. Install main project deps ─────────────────────────────────────────────
FROM base AS deps
COPY package.json package-lock.json ./
RUN npm install --legacy-peer-deps
# ── 2. Install studio deps ────────────────────────────────────────────────────
FROM base AS studio-deps
COPY studio/package.json studio/package-lock.json* ./
RUN npm install --legacy-peer-deps
# ── 3. Build Sanity Studio ────────────────────────────────────────────────────
FROM base AS studio-build
COPY --from=studio-deps /app/node_modules ./node_modules
COPY studio/ ./
ARG SANITY_STUDIO_PROJECT_ID
ARG SANITY_STUDIO_DATASET=production
ENV SANITY_STUDIO_PROJECT_ID=$SANITY_STUDIO_PROJECT_ID
ENV SANITY_STUDIO_DATASET=$SANITY_STUDIO_DATASET
RUN npm run build
# ── 4. Build Astro site (with studio output as static files) ──────────────────
FROM base AS build
COPY --from=deps /app/node_modules ./node_modules
COPY . .
COPY --from=studio-build /app/dist ./public/studio
# Remove index.html from public so static middleware doesn't serve it —
# the SSR route rewrites asset paths before serving it.
RUN rm -f ./public/studio/index.html
ARG SANITY_PROJECT_ID
ARG SANITY_DATASET=production
ARG SANITY_API_TOKEN
ENV SANITY_PROJECT_ID=$SANITY_PROJECT_ID
ENV SANITY_DATASET=$SANITY_DATASET
ENV SANITY_API_TOKEN=$SANITY_API_TOKEN
RUN npm run build
# Place studio index.html outside dist/client/ so SSR can read it without
# it being served as a static file.
COPY --from=studio-build /app/dist/index.html ./dist/studio-index.html
# ── 5. Runtime ────────────────────────────────────────────────────────────────
FROM node:20-alpine AS runtime
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD ["node", "./dist/server/entry.mjs"]