diff --git a/flight-comparator/Dockerfile b/flight-comparator/Dockerfile deleted file mode 100644 index 0006568..0000000 --- a/flight-comparator/Dockerfile +++ /dev/null @@ -1,55 +0,0 @@ -# ── 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 \ - git \ - && 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"] diff --git a/flight-comparator/Dockerfile.backend b/flight-comparator/Dockerfile.backend new file mode 100644 index 0000000..0f4f4df --- /dev/null +++ b/flight-comparator/Dockerfile.backend @@ -0,0 +1,30 @@ +FROM python:3.11-slim + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + git \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY api_server.py airports.py cache.py ./ +COPY database/ ./database/ + +# 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 8000 + +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ + CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1 + +CMD ["python", "api_server.py"] diff --git a/flight-comparator/Dockerfile.frontend b/flight-comparator/Dockerfile.frontend new file mode 100644 index 0000000..62e2f23 --- /dev/null +++ b/flight-comparator/Dockerfile.frontend @@ -0,0 +1,19 @@ +# ── Stage 1: Build React frontend ───────────────────────────────────────── +FROM node:20-alpine AS builder + +WORKDIR /app +COPY frontend/package*.json ./ +RUN npm ci +COPY frontend/ . +RUN npm run build + +# ── Stage 2: Serve with nginx ────────────────────────────────────────────── +FROM nginx:alpine + +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD wget -q --spider http://localhost/ || exit 1 diff --git a/flight-comparator/docker-compose.yml b/flight-comparator/docker-compose.yml index 707356e..14f67b8 100644 --- a/flight-comparator/docker-compose.yml +++ b/flight-comparator/docker-compose.yml @@ -1,15 +1,28 @@ services: - app: - build: . - container_name: flight-radar + backend: + build: + context: . + dockerfile: Dockerfile.backend + container_name: flight-radar-backend restart: unless-stopped ports: - - "80:80" + - "8000:8000" environment: - DATABASE_PATH=/app/data/cache.db volumes: - flight-radar-data:/app/data + frontend: + build: + context: . + dockerfile: Dockerfile.frontend + container_name: flight-radar-frontend + restart: unless-stopped + ports: + - "80:80" + depends_on: + - backend + volumes: flight-radar-data: driver: local diff --git a/flight-comparator/nginx.conf b/flight-comparator/nginx.conf index c36c147..23b180d 100644 --- a/flight-comparator/nginx.conf +++ b/flight-comparator/nginx.conf @@ -17,7 +17,7 @@ server { # API proxy location /api/ { - proxy_pass http://localhost:8000; + proxy_pass http://backend:8000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -30,7 +30,7 @@ server { # Health check endpoint proxy location /health { - proxy_pass http://localhost:8000; + proxy_pass http://backend:8000; proxy_http_version 1.1; proxy_set_header Host $host; } diff --git a/flight-comparator/supervisord.conf b/flight-comparator/supervisord.conf deleted file mode 100644 index 10fd68d..0000000 --- a/flight-comparator/supervisord.conf +++ /dev/null @@ -1,24 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/dev/null -logfile_maxbytes=0 -pidfile=/tmp/supervisord.pid - -[program:api] -command=python /app/api_server.py -directory=/app -autostart=true -autorestart=true -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 - -[program:nginx] -command=nginx -g "daemon off;" -autostart=true -autorestart=true -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0