# Stage 1: Build
FROM node:25 AS builder
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
ENV PATH="/root/.local/bin:$PATH"
RUN npm install -g pnpm && pnpm install --frozen-lockfile
RUN apt-get install curl && curl -sSf https://install.spacetimedb.com | sh -s -- -y
COPY --exclude=src-tauri . .
# Build the static site
RUN pnpm run build

# Stage 2: Serve
FROM nginx:alpine
# Copy built assets
COPY --from=builder /app/dist /usr/share/nginx/html
# Copy custom Nginx config for SPA routing
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy entrypoint script for runtime environment variable injection
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

EXPOSE 80
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
