FROM node:20-alpine AS builder
WORKDIR /app
# Copy repository contents
COPY . .
# Install dependencies if a package.json exists
RUN if [ -f package.json ]; then \
if [ -f package-lock.json ]; then npm ci; else npm install; fi; \
else \
echo "No package.json found; skipping npm install"; \
fi
# Build if a build script is defined in package.json
RUN if [ -f package.json ] && grep -q '"build"' package.json; then npm run build; fi
# Stage 2: Runtime image serving assets with Nginx
FROM nginx:1.25-alpine
# Clear default content
RUN rm -rf /usr/share/nginx/html/*
# Copy built assets (or full repo) from builder into nginx html directory
COPY --from=builder /app/ /usr/share/nginx/html/
# Ensure there is an index page
RUN [ -f /usr/share/nginx/html/index.html ] || sh -lc 'echo "<!doctype html><html><head><title>Font Awesome</title></head><body><h1>Font Awesome Static Assets</h1></body></html>" > /usr/share/nginx/html/index.html'
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]