volumes:
  database:

services:
  database:
    image: postgres:latest
    volumes:
      - database:/var/lib/postgresql/data:z
    restart: unless-stopped
    env_file:
      - .env
    healthcheck:
      test:
        [
          'CMD-SHELL',
          'pg_isready -U ${POSTGRES_USER:-kycnot} -d ${POSTGRES_DATABASE:-kycnot}',
        ]
      interval: 10s
      timeout: 5s
      retries: 5

  pyworker:
    build:
      context: ./pyworker
    image: kycnotme/pyworker:${PYWORKER_IMAGE_TAG:-latest}
    restart: always
    env_file:
      - .env

  crawl4ai:
    image: unclecode/crawl4ai:basic-amd64
    expose:
      - '11235'
    env_file:
      - .env
    volumes:
      - /dev/shm:/dev/shm
    deploy:
      resources:
        limits:
          memory: 4G
        reservations:
          memory: 1G

  redis:
    image: redis:latest
    restart: unless-stopped
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5

  astro:
    build:
      dockerfile: web/Dockerfile
    image: kycnotme/astro:${ASTRO_IMAGE_TAG:-latest}
    restart: unless-stopped
    env_file:
      - .env
    depends_on:
      database:
        condition: service_healthy
      redis:
        condition: service_healthy
    expose:
      - 4321
    healthcheck:
      test:
        [
          'CMD',
          'curl',
          '-k',
          '--silent',
          '--fail',
          'http://localhost:4321/internal-api/healthcheck',
        ]
      interval: 10s
      timeout: 5s
      retries: 5
