version: '3.8'

services:
  db:
    image: postgres:13
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=testarena
    networks:
      - app-network
    restart: always

  backend:
    build: ./backend
    command: uvicorn app.main:app --host 0.0.0.0 --port 8000
    volumes:
      - ./backend:/app
      - ./results:/results
    environment:
      - DATABASE_URL=postgresql://user:password@db/testarena
      - SCRIPTS_DIR=/app/scripts
    depends_on:
      - db
    networks:
      - app-network
    restart: always

  frontend:
    build: 
      context: ./frontend
      dockerfile: Dockerfile
    networks:
      - app-network
    restart: always

  caddy:
    image: caddy:2
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./results:/srv/results
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - backend
      - frontend
    networks:
      - app-network
    restart: always

networks:
  app-network:
    driver: bridge

volumes:
  postgres_data:
  caddy_data:
  caddy_config:
