# VERSION=latest
# DATA_PREFIX=/usr/local/cloud
# NETWORK_PREFIX=172.20.0
# DB_NAME=clouds
# DB_PASSWORD=123456

name: cloud-instance

networks:
  cloud:
    name: cloud
    driver: bridge
    ipam:
      driver: default
      config:
        - gateway: ${NETWORK_PREFIX}.1
          subnet: ${NETWORK_PREFIX}.0/24
    driver_opts:
      com.docker.network.bridge.name: cloud

services:
  db:
    container_name: cloud-mysql
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    volumes:
      - ${DATA_PREFIX}/mysql/data:/var/lib/mysql
      - ${DATA_PREFIX}/mysql/conf.d:/etc/mysql/conf.d
    networks:
      cloud:
        ipv4_address: ${NETWORK_PREFIX}.2

  instance:
    container_name: cloud-instance
    image: flexcdn/cloud-instance
    restart: always
    networks:
      cloud:
        ipv4_address: ${NETWORK_PREFIX}.3
    environment:
      - CLOUD_DB_HOST=${NETWORK_PREFIX}.2
      - CLOUD_DB_PASSWORD=${DB_PASSWORD}
      - CLOUD_DB_NAME=${DB_NAME}
      - CLOUD_HTTP_FIREWALL_ENDPOINT=${HTTP_FIREWALL_ENDPOINT}
    ports:
      - 8000:8000
      - 8100:8100
      - 8001:8001
      - 8002:8002
      - 80:80
      - 443:443
    volumes:
      - ${DATA_PREFIX}/cache:/opt/cache
      - ${DATA_PREFIX}/cloud-admin/logs:/usr/local/cloud/cloud-admin/logs
      - ${DATA_PREFIX}/cloud-admin/configs:/usr/local/cloud/cloud-admin/configs
      - ${DATA_PREFIX}/cloud-api/logs:/usr/local/cloud/cloud-api/logs
      - ${DATA_PREFIX}/cloud-api/configs:/usr/local/cloud/cloud-api/configs
      - ${DATA_PREFIX}/cloud-node/logs:/usr/local/cloud/cloud-node/logs
      - ${DATA_PREFIX}/cloud-node/configs:/usr/local/cloud/cloud-node/configs
      - ${DATA_PREFIX}/cloud-node/data:/usr/local/cloud/cloud-node/data
      - ${DATA_PREFIX}/cloud-user/logs:/usr/local/cloud/cloud-user/logs
      - ${DATA_PREFIX}/cloud-user/configs:/usr/local/cloud/cloud-user/configs
    depends_on:
      - db