# Rx3/ETC Docker Image
#-------------------------------------------------------------------------------

name:                               ${HOST_NAME_PREFIX}

services:



#-------------------------------------------------------------------------------

  web-server:
    container_name:                 ${WS_HOST_NAME}
    hostname:                       ${WS_HOST_NAME}
    
    image:                          ${WS_IMG_URL}

    build:
      dockerfile:                   Dockerfile
      
      args:
        IMG_NAME:                   ${WS_IMG_URL}
        IMG_NAME_FULL:              ${WS_IMG_NAME_FULL}
        IMG_VERSION:                ${WS_IMG_VERSION}
        IMG_MAINTAINER:             ${APPL_MAINTAINER}
        IMG_URL:                    ${WS_IMG_URL}
        IMG_FROM_URL:               ${WS_IMG_FROM_URL}

        MODULE_NAME:                ${WS_MODULE_NAME}
        MODULE_PATH:                ${WS_MODULE_PATH}
        MODULE_VERSION:             ${WS_MODULE_VERSION}
        WEB_SERVER_CONF_NAME:       ${WS_CONF_NAME}

    restart:                        unless-stopped
          
    environment:
      APACHE_UID:                   ${WS_USER_ID}
      APACHE_GID:                   ${WS_GROUP_ID}
      APACHE_DOC_ROOT:              /var/www/html
      
      ENV_NET_SED:                  "${ENV_NET_SED}"

    healthcheck:
        test:                       ["CMD", "curl", "-f", "http://localhost:${WS_PORT_MAIN_INT}/"]
        interval:                   10s
        timeout:                    3s
        retries:                    3

    volumes:
#      - ./${WS_CONF_EXT}:${WS_CONF_INT}
#      - ./${WS_LIB_EXT}:${WS_LIB_INT}
      - ./${WS_LOG_INIT_EXT}:${WS_LOG_INIT_INT}
      - ./${WS_LOG_SV_EXT}:${WS_LOG_SV_INT}
      - ./${WS_LOG_HTTPD_EXT}:${WS_LOG_HTTPD_INT}
      
    networks:
      - appl

    ports:
      - "127.0.0.1:${WS_PORT_SV_EXT}:${WS_PORT_SV_INT}"
      - "127.0.0.1:${WS_PORT_MAIN_EXT}:${WS_PORT_MAIN_INT}"



#-------------------------------------------------------------------------------

  database:
    container_name:                 ${DB_HOST_NAME}
    hostname:                       ${DB_HOST_NAME}
    
    image:                          ${DB_IMG_URL}

    restart:                        unless-stopped
    
    environment:
      MARIADB_UID:                  ${DB_USER_ID}
      MARIADB_GID:                  ${DB_GROUP_ID}
      MARIADB_ROOT_HOST:            ${DB_ROOT_HOST}
      MARIADB_ROOT_PASSWORD:        ${DB_ROOT_PASSWORD}
      MARIADB_DATABASE:             ${DB_DB_NAME}
      MARIADB_USER:                 ${DB_DB_USER}
      MARIADB_PASSWORD:             ${DB_DB_PASSWORD}

    healthcheck:
      test:                         ["CMD", 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', '-p${DB_ROOT_PASSWORD}' ]
      interval:                     10s
      timeout:                      3s
      retries:                      3
      
    volumes:
      - ./${DB_LIB_EXT}:${DB_LIB_INT}
      - ./${DB_LOG_INIT_EXT}:${DB_LOG_INIT_INT}
      - ./${DB_LOG_SV_EXT}:${DB_LOG_SV_INT}
      - ./${DB_LOG_MAIN_EXT}:${DB_LOG_MAIN_INT}
      
    networks:
      - appl
      
#    ports:
#      - "127.0.0.1:${DB_PORT_SV_EXT}:${DB_PORT_SV_INT}"
#      - "127.0.0.1:${DB_PORT_MAIN_EXT}:${DB_PORT_MAIN_INT}"



#-------------------------------------------------------------------------------

  tools:
    container_name:                 ${TOOLS_HOST_NAME}
    hostname:                       ${TOOLS_HOST_NAME}
    
    image:                          ${TOOLS_IMG_URL}

    restart:                        unless-stopped
          
    depends_on:
      database:
        condition:                  service_healthy
                
    environment:
      SERVER_CROND_ENABLED:         ${TOOLS_CROND_ENABLED}
      
      APACHE_UID:                   ${TOOLS_USER_ID}
      APACHE_GID:                   ${TOOLS_GROUP_ID}
      APACHE_DOC_ROOT:              /var/www/html
      
      MARIADB_SERVER_NAME:          "${DB_SERVER_NAME}"
      MARIADB_HOST:                 "${DB_HOST_NAME}"
      MARIADB_PORT:                 "${DB_PORT_MAIN_INT}"

      TOOLS_RPC_ENABLED:            ${TOOLS_RPC_ENABLED}

    healthcheck:
        test:                       ["CMD", "curl", "-f", "http://localhost:${TOOLS_PORT_MAIN_INT}/"]
        interval:                   10s
        timeout:                    3s
        retries:                    3

    volumes:
      - ./${TOOLS_LOG_INIT_EXT}:${TOOLS_LOG_INIT_INT}
      - ./${TOOLS_LOG_SV_EXT}:${TOOLS_LOG_SV_INT}
      - ./${TOOLS_LOG_MAIN_EXT}:${TOOLS_LOG_MAIN_INT}
      
    networks:
      - appl

 #   ports:
 #     - "127.0.0.1:${TOOLS_PORT_SV_EXT}:${TOOLS_PORT_SV_INT}"
 #     - "127.0.0.1:${TOOLS_PORT_MAIN_EXT}:${TOOLS_PORT_MAIN_INT}"
 #     - "127.0.0.1:${TOOLS_PORT_ADMIN_EXT}:${TOOLS_PORT_ADMIN_INT}"



#-------------------------------------------------------------------------------

  webapp:
    container_name:                 ${WA_HOST_NAME}
    hostname:                       ${WA_HOST_NAME}
    
    image:                          ${WA_IMG_URL}

    restart:                        unless-stopped
    
    depends_on:
      database:
        condition:                  service_healthy
        
    environment:
      SERVER_CROND_ENABLED:         ${WA_CROND_ENABLED}
      APACHE_UID:                   ${WA_USER_ID}
      APACHE_GID:                   ${WA_GROUP_ID}
      APACHE_DOC_ROOT:              ${WA_APACHE_DOC_ROOT}
      PHP_UPLOAD_LIMIT:             ${WA_PHP_UPLOAD_LIMIT}
      TIKI_URL:                     ${WA_TIKI_URL}
      TIKI_ROOT_LINK_LIST:          ${WA_TIKI_ROOT_LINK_LIST}
      
    healthcheck:
        test:                       ["CMD", "curl", "-f", "http://localhost:${WA_PORT_MAIN_INT}/${WA_TIKI_URL}/"]
        interval:                   10s
        timeout:                    3s
        retries:                    3
        
    volumes:
      - ./${WA_LOG_INIT_EXT}:${WA_LOG_INIT_INT}
      - ./${WA_LOG_SV_EXT}:${WA_LOG_SV_INT}
      - ./${WA_LOG_HTTPD_EXT}:${WA_LOG_HTTPD_INT}

      - ./${WA_WWW_EXT}:${WA_WWW_INT}
          
    networks:
      - appl

#    ports:
#      - "127.0.0.1:${WA_PORT_SV_EXT}:${WA_PORT_SV_INT}"
#      - "127.0.0.1:${WA_PORT_MAIN_EXT}:${WA_PORT_MAIN_INT}"



#-------------------------------------------------------------------------------
      
networks:
  appl:
    name:                           ${NETWORK_NAME}
    driver:                         bridge
    driver_opts:
      com.docker.network.bridge.name: ${NETWORK_IF_NAME}
