# syntax=docker/dockerfile:1.4
# ============================================================
# Velocity-OS — webos (React 19 WebOS Frontend)
# Multi-stage: Vite build → Nginx static serve.
# ============================================================

# ── Stage 1: Node build ──────────────────────────────────────
FROM node:20-alpine AS builder

WORKDIR /app

# Cache node_modules layer separately from source
COPY package*.json ./
RUN --mount=type=cache,target=/root/.npm \
    npm ci --prefer-offline

# Copy source and build
COPY . .
RUN npm run build

# ── Stage 2: Nginx runtime ───────────────────────────────────
FROM nginx:1.25-alpine AS runtime

LABEL org.opencontainers.image.title="velocity-os-webos" \
      org.opencontainers.image.description="Velocity-OS React WebOS Frontend" \
      org.opencontainers.image.vendor="Desineuron" \
      org.opencontainers.image.version="2.0.0"

# Remove default config
RUN rm /etc/nginx/conf.d/default.conf

# Copy built assets and custom nginx config
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/velocity-os.conf

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
    CMD wget -qO- http://localhost/health.txt || exit 1

CMD ["nginx", "-g", "daemon off;"]
