# ── Stage 1: Build React frontend ───────────────────────────────────────── FROM node:20-alpine AS frontend-builder WORKDIR /app COPY frontend/package*.json ./ RUN npm ci COPY frontend/ . RUN npm run build # ── Stage 2: Single runtime image ───────────────────────────────────────── FROM python:3.11-slim ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 # Install nginx, supervisor, and gcc (for some pip packages) RUN apt-get update && apt-get install -y --no-install-recommends \ nginx \ supervisor \ gcc \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Backend source COPY api_server.py airports.py cache.py ./ COPY database/ ./database/ # Frontend build output COPY --from=frontend-builder /app/dist /usr/share/nginx/html # Config files COPY nginx.conf /etc/nginx/conf.d/default.conf COPY supervisord.conf /etc/supervisor/conf.d/app.conf # Remove the default nginx site RUN rm -f /etc/nginx/sites-enabled/default # Pre-fetch airport data and initialise the database at build time RUN mkdir -p data && \ python -c "from airports import download_and_build_airport_data; download_and_build_airport_data()" && \ python database/init_db.py EXPOSE 80 HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ CMD wget -q --spider http://localhost/ || exit 1 CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/conf.d/app.conf"]