version: '3.8'

services:
  php:
    build: 
      context: ./php/${IMAGE_PHP_DIR}
      target: php_base
      args:
        image: ${IMAGE_PHP}        
        workdir_base: ${WORKDIR_BASE}
        workdir_init: ${WORKDIR_INIT}
        workdir_contao: ${WORKDIR_CONTAO}
        workdir_contao_public: ${WORKDIR_CONTAO_PUBLIC}
        workdir_bundle: ${WORKDIR_BUNDLE}
        workdir_simlink_base: ${WORKDIR_SIMLINK_BASE}
        workdir_bundle_end_slash: ${WORKDIR_BUNDLE_END_SLASH}
        db_host: 'db' # the db node
        db_database: ${DB_DATABASE}
        db_user: ${DB_USER}
        db_password: ${DB_PASSWORD}
        php_ini_max_execution_time: ${PHP_INI_MAX_EXECUTION_TIME}
        php_ini_memory_limit: ${PHP_INI_MEMORY_LIMIT}
        php_ini_disable_functions: ${PHP_INI_DISABLE_FUNCTIONS}
        php_ini_post_max_size: ${PHP_INI_POST_MAX_SIZE}
        php_ini_upload_max_filesize: ${PHP_INI_UPLOAD_MAX_FILESIZE}
        php_ini_max_input_vars: ${PHP_INI_MAX_INPUT_VARS}
    environment:
      PRJ_NAME: ${PRJ_NAME}
      DB_HOST: 'db'
      DB_DATABASE: ${DB_DATABASE}
      DB_USER: ${DB_USER}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_PORT: 3306
      WORKDIR_BUNDLE: ${WORKDIR_BUNDLE}
      WORKDIR_CONTAO: ${WORKDIR_CONTAO}
      BUNDLE_NAME: ${BUNDLE_NAME}
    container_name: ${COMPOSE_PROJECT_NAME_SHORT}_php_base
    volumes:
      # - ..:${WORKDIR_BASE}/${BUNDLE_NAME}
      - ..:${WORKDIR_BUNDLE}
      - ./contao/${CONTAO_VERSION}:${WORKDIR_BASE}/init:ro
      - type: volume
        source: static-content
        target : ${WORKDIR_BASE}/${PRJ_NAME}
    networks:
      - common
      - db
      - php

  db:
    build: 
      context: ./db/${IMAGE_DB_DIR}
      target: db_base
      args:
        image: ${IMAGE_DB}
        prj_name: ${PRJ_NAME}
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} #mandatory
      MYSQL_USER: ${DB_USER} #mandatory
      MYSQL_PASSWORD: ${DB_PASSWORD} #mandatory
      MYSQL_DATABASE: ${DB_DATABASE} #optionnal, makes mysql create a database on startup
    container_name: ${COMPOSE_PROJECT_NAME_SHORT}_db_base
    networks:
      - db
  
  web:
    build: 
      context: ./web/${IMAGE_WEBSERVER_DIR}
      target: web_base
      args:
        image: ${IMAGE_WEBSERVER}
        workdir_contao_public: ${WORKDIR_CONTAO_PUBLIC}
        prj_name: ${PRJ_NAME}
        ssl_port: ${WEBSERVER_EXPOSED_PORT_SSL}
        php_port: ${PHP_FPM_EXPOSED_PORT}
    container_name: ${COMPOSE_PROJECT_NAME_SHORT}_web_base
    restart: unless-stopped
    tty: true
    volumes:
      # - ..:${WORKDIR_BASE}/${BUNDLE_NAME}
      - ..:${WORKDIR_BUNDLE}
      - type: volume
        source: static-content
        target : ${WORKDIR_BASE}/${PRJ_NAME}
    networks:
      - common
      - php

volumes:
  static-content:
    name: ${COMPOSE_PROJECT_NAME_SHORT}-volume-shared-php-web-base

#Docker Networks
networks:
  common:
  php:
  db: