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: .
|
context: .
|
||||||
dockerfile: docker/Dockerfile.frontend
|
dockerfile: docker/Dockerfile.frontend
|
||||||
args:
|
args:
|
||||||
REACT_APP_API_URL: http://backend:8000
|
NEXT_PUBLIC_API_URL: http://backend:8000
|
||||||
CACHEBUST: ${CACHEBUST:-1}
|
|
||||||
container_name: evoting_frontend
|
container_name: evoting_frontend
|
||||||
ports:
|
ports:
|
||||||
- "${FRONTEND_PORT:-3000}:3000"
|
- "${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
|
FROM node:20-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copier package.json
|
# Copy only necessary files from builder
|
||||||
COPY frontend/package*.json ./
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder /app/.next ./.next
|
||||||
# Installer dépendances
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
RUN npm install --legacy-peer-deps
|
COPY --from=builder /app/package.json ./package.json
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Servir la build
|
# Start Next.js in production mode
|
||||||
CMD ["serve", "-s", "build", "-l", "3000"]
|
CMD ["npm", "start"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user