|
1 | | -# Content Generation Solution Accelerator - Docker Image |
| 1 | +# ============================================ |
| 2 | +# Frontend Dockerfile |
| 3 | +# Multi-stage build for Content Generation Frontend |
| 4 | +# Combines: frontend (React/Vite) + frontend-server (Node.js proxy) |
| 5 | +# ============================================ |
2 | 6 |
|
3 | | -FROM python:3.11-slim |
| 7 | +# ============================================ |
| 8 | +# Stage 1: Build the React frontend with Vite |
| 9 | +# ============================================ |
| 10 | +FROM node:20-alpine AS frontend-build |
4 | 11 |
|
5 | 12 | WORKDIR /app |
6 | 13 |
|
7 | | -# Install system dependencies |
8 | | -RUN apt-get update && apt-get install -y \ |
9 | | - curl \ |
10 | | - && rm -rf /var/lib/apt/lists/* |
| 14 | +# Copy frontend package files |
| 15 | +COPY frontend/package*.json ./ |
11 | 16 |
|
12 | | -# Copy requirements first for layer caching |
13 | | -COPY requirements.txt . |
14 | | -RUN pip install --no-cache-dir -r requirements.txt |
| 17 | +# Install dependencies |
| 18 | +RUN npm ci |
15 | 19 |
|
16 | | -# Copy application code |
17 | | -COPY . . |
| 20 | +# Copy frontend source code |
| 21 | +COPY frontend/ ./ |
18 | 22 |
|
19 | | -# Set environment variables |
20 | | -ENV PYTHONPATH=/app |
21 | | -ENV PORT=8000 |
22 | | -ENV PYTHONUNBUFFERED=1 |
| 23 | +# Build the frontend (outputs to ../static, but we're in /app so it goes to /static) |
| 24 | +# Override outDir to keep it in the container context |
| 25 | +RUN npm run build -- --outDir ./dist |
23 | 26 |
|
24 | | -# Expose port |
25 | | -EXPOSE 8000 |
| 27 | +# ============================================ |
| 28 | +# Stage 2: Production Node.js server |
| 29 | +# ============================================ |
| 30 | +FROM node:20-alpine AS production |
| 31 | + |
| 32 | +WORKDIR /app |
| 33 | + |
| 34 | +# Copy frontend-server package files |
| 35 | +COPY frontend-server/package*.json ./ |
| 36 | + |
| 37 | +# Install only production dependencies |
| 38 | +RUN npm ci --only=production |
| 39 | + |
| 40 | +# Copy the server code |
| 41 | +COPY frontend-server/server.js ./ |
| 42 | + |
| 43 | +# Copy built frontend assets from stage 1 |
| 44 | +COPY --from=frontend-build /app/dist ./static |
| 45 | + |
| 46 | +# Environment variables (can be overridden at runtime) |
| 47 | +ENV PORT=8080 |
| 48 | +ENV NODE_ENV=production |
| 49 | + |
| 50 | +# Expose the port |
| 51 | +EXPOSE 8080 |
26 | 52 |
|
27 | 53 | # Health check |
28 | 54 | HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ |
29 | | - CMD curl -f http://localhost:${PORT}/health || exit 1 |
| 55 | + CMD node -e "require('http').get('http://localhost:' + (process.env.PORT || 8080) + '/', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))" |
30 | 56 |
|
31 | | -# Run the application |
32 | | -CMD ["hypercorn", "app:app", "--bind", "0.0.0.0:8000", "--workers", "1"] |
| 57 | +# Start the server |
| 58 | +CMD ["node", "server.js"] |
0 commit comments