|
| 1 | +# Multi-stage Dockerfile for monorepo |
| 2 | +# This is optional - docker-compose is the recommended approach |
| 3 | + |
| 4 | +# Stage 1: Build Frontend |
| 5 | +FROM oven/bun:1 AS frontend-build |
| 6 | +WORKDIR /app |
| 7 | + |
| 8 | +# Copy root dependencies and common folder |
| 9 | +COPY package*.json bun.lock ./ |
| 10 | +COPY common/ ./common/ |
| 11 | + |
| 12 | +# Copy ALL workspace directories so bun can resolve workspaces |
| 13 | +COPY server/ ./server/ |
| 14 | +COPY web/ ./web/ |
| 15 | + |
| 16 | +# Install dependencies from root |
| 17 | +RUN bun install |
| 18 | + |
| 19 | +# Set working directory to web for build |
| 20 | +WORKDIR /app/web |
| 21 | +ARG VITE_BACKEND_URL=http://localhost:5000 |
| 22 | +ENV VITE_BACKEND_URL=$VITE_BACKEND_URL |
| 23 | +RUN bun run build |
| 24 | + |
| 25 | +# Stage 2: Build Backend |
| 26 | +FROM oven/bun:1 AS backend-build |
| 27 | +WORKDIR /app |
| 28 | + |
| 29 | +# Copy root dependencies and common folder |
| 30 | +COPY package*.json bun.lock ./ |
| 31 | +COPY common/ ./common/ |
| 32 | + |
| 33 | +# Copy ALL workspace directories so bun can resolve workspaces |
| 34 | +COPY server/ ./server/ |
| 35 | +COPY web/ ./web/ |
| 36 | + |
| 37 | +# Install dependencies from root |
| 38 | +RUN bun install |
| 39 | + |
| 40 | +# Stage 3: Production |
| 41 | +FROM oven/bun:1 |
| 42 | +WORKDIR /app |
| 43 | + |
| 44 | +# Install nginx and curl |
| 45 | +USER root |
| 46 | +RUN apt-get update && apt-get install -y nginx curl && rm -rf /var/lib/apt/lists/* |
| 47 | + |
| 48 | +# Copy common folder to production image |
| 49 | +COPY common/ ./common/ |
| 50 | + |
| 51 | +# Copy backend from build stage |
| 52 | +COPY --from=backend-build /app/server /app/server |
| 53 | +WORKDIR /app/server |
| 54 | +RUN mkdir -p public/uploads |
| 55 | + |
| 56 | +# Copy frontend build to nginx |
| 57 | +COPY --from=frontend-build /app/web/dist /usr/share/nginx/html |
| 58 | +COPY web/nginx.conf /etc/nginx/conf.d/default.conf |
| 59 | + |
| 60 | +# Create startup script |
| 61 | +RUN echo '#!/bin/sh' > /app/start.sh && \ |
| 62 | + echo 'nginx &' >> /app/start.sh && \ |
| 63 | + echo 'cd /app/server && bun run dev' >> /app/start.sh && \ |
| 64 | + chmod +x /app/start.sh |
| 65 | + |
| 66 | +# Switch back to bun user |
| 67 | +USER bun |
| 68 | + |
| 69 | +EXPOSE 80 5000 |
| 70 | + |
| 71 | +CMD ["/app/start.sh"] |
0 commit comments