# Stage 1: Build the VuePress application
FROM node:25-alpine AS builder

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json (if available)
COPY wiki-src/package*.json ./

# Install dependencies
RUN npm install --legacy-peer-deps

# Copy the rest of the application code
COPY wiki-src/ .

# Build the application
# VuePress build command usually outputs to .vuepress/dist
# Increase Node.js memory limit to prevent heap out of memory errors
ENV NODE_OPTIONS="--max-old-space-size=4096"
RUN npm run build

# Stage 2: Serve the application with Nginx
FROM gitea.rwcloud.ch/official-docker-images/nginx:alpine

# Copy the built files from the builder stage
# Adjust the source path if your VuePress config outputs somewhere else
# Common paths: src/.vuepress/dist or .vuepress/dist
COPY --from=builder /app/src/.vuepress/dist /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]