spicebook/frontend/Dockerfile
Ryan Malloy 9b2737ef77 Set PUBLIC_API_URL at build time for production
Vite inlines import.meta.env.PUBLIC_* at build time, not runtime.
Without this, the frontend falls back to localhost:8099 which doesn't
exist from the browser. Empty string means same-origin requests,
letting Caddy route /api/* to the backend.
2026-02-13 03:45:23 -07:00

56 lines
1.4 KiB
Docker

# ── Dev stage ────────────────────────────────────────────────────────
FROM node:20-slim AS dev
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install
COPY . .
EXPOSE 4321
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
# ── Build stage ──────────────────────────────────────────────────────
FROM node:20-slim AS build
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
COPY . .
ENV ASTRO_TELEMETRY_DISABLED=1
# PUBLIC_API_URL must be set at build time for Vite to inline it.
# Empty string = same-origin (Caddy routes /api/* to backend).
ARG PUBLIC_API_URL=""
ENV PUBLIC_API_URL=${PUBLIC_API_URL}
RUN npm run build
# ── Prod stage ───────────────────────────────────────────────────────
FROM node:20-slim AS prod
WORKDIR /app
# Copy the built Astro SSR server
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./
# Run as non-root
RUN useradd --create-home --shell /bin/bash astro
USER astro
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD ["node", "dist/server/entry.mjs"]