Dockerfile 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Stage 1: Build frontend
  2. FROM --platform=$TARGETPLATFORM node:20-slim AS frontend-builder
  3. WORKDIR /app/frontend
  4. # Copy frontend package files
  5. COPY frontend/package*.json ./
  6. # Install dependencies
  7. RUN npm ci
  8. # Copy frontend source
  9. COPY frontend/ ./
  10. # Build frontend
  11. RUN npm run build
  12. # Stage 2: Python backend with nginx
  13. FROM --platform=$TARGETPLATFORM python:3.11-slim-bookworm
  14. # Faster, repeatable builds
  15. ENV PYTHONDONTWRITEBYTECODE=1 \
  16. PYTHONUNBUFFERED=1 \
  17. PIP_NO_CACHE_DIR=1 \
  18. PIP_DISABLE_PIP_VERSION_CHECK=1
  19. WORKDIR /app
  20. COPY requirements.txt ./
  21. RUN apt-get update && apt-get install -y --no-install-recommends \
  22. gcc g++ make libjpeg-dev zlib1g-dev git \
  23. # GPIO/NeoPixel support for DW LEDs
  24. python3-dev python3-pip \
  25. libgpiod2 libgpiod-dev \
  26. scons \
  27. systemd \
  28. # Nginx for serving frontend
  29. nginx \
  30. # Docker CLI for container self-restart/update
  31. ca-certificates curl gnupg \
  32. && pip install --upgrade pip \
  33. && pip install --no-cache-dir -r requirements.txt \
  34. # Install Docker CLI from official Docker repo
  35. && install -m 0755 -d /etc/apt/keyrings \
  36. && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
  37. && chmod a+r /etc/apt/keyrings/docker.gpg \
  38. && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list \
  39. && apt-get update \
  40. && apt-get install -y --no-install-recommends docker-ce-cli docker-compose-plugin \
  41. && apt-get purge -y gcc g++ make scons \
  42. && rm -rf /var/lib/apt/lists/*
  43. # Copy nginx configuration
  44. COPY nginx.conf /etc/nginx/sites-available/default
  45. RUN rm -f /etc/nginx/sites-enabled/default && \
  46. ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
  47. # Copy backend code
  48. COPY . .
  49. # Copy built frontend from Stage 1
  50. COPY --from=frontend-builder /app/static/dist ./static/dist
  51. # Ensure startup script is executable
  52. RUN chmod +x /app/start.sh
  53. # Expose ports: 80 for frontend (nginx), 8080 for backend API
  54. EXPOSE 80 8080
  55. CMD ["/app/start.sh"]