services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: ltt
      POSTGRES_PASSWORD: ltt
      POSTGRES_DB: ltt
    ports:
      - "5433:5432" # host 5432 is often taken by a local postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ltt"]
      interval: 2s
      timeout: 3s
      retries: 15

  server:
    build: ./server
    environment:
      DATABASE_URL: postgresql+asyncpg://ltt:ltt@postgres:5432/ltt
      FILES_DIR: /srv/data/files
      CORS_ORIGINS: '["http://localhost:5173","http://127.0.0.1:5173"]'
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "8001:8000"
    volumes:
      - ./data:/srv/data
      - ./server/app:/srv/app
      - ./server/alembic:/srv/alembic

volumes:
  postgres_data: