version: '3.5'

networks:
  aix-docker-cc:
    name: aix-docker-cc
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: ${NET_SUBNET:-10.12.25}.0/24
        gateway: ${NET_SUBNET:-10.12.25}.1          
    driver_opts:
      com.docker.network.bridge.name: aix-docker-cc

services:
  nodejs:
    image: ${IMAGE_BASE}/nodejs:18.18.2
    container_name: nodejs
    environment:
      - PACKAGE_PATH=${PACKAGE_PATH}
    volumes:
      - "${WWWROOT_PATH}:/data/wwwroot"
    working_dir: /data/wwwroot/
    extra_hosts:
      - "host.docker.internal:host-gateway"
    privileged: true
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.200

  elasticsearch:
    image: ${IMAGE_BASE}/elasticsearch:${ELK_VERSION:-7.17.7}
    container_name: elasticsearch
    restart: always
    environment:
      - cluster.name=cc-docker-cluster
      - node.name=cc-docker-node
      - bootstrap.memory_lock=true
      - http.cors.enabled=true
      - http.cors.allow-origin="*"
      # - xpack.security.transport.ssl.enabled=false
      - xpack.security.enabled=true
      - xpack.security.authc.api_key.enabled=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx1024m"
      # - discovery.seed_hosts=
      # - cluster.initial_master_nodes=cc-docker-node
      - discovery.type=single-node
      - ELASTIC_PASSWORD=${ELK_ELASTIC_PASSWD:-qq1458513}
    volumes:
      - "./elasticsearch/data/${ELK_VERSION:-7.17.7}:/usr/share/elasticsearch/data:rw"
      - "./elasticsearch/plugins/${ELK_VERSION:-7.17.7}:/usr/share/elasticsearch/plugins"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.10
    depends_on:
      - redis

  openresty:
    image: ${IMAGE_BASE}/openresty:1.21.4.1
    container_name: openresty
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - "${WWWROOT_PATH}:/data/wwwroot"
      - "./logs/wwwlogs:/data/wwwlogs"
      - "./logs/nginx:/usr/local/openresty/nginx/logs"
      - "./openresty/config/conf:/usr/local/openresty/nginx/conf"
      - "./openresty/config/vhost:/usr/local/openresty/nginx/conf/vhost"
      - "./openresty/config/rewrite:/usr/local/openresty/nginx/conf/rewrite"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.2
    depends_on:
      - php74
      - php73
      - php81
    cap_add:
      - net_raw

  redis:
    image: ${IMAGE_BASE}/redis:7.2.2
    container_name: redis
    restart: always
    environment:
      - REDIS_PASSWORD=${REDIS_PASSWORD:-qq1458513}
    volumes:
      - "./redis/redis.conf:/etc/redis/redis.conf"
      - "./redis/data:/data/db"
      - "./logs/redis:/data/logs"
    command: [ "redis-server", "/etc/redis/redis.conf", "--requirepass ${REDIS_PASSWORD:-qq1458513}" ]
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      interval: 1s
      timeout: 3s
      retries: 30
      start_period: 30s
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.3

  php73:
    image: ${IMAGE_BASE}/php:7.3.33
    container_name: php73
    restart: always
    volumes:
      - "${WWWROOT_PATH}:/data/wwwroot:rw"
      - "./php/php73/etc:/usr/local/etc"
      - "./php/php73/supervisord.d:/etc/supervisord.d"
    working_dir: /data/wwwroot/
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.73
    healthcheck:
      test:
        [
          "CMD",
          "curl",
          "--fail",
          "http://${NET_SUBNET:-10.12.25}.1/ping_73"
        ]
      interval: 1s
      timeout: 3s
      retries: 30
      start_period: 30s
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - elasticsearch
      - redis

  php74:
    image: ${IMAGE_BASE}/php:7.4.33
    container_name: php74
    restart: always
    volumes:
      - "${WWWROOT_PATH}:/data/wwwroot:rw"
      - "./php/php74/etc:/usr/local/etc"
    working_dir: /data/wwwroot/
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.74
    healthcheck:
      test:
        [
          "CMD",
          "curl",
          "--fail",
          "http://${NET_SUBNET:-10.12.25}.1/ping_74"
        ]
      interval: 1s
      timeout: 3s
      retries: 30
      start_period: 30s
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - elasticsearch
      - redis

  php81:
    image: ${IMAGE_BASE}/php:8.1.24
    container_name: php81
    restart: always
    volumes:
      - "${WWWROOT_PATH}:/data/wwwroot"
      - "./php/php81/etc:/usr/local/etc"
      - "./php/php81/supervisord.d:/etc/supervisord.d"
    working_dir: /data/wwwroot/
    networks:
      aix-docker-cc:
        ipv4_address: ${NET_SUBNET:-10.12.25}.81
    healthcheck:
      test:
        [
          "CMD",
          "curl",
          "--fail",
          "http://${NET_SUBNET:-10.12.25}.1/ping_81"
        ]
      interval: 1s
      timeout: 3s
      retries: 30
      start_period: 30s
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      redis:
        condition: service_healthy
