version: "3.8"
services:
  # Configuration for the WwaveAPI service
  WwaveAPI:
    # Use the image built from the Dockerfile in the current directory
    build:
      context: .
      args:
        - TAG=${TAG}  # Pass TAG as a build argument, useful if needed inside the Dockerfile
    image: wwave-api:${TAG}  # Tag the image using the TAG environment variable
    container_name: WwaveAPI

    # Define the network and its settings
    networks:
      wwaveapi_net:
        ipv4_address: 172.30.0.4

    # Map port 5000 of the host to port 5000 of the container
    ports:
      - "5000:5000"

    # Bind mount the logs directory from the host to the container
    volumes:
      - api_dir:/usr/src/WwaveAPI
      - /home/devwwavecom/logs/API-container-logs:/usr/src/WwaveAPI/logs
      
      # logs_dir:/usr/src/WwaveAPI/logs  # Mount the logs volume now using a different method

    # Specify dependencies on other services
    depends_on:
      - redis
      - celery

    # Set environment variables
    environment:
      - REDIS_PORT=6379

  # Configuration for the Celery worker service
  celery:
    build:
      context: .
      args:
        - TAG=${TAG}  # Pass TAG as a build argument, useful if needed inside the Dockerfile
    image: wwave-api-celery:${TAG}  # Optionally tag the celery service image as well
    container_name: WwaveAPI-celery
    command: celery --app=src.tasks worker --loglevel=info
    depends_on:
      - redis
    environment:
      - REDIS_PORT=6379
      - REDIS_HOST="172.30.0.3"
    networks:
      wwaveapi_net:
        ipv4_address: 172.30.0.5
    volumes:
      - /home/devwwavecom/logs/API-container-logs:/usr/src/WwaveAPI/logs

  # Configuration for the Redis service
  redis:
    image: "redis"
    container_name: WwaveAPI-redis
    ports:
      - "5023:6379"
    networks:
      wwaveapi_net:
        ipv4_address: 172.30.0.3
    volumes:
    #  - /home/devwwavecom/logs/API-container-logs:/usr/src/WwaveAPI/logs
      - redis_data:/data

# Define networks
networks:
  wwaveapi_net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.30.0.0/24

# Define volumes
volumes:
  api_dir:  # This volume is for the api directory
  # logs_dir:  # Define a volume for logs, now using a different method
  redis_data:
