Skip to content

Commit 4c7cf14

Browse files
Added frontend dockerfile
1 parent a9f48a0 commit 4c7cf14

2 files changed

Lines changed: 88 additions & 20 deletions

File tree

content-gen/src/.dockerignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Docker ignore file for src/ build context
2+
# Excludes unnecessary files from Docker build
3+
4+
# Dependencies (will be installed fresh in container)
5+
**/node_modules/
6+
**/__pycache__/
7+
*.pyc
8+
9+
# Build outputs (will be built in container)
10+
static/
11+
**/dist/
12+
frontend-server/static/
13+
14+
# Development files
15+
*.log
16+
*.md
17+
.git/
18+
.gitignore
19+
.vscode/
20+
.env
21+
.env.*
22+
!.env.template
23+
24+
# Test files
25+
**/*.test.*
26+
**/*.spec.*
27+
__tests__/
28+
coverage/
29+
tests/
30+
31+
# IDE and OS files
32+
.DS_Store
33+
Thumbs.db
34+
*.swp
35+
*.swo
36+
37+
# Deployment artifacts
38+
*.zip
39+
frontend-deploy.zip
40+
41+
# Backend not needed for frontend build (and vice versa)
42+
# Comment out if building full-stack image

content-gen/src/WebApp.Dockerfile

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
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+
# ============================================
26

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
411

512
WORKDIR /app
613

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 ./
1116

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
1519

16-
# Copy application code
17-
COPY . .
20+
# Copy frontend source code
21+
COPY frontend/ ./
1822

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
2326

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
2652

2753
# Health check
2854
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))"
3056

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

Comments
 (0)