# Strapi CMS — build context: ./cms
# In Coolify: set "Base Directory" to /cms so this file is used.
FROM node:20-alpine AS base
WORKDIR /app

# --- install deps (cached layer) ---
FROM base AS deps
COPY package*.json ./
RUN npm ci

# --- build the admin panel / app ---
FROM base AS builder
ENV NODE_ENV=production
# Strapi's admin-panel Vite build is memory-heavy and gets OOM-killed on
# Railway's default builder without this. Must be set at build time.
ENV NODE_OPTIONS="--max-old-space-size=4096"
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

# --- minimal runtime image ---
FROM base AS runner
ENV NODE_ENV=production
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app .
RUN mkdir -p /app/public/uploads /app/.tmp
EXPOSE 1337
CMD ["npm", "start"]
