fix: Update Docker config for Next.js frontend
- Updated Dockerfile.frontend to use Next.js instead of React CRA - Multi-stage build for optimized image size - Use NEXT_PUBLIC_API_URL instead of REACT_APP_API_URL - Updated docker-compose.yml to pass correct env variable - Frontend now starts with 'npm start' instead of serve 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ecf330bbc9
commit
68c0648cf1
@ -51,8 +51,7 @@ services:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile.frontend
|
||||
args:
|
||||
REACT_APP_API_URL: http://backend:8000
|
||||
CACHEBUST: ${CACHEBUST:-1}
|
||||
NEXT_PUBLIC_API_URL: http://backend:8000
|
||||
container_name: evoting_frontend
|
||||
ports:
|
||||
- "${FRONTEND_PORT:-3000}:3000"
|
||||
|
||||
@ -1,34 +1,36 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY frontend/package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY frontend/ .
|
||||
|
||||
# Build argument for API URL (Next.js uses NEXT_PUBLIC_)
|
||||
ARG NEXT_PUBLIC_API_URL=http://backend:8000
|
||||
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||
|
||||
# Build Next.js app
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copier package.json
|
||||
COPY frontend/package*.json ./
|
||||
|
||||
# Installer dépendances
|
||||
RUN npm install --legacy-peer-deps
|
||||
|
||||
# Copier code source
|
||||
COPY frontend/ .
|
||||
|
||||
# Clean previous builds
|
||||
RUN rm -rf build/
|
||||
|
||||
# Build argument for API URL
|
||||
ARG REACT_APP_API_URL=http://backend:8000
|
||||
ENV REACT_APP_API_URL=${REACT_APP_API_URL}
|
||||
|
||||
# Force rebuild timestamp (bust cache)
|
||||
ARG CACHEBUST=1
|
||||
ENV CACHEBUST=${CACHEBUST}
|
||||
|
||||
# Build avec npm run build (CRA standard)
|
||||
RUN npm run build
|
||||
|
||||
# Installer serve pour servir la build
|
||||
RUN npm install -g serve
|
||||
# Copy only necessary files from builder
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Servir la build
|
||||
CMD ["serve", "-s", "build", "-l", "3000"]
|
||||
# Start Next.js in production mode
|
||||
CMD ["npm", "start"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user