| # Use Node.js as base image since it's needed for the web build | |
| FROM node:20.11-alpine3.19 AS web-builder | |
| # Set working directory for web | |
| WORKDIR /app/web | |
| # Copy package files first | |
| COPY web/package.json web/yarn.lock ./ | |
| # Configure Node to use less memory and disable telemetry | |
| ENV NODE_OPTIONS="--max_old_space_size=2048" | |
| ENV NEXT_TELEMETRY_DISABLED=1 | |
| ENV NODE_ENV=production | |
| # Install only production dependencies | |
| RUN yarn install --production --frozen-lockfile --network-timeout 300000 | |
| # Copy web source files | |
| COPY web/ . | |
| # Build web app | |
| RUN yarn build | |
| # Python base image for final stage | |
| FROM python:3.10-slim-bookworm | |
| # Install only essential dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| nodejs \ | |
| npm \ | |
| --no-install-recommends && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy API files | |
| COPY api/ /app/api/ | |
| # Install Python dependencies | |
| WORKDIR /app/api | |
| RUN pip install --no-cache-dir poetry && \ | |
| poetry config virtualenvs.create false && \ | |
| poetry install --no-dev | |
| # Copy built web files from builder stage | |
| COPY --from=web-builder /app/web/.next /app/web/.next | |
| COPY --from=web-builder /app/web/public /app/web/public | |
| COPY --from=web-builder /app/web/node_modules /app/web/node_modules | |
| COPY --from=web-builder /app/web/package.json /app/web/package.json | |
| # Set environment variables | |
| ENV FLASK_APP=app.py \ | |
| EDITION=SELF_HOSTED \ | |
| DEPLOY_ENV=PRODUCTION \ | |
| CONSOLE_API_URL=http://127.0.0.1:5001 \ | |
| CONSOLE_WEB_URL=http://127.0.0.1:3000 \ | |
| SERVICE_API_URL=http://127.0.0.1:5001 \ | |
| APP_WEB_URL=http://127.0.0.1:3000 \ | |
| NODE_ENV=production | |
| # Expose ports | |
| EXPOSE 3000 5001 | |
| # Copy and setup entrypoint script | |
| COPY docker/entrypoint.sh /entrypoint.sh | |
| RUN chmod +x /entrypoint.sh | |
| # Start services | |
| CMD ["/entrypoint.sh"] |