diff --git a/Dockerfile b/Dockerfile index 9cd0fcf..097e7b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -# Multi-stage build for combined frontend + backend -FROM node:20-bullseye AS backend-builder +# Single stage build for workspaces +FROM node:20-bullseye AS builder -WORKDIR /app/backend +WORKDIR /app # Install Python + OR-Tools RUN apt-get update && apt-get install -y python3 python3-pip build-essential \ @@ -10,54 +10,21 @@ RUN apt-get update && apt-get install -y python3 python3-pip build-essential \ # Create symlink so python3 is callable as python RUN ln -sf /usr/bin/python3 /usr/bin/python -# Copy root package files -COPY package*.json ./ -COPY tsconfig.base.json ./ +# Copy all files +COPY . . -# Copy workspace package files -COPY backend/package*.json ./backend/ -COPY frontend/package*.json ./frontend/ - -# Install backend dependencies +# Install all dependencies (workspaces) RUN npm ci -# Copy source code -COPY backend/ ./backend/ -COPY frontend/ ./frontend/ - # Build backend RUN npm run build --workspace=backend -# Build frontend +# Build frontend RUN npm run build --workspace=frontend -# Copy database files manually -RUN cp -r src/database/ dist/database/ - # Verify Python and OR-Tools installation RUN python -c "from ortools.sat.python import cp_model; print('OR-Tools installed successfully')" -# Frontend build stage - UPDATED FOR VITE -FROM node:20-bullseye AS frontend-builder - -WORKDIR /app/frontend - -# Copy frontend files -COPY frontend/package*.json ./ -COPY frontend/tsconfig.json ./ -COPY frontend/vite.config.ts ./ -COPY frontend/index.html ./ - -# Install frontend dependencies -RUN npm ci - -# Copy frontend source -COPY frontend/src/ ./src/ -COPY frontend/public/ ./public/ - -# Build frontend with Vite -RUN npm run build - # Production stage FROM node:20-bookworm @@ -70,15 +37,17 @@ RUN npm install -g pm2 RUN mkdir -p /app/data # Copy backend built files -COPY --from=backend-builder /app/backend/package*.json ./ -COPY --from=backend-builder /app/backend/dist/ ./dist/ -COPY --from=backend-builder /app/backend/node_modules/ ./node_modules/ +COPY --from=builder /app/backend/dist/ ./dist/ +COPY --from=builder /app/backend/package*.json ./ -# Copy frontend built files - UPDATED FOR VITE (uses 'dist' instead of 'build') -COPY --from=frontend-builder /app/frontend/dist/ ./frontend-build/ +# Copy only production dependencies +COPY --from=builder /app/node_modules/ ./node_modules/ + +# Copy frontend built files +COPY --from=builder /app/frontend/dist/ ./frontend-build/ # Copy PM2 configuration -COPY ecosystem.config.cjs ./ +COPY --from=builder /app/ecosystem.config.cjs ./ # Create a non-root user and group - DEBIAN STYLE RUN groupadd -g 1001 nodejs && \ diff --git a/package.json b/package.json index 20ed4d0..b57c99d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "docker:build": "docker build -t schichtplan-app .", "docker:run": "docker run -p 3002:3002 schichtplan-app", - "build:all": "cd backend && npm run build && cd ../frontend && npm run build" + "build:all": "npm run build --workspace=backend && npm run build --workspace=frontend" }, "devDependencies": { "typescript": "^5.3.3"