Spaces:
Sleeping
Sleeping
| # Stage 1: Build the Python backend (switching to Debian-based image) | |
| FROM python:3.11-slim AS backend-builder | |
| WORKDIR /app | |
| # Install build tools using apt-get | |
| RUN apt-get update && apt-get install -y --no-install-recommends gcc && rm -rf /var/lib/apt/lists/* | |
| COPY requirements.api.txt . | |
| RUN pip install --no-cache-dir -r requirements.api.txt | |
| COPY chess_engine/ ./chess_engine | |
| COPY main.py . | |
| COPY app.py . | |
| # Stage 2: Final image (switching to Debian-based image) | |
| FROM python:3.11-slim | |
| # Install Node.js, npm, Stockfish, and dos2unix using apt-get | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends curl dos2unix && \ | |
| curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ | |
| apt-get install -y --no-install-recommends nodejs stockfish && \ | |
| rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # Copy the installed Python dependencies | |
| COPY --from=backend-builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/ | |
| COPY --from=backend-builder /app/chess_engine ./chess_engine | |
| COPY --from=backend-builder /app/main.py . | |
| COPY --from=backend-builder /app/app.py . | |
| # Copy frontend files | |
| COPY web/ ./web/ | |
| # Build the frontend | |
| WORKDIR /app/web | |
| RUN npm install | |
| # Add environment variable to skip TypeScript errors during build | |
| ENV TSC_COMPILE_ON_ERROR=true | |
| RUN npm run build | |
| # Copy the built frontend files to the location expected by the backend | |
| WORKDIR /app | |
| RUN mkdir -p ./dist | |
| RUN cp -r /app/web/dist/* ./dist/ | |
| # Copy the entrypoint script and ensure it's executable | |
| COPY docker-entrypoint.sh . | |
| RUN dos2unix docker-entrypoint.sh && \ | |
| chmod +x docker-entrypoint.sh | |
| # Expose the ports | |
| EXPOSE 8000 | |
| EXPOSE 5173 | |
| ENTRYPOINT ["./docker-entrypoint.sh"] |