version: '3.8'

services:
  db:
    image: postgres:15
    container_name: afropreunariat_db
    restart: always
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: adminpassword
      POSTGRES_DB: afropreunariat_dev
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U admin -d afropreunariat_dev"]
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: afropreunariat_app
    restart: always
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://admin:adminpassword@db:5432/afropreunariat_dev?schema=public
      - NEXT_PUBLIC_SITE_URL=http://localhost:3000
    depends_on:
      db:
        condition: service_healthy

  admin:
    build:
      context: ./admin
      dockerfile: Dockerfile
    container_name: afropreunariat_admin
    restart: always
    ports:
      - "3001:3001"
    environment:
      - DATABASE_URL=postgresql://admin:adminpassword@db:5432/afropreunariat_dev?schema=public
      - NEXT_PUBLIC_SITE_URL=http://localhost:3000
      - NEXT_PUBLIC_ADMIN_URL=http://localhost:3001
    depends_on:
      db:
        condition: service_healthy

volumes:
  pgdata:
