build: Implement multi-stage Dockerfile for frontend production build, passing environment variables via build arguments.
This commit is contained in:
parent
5e65dd84f6
commit
605cbc3a8b
@ -53,19 +53,15 @@ services:
|
|||||||
condition: service_started
|
condition: service_started
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
# Next.js frontend
|
# Next.js frontend (production build)
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
- NEXT_PUBLIC_API_URL=http://192.168.50.130:8091
|
||||||
|
- NEXT_PUBLIC_WS_URL=ws://192.168.50.130:8091
|
||||||
container_name: sp-frontend
|
container_name: sp-frontend
|
||||||
environment:
|
|
||||||
- NEXT_PUBLIC_API_URL=http://192.168.50.130:8091
|
|
||||||
- NEXT_PUBLIC_WS_URL=ws://192.168.50.130:8091
|
|
||||||
volumes:
|
|
||||||
- ./frontend:/app
|
|
||||||
- frontend_node_modules:/app/node_modules
|
|
||||||
- frontend_next:/app/.next
|
|
||||||
ports:
|
ports:
|
||||||
- "3091:3000"
|
- "3091:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -75,5 +71,3 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
piston_packages:
|
piston_packages:
|
||||||
frontend_node_modules:
|
|
||||||
frontend_next:
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
FROM node:22-alpine
|
FROM node:22-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@ -6,19 +6,38 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN npm install
|
RUN npm ci
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Make entrypoint executable
|
# Build arguments for environment variables
|
||||||
RUN chmod +x /app/entrypoint.sh
|
ARG NEXT_PUBLIC_API_URL
|
||||||
|
ARG NEXT_PUBLIC_WS_URL
|
||||||
|
|
||||||
|
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||||
|
ENV NEXT_PUBLIC_WS_URL=$NEXT_PUBLIC_WS_URL
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production image
|
||||||
|
FROM node:22-alpine AS runner
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
# Copy necessary files from builder
|
||||||
|
COPY --from=builder /app/package*.json ./
|
||||||
|
COPY --from=builder /app/.next ./.next
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy public folder if exists
|
||||||
|
COPY --from=builder /app/public* ./public/
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Use entrypoint for dependency sync
|
# Run the production server
|
||||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
CMD ["npm", "run", "start"]
|
||||||
|
|
||||||
# Run the development server
|
|
||||||
CMD ["npm", "run", "dev"]
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user