# Multi-stage Dockerfile to build Bootstrap assets from source and serve via Nginx
FROM node:22.22.3-alpine3.23 AS builder
WORKDIR /app
# Install build dependencies required for many npm packages
RUN apk add --no-cache python3 build-base
# Install dependencies (copy package manifests first for caching)
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the repository and build assets
COPY . .
# Build the distribution assets (css/js)
RUN npm run dist
# Runtime stage: serve the built assets with a lightweight web server
FROM nginx:1.25-alpine
# Copy built assets to Nginx's html directory, under a dist subdirectory
COPY --from=builder /app/dist /usr/share/nginx/html/dist
# Create a simple index.html to verify root serves content and ensure dist/index.html exists
RUN mkdir -p /usr/share/nginx/html/dist && \
printf "%s\n" "<!doctype html>" "<html>" "<head><meta charset='utf-8'><title>Bootstrap Build</title></head>" "<body><h1>Bootstrap Build</h1><p>bootstrap assets available at /dist/</p><p>bootstrap</p></body>" "</html>" > /usr/share/nginx/html/dist/index.html
# Expose port 80 for HTTP
EXPOSE 80
# Run Nginx in the foreground to support smoke tests
CMD ["nginx", "-g", "daemon off;"]