services: db: image: ankane/pgvector:latest container_name: face_recognition_db restart: unless-stopped environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: face_recognition volumes: - postgres_data:/var/lib/postgresql/data - ./init.sql:/docker-entrypoint-initdb.d/init.sql - db_backups:/backups ports: - "127.0.0.1:5432:5432" healthcheck: test: [ "CMD-SHELL", "pg_isready -U postgres && psql -U postgres -d face_recognition -c 'SELECT 1' > /dev/null 2>&1", ] interval: 10s timeout: 5s retries: 10 start_period: 30s networks: - face_recognition_network # Ensures face_recognition DB exists and schema is applied when the volume was # created by an older run (PostgreSQL skips init and does not create the DB). db-init: image: ankane/pgvector:latest container_name: face_recognition_db_init depends_on: db: condition: service_healthy environment: PGPASSWORD: postgres volumes: - ./init.sql:/init.sql:ro entrypoint: ["/bin/sh", "-c"] command: - | set -e until psql -U postgres -h db -c 'SELECT 1' 2>/dev/null; do sleep 1; done if ! psql -U postgres -h db -d face_recognition -c 'SELECT 1' 2>/dev/null; then psql -U postgres -h db -c "CREATE DATABASE face_recognition" psql -U postgres -h db -d face_recognition -f /init.sql echo "Created database face_recognition and applied schema." else echo "Database face_recognition already exists." fi networks: - face_recognition_network restart: "no" api: build: context: ./api dockerfile: Dockerfile # Use the host's network during build so pip/apt can reach the internet # even when Docker's bridge/DNS is broken (fixes "[Errno 101] Network is # unreachable" during `pip install`). network: host args: BUILDKIT_INLINE_CACHE: 1 container_name: face_recognition_api restart: unless-stopped ports: - "127.0.0.1:8000:8000" environment: DATABASE_URL: postgresql://postgres:postgres@db:5432/face_recognition DB_MAX_RETRIES: "10" DB_RETRY_DELAY: "2" # Kavenegar SMS notifications SMS_ENABLED: "true" KAVENEGAR_API_KEY: "4A796970707061476C627347356B674750466173516161686739655456634A785342636173324A787A45493D" KAVENEGAR_TEMPLATE: "audingo-verify" depends_on: db-init: condition: service_completed_successfully volumes: - ./api:/app command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload healthcheck: test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""] interval: 30s timeout: 10s retries: 3 start_period: 30s networks: - face_recognition_network frontend: build: context: ./frontend # Build over the host network too (see note on the api service above). network: host container_name: face_recognition_frontend restart: unless-stopped ports: - "3000:3000" environment: # Server-side proxy: frontend container must reach API via service name API_BACKEND_URL: http://api:8000 depends_on: - api networks: - face_recognition_network # Automated daily database backup db-backup: image: ankane/pgvector:latest container_name: face_recognition_db_backup restart: unless-stopped depends_on: db: condition: service_healthy environment: PGPASSWORD: postgres volumes: - db_backups:/backups entrypoint: ["/bin/sh", "-c"] command: - | echo "🗄️ Database backup service started" echo " Backups run every 6 hours, keeping the last 30 copies" while true; do TIMESTAMP=$$(date +%Y%m%d_%H%M%S) BACKUP_FILE="/backups/face_recognition_$${TIMESTAMP}.sql.gz" echo "[$$TIMESTAMP] Starting backup..." if pg_dump -U postgres -h db -d face_recognition | gzip > "$$BACKUP_FILE"; then echo "[$$TIMESTAMP] ✓ Backup saved: $$BACKUP_FILE ($$(du -h "$$BACKUP_FILE" | cut -f1))" # Keep only the last 30 backups (= ~7.5 days at 6h intervals) ls -1t /backups/face_recognition_*.sql.gz 2>/dev/null | tail -n +31 | xargs -r rm -f echo "[$$TIMESTAMP] ✓ Old backups cleaned up" else echo "[$$TIMESTAMP] ✗ Backup FAILED" fi # Sleep 6 hours between backups sleep 21600 done networks: - face_recognition_network volumes: postgres_data: # Named volume — survives `docker compose down`. # WARNING: `docker compose down -v` or `docker volume rm` will DELETE all data. # Use `docker volume inspect face-recognition-authentication-system_postgres_data` # to find the host path if you need to back up the raw files. name: face_recognition_postgres_data db_backups: # Stores periodic pg_dump backups for disaster recovery name: face_recognition_db_backups networks: face_recognition_network: driver: bridge