| FROM oven/bun:latest as frontend-builder | |
| # Set working directory for frontend | |
| WORKDIR /build | |
| # Copy frontend package files from the correct path | |
| COPY frontend/package.json frontend/bun.lockb* ./ | |
| # Install ALL dependencies (including Next.js) | |
| RUN bun install | |
| # Copy frontend source | |
| COPY frontend/ ./ | |
| # Build the Next.js app | |
| RUN bun run build | |
| FROM oven/bun:latest | |
| # Use the existing user with UID 1000 (the 'bun' user) | |
| USER 1000 | |
| WORKDIR /app | |
| # Copy package files and install dependencies for backend | |
| COPY --chown=1000:1000 package.json bun.lockb* ./ | |
| RUN bun install --production | |
| # Copy backend application code | |
| COPY --chown=1000:1000 src/ ./src/ | |
| # Create frontend directory structure | |
| RUN mkdir -p ./frontend | |
| # Copy built Next.js app AND node_modules from builder stage | |
| COPY --from=frontend-builder --chown=1000:1000 /build/.next ./frontend/.next | |
| COPY --from=frontend-builder --chown=1000:1000 /build/public ./frontend/public | |
| COPY --from=frontend-builder --chown=1000:1000 /build/package.json ./frontend/package.json | |
| COPY --from=frontend-builder --chown=1000:1000 /build/next.config.mjs ./frontend/next.config.mjs | |
| COPY --from=frontend-builder --chown=1000:1000 /build/node_modules ./frontend/node_modules | |
| # Create necessary directories and set permissions | |
| RUN mkdir -p /app/logs /app/temp | |
| # Expose ports for both services (backend: 5000, frontend: 7860) | |
| EXPOSE 5000 | |
| EXPOSE 7860 | |
| # Set environment variables | |
| ENV NODE_ENV=production | |
| ENV BACKEND_PORT=5000 | |
| ENV FRONTEND_PORT=7860 | |
| # Start both services using a start script | |
| COPY --chown=1000:1000 start.sh ./ | |
| RUN chmod +x start.sh | |
| CMD ["./start.sh"] |