# 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 ENV NODE_OPTIONS="--max_old_space_size=2048" ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production # Install dependencies with memory optimizations RUN yarn config set network-timeout 300000 && \ yarn install --frozen-lockfile --network-timeout 300000 && \ yarn cache clean # Copy web source files COPY web/ . # Build web app with optimizations 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 with memory optimizations WORKDIR /app/api ENV POETRY_VIRTUALENVS_CREATE=false RUN pip install --no-cache-dir poetry && \ # Install dependencies in smaller groups to avoid memory issues poetry install --only main --no-interaction --no-ansi \ --no-root \ --with runtime-dependencies && \ poetry install --only main --no-interaction --no-ansi \ --no-root \ --with core-dependencies && \ poetry install --only main --no-interaction --no-ansi # 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"]