Replace two-container setup (separate backend + nginx frontend) with a single image that runs both via supervisord: - New Dockerfile: Node stage builds React, Python+nginx stage is the runtime - supervisord.conf: manages uvicorn (api_server.py) + nginx as sibling procs - nginx.conf: proxy_pass updated to localhost:8000 (same container) - docker-compose.yml: simplified to one service on port 80 Deploy: docker-compose up -d # or docker build -t flight-radar . && docker run -p 80:80 flight-radar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.6 KiB
Docker
55 lines
1.6 KiB
Docker
# ── 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"]
|