version: '3'
services:

#################################
#            APACHE             #
#################################

  gui:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/cristie_httpd
    depends_on:
      - main_db
      - web_boot
    ports:
      - 80:80/tcp
      - 443:443/tcp
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
      - ssl:/etc/pki/
    networks:
      - frontend
      - discovery

#################################
#             JAVA              #
#################################

  control:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/control
    depends_on:
      - main_db
      - token_manager
    logging:
      driver: journald
    ports:
      - 5000:5000/tcp
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
    networks:
      - frontend
      - internal
      - discovery
    environment: 
      hostMachine: ${HOSTMACHINE}
    extra_hosts:
      hostMachine: ${HOSTMACHINE}

  orchestration:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/orchestration
    depends_on:
      - main_db
    ports:
      - 5002:5002/tcp
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
      - shared_logs:/var/shared_logs/
    networks:
      - frontend
      - internal
      - discovery
    environment: 
      hostMachine: ${HOSTMACHINE}
    extra_hosts:
      hostMachine: ${HOSTMACHINE}


#################################
#	           PYTHON             #
#################################

  software_deployment:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/software_deployment
    depends_on:
      - main_db
      - update_management
    logging:
      driver: journald
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - agents:/var/agents/
      - logs:/var/log/cristie
    networks:
      - frontend
      - internal
      - discovery

  backup_management:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/backup_management
    cap_add: 
      - SYS_ADMIN
      - DAC_READ_SEARCH
    depends_on:
      - main_db
    logging:
      driver: journald
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - agents:/var/agents/
      - logs:/var/log/cristie
    networks:
      - frontend
      - internal
      - discovery

  discovery_service:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/discovery
    depends_on:
      - main_db
    ports:
      - 4000:4000/udp
      - 4001:4001/udp
      - 4001:4001/tcp
    logging:
      driver: journald
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
    networks:
      - frontend
      - internal
      - discovery

  update_management:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/update_management
    depends_on:
      - main_db
    logging:
      driver: journald
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
      - agents:/var/agents/
      - isos:/var/isos/
    networks:
      - frontend
      - internal
      - discovery

  user_management:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/user_management
    depends_on:
      - main_db
    logging:
      driver: journald    
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
    networks:
      - frontend
      - internal
      - discovery

  log_provider:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/log_provider
    depends_on:
      - main_db
    logging:
      driver: journald
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - logs:/var/log/cristie
      - shared_logs:/var/shared_logs/
    networks:
      - frontend
      - discovery

  web_boot:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/web_boot
    depends_on:
      - nfs
      - smb
    logging:
      driver: journald
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - isos:/var/isos/
      - httpd_conf:/etc/httpd/conf.d/
      - logs:/var/log/cristie
      - uuid:/etc/cristie/
      - ssl:/etc/pki/
    networks:
      - frontend
      - discovery

  log_analysis:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/log_analysis
    depends_on:
      - main_db
    logging:
      driver: journald
    volumes:
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
    networks:
      - frontend
      - discovery
      - internal
      
#################################
#            PRODUCTS           #
#################################      
  cbmr:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/cbmr
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery
      
  cobmr:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/cobmr
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery

  abmr:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/abmr
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery

  nbmr:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/nbmr
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery
  
  tbmr:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/tbmr
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery
  
  p4vm:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/p4vm
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery
      
  cm:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/cm
    depends_on:
      - update_management
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
      - DAC_OVERRIDE
    privileged: true
    environment: 
      hostMachine: ${HOSTMACHINE}
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - uuid:/etc/cristie/
    networks:
      - discovery

#################################
#            OTHER              #
#################################

  token_manager:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/token_manager
    depends_on:
      - main_db
    volumes:
      - httpd_conf:/etc/httpd/conf.d/
      - logs:/var/log/cristie
      - uuid:/etc/cristie/
      # Volume ensures licensing info is kept consistent 
      - license:/etc/cbmr
      - license_root:/".. "
    networks:
      - frontend
      - discovery

  nfs:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/cristie_nfs
    ports:
      - 111:111/tcp
      - 2049:2049/tcp
      - 2049:2049/udp
      - 662:662/tcp
      - 662:662/udp
      - 892:892/tcp
      - 892:892/udp
      - 875:875/tcp
      - 875:875/udp
      - 32769:32769/udp
      - 32803:32803/tcp
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    depends_on:
      - update_management
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - shared_logs:/var/shared_logs/
    networks:
      - frontend
      - internal
      - discovery

  smb:
    image: ${DOCKER_REGISTRY}/cristie-va-composition/cristie_smb
    ports:
      - 137:137/udp
      - 138:138/udp
      - 139:139/tcp
      - 445:445/tcp
    # Capacities needed to host volumes
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    depends_on:
      - update_management
    volumes:
      - agents:/var/agents/
      - isos:/var/isos/
      - shared_logs:/var/shared_logs/
    networks:
      - frontend
      - internal
      - discovery

  main_db:
    image: mariadb:latest
    command: --lower_case_table_names=1 --log-bin
    restart: always
    environment:
      - MYSQL_USER=user
      - MYSQL_PASSWORD=cristie
      - MYSQL_DATABASE=cristie
      - MYSQL_ROOT_PASSWORD=cristie
    # Health check ensures nothing starts till the user is setup
    healthcheck:
      test: mysqladmin -uuser -pcristie ping
      interval: 2s
      timeout: 5s
      retries: 30
    volumes:
      - "./mysql/cristie.sql:/docker-entrypoint-initdb.d/cristie.sql"
      - "./mysql/my.cnf:/etc/mysql/conf.d/my.cnf"
      - main_db:/var/lib/mysql
      - uuid:/etc/cristie/
      - logs:/var/log/cristie
    networks:
      - internal
      - discovery

networks:
  frontend:
  internal: 
  discovery:

volumes:
  main_db:
  httpd_conf:
  uuid:
  agents:
  isos:
  logs:
  shared_logs:
  license:
  license_root:
  ssl:
