services:
  mariadb10:
    image: mariadb:10
    environment:
      MYSQL_ROOT_PASSWORD: funcp
    tmpfs:
      - /var/lib/mysql/:rw,noexec,nosuid

  mssql2019latest:
    image: typo3/core-testing-mssql2019:latest
    environment:
      ACCEPT_EULA: Y
      SA_PASSWORD: "Test1234!"
      MSSQL_PID: Developer

  postgres10:
    image: postgres:10-alpine
    environment:
      POSTGRES_PASSWORD: funcp
      POSTGRES_USER: ${HOST_USER}
    tmpfs:
      - /var/lib/postgresql/data:rw,noexec,nosuid

  minio:
    image: minio/minio
    user: ${HOST_UID}
    command: server /minio-data
    volumes:
      - ../../.Build/minio-data:/minio-data

  composer_install:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        composer install --no-progress --no-interaction;
      "
  composer_install_max:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c '
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        if [[ ${PHP_VERSION} == "8.0" || ${PHP_VERSION} == "7.4" ]]; then
          composer req typo3/cms-core:"dev-master" \
            typo3/cms-backend:"dev-master" \
            typo3/cms-frontend:"dev-master" \
            typo3/cms-extbase:"dev-master" \
            typo3/cms-fluid:"dev-master" \
            typo3/cms-recordlist:"dev-master" \
            typo3/cms-install:"dev-master"
        fi
        composer config --unset platform.php;
        composer update --no-progress --no-interaction;
        composer dumpautoload;
      '

  composer_install_min:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c '
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        if [ ${PHP_VERSION} == "8.0" ]; then
          composer req typo3/cms-core:"dev-master" \
            typo3/cms-backend:"dev-master" \
            typo3/cms-frontend:"dev-master" \
            typo3/cms-extbase:"dev-master" \
            typo3/cms-fluid:"dev-master" \
            typo3/cms-recordlist:"dev-master" \
            typo3/cms-install:"dev-master"
        fi
        composer config platform.php ${PHP_VERSION}.0;
        composer update --prefer-lowest --no-progress --no-interaction;
        composer dumpautoload;
      '

  composer_validate:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        composer validate;
      "

  functional_mariadb10:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    links:
      - mariadb10
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    environment:
      typo3DatabaseName: func_test
      typo3DatabaseUsername: root
      typo3DatabasePassword: funcp
      typo3DatabaseHost: mariadb10
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        echo Waiting for database start...;
        while ! nc -z mariadb10 3306; do
          sleep 1;
        done;
        echo Database is up;
        php -v | grep '^PHP';
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          export XDEBUG_MODE=\"off\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        else
          export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          export XDEBUG_MODE=\"debug,develop\"
          export XDEBUG_TRIGGER=\"foo\"
          export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        fi
      "

  functional_mssql2019latest:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    links:
      - mssql2019latest
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    environment:
      typo3DatabaseDriver: sqlsrv
      typo3DatabaseName: func
      typo3DatabasePassword: "Test1234!"
      typo3DatabaseUsername: SA
      typo3DatabasePort: 1433
      typo3DatabaseCharset: utf-8
      typo3DatabaseHost: mssql2019latest
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        echo Waiting for database start...;
        while ! nc -z mssql2019latest 1433; do
          sleep 1;
        done;
        sleep 5;
        echo Database is up;
        php -v | grep '^PHP';
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          export XDEBUG_MODE=\"off\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-mssql ${TEST_FILE};
        else
          export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          export XDEBUG_MODE=\"debug,develop\"
          export XDEBUG_TRIGGER=\"foo\"
          export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-mssql ${TEST_FILE};
        fi
      "

  functional_postgres10:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    links:
      - postgres10
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    environment:
      typo3DatabaseDriver: pdo_pgsql
      typo3DatabaseName: bamboo
      typo3DatabaseUsername: ${HOST_USER}
      typo3DatabaseHost: postgres10
      typo3DatabasePassword: funcp
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        echo Waiting for database start...;
        while ! nc -z postgres10 5432; do
          sleep 1;
        done;
        echo Database is up;
        php -v | grep '^PHP';
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          export XDEBUG_MODE=\"off\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-postgres ${TEST_FILE};
        else
          export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          export XDEBUG_MODE=\"debug,develop\"
          export XDEBUG_TRIGGER=\"foo\"
          export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-postgres ${TEST_FILE};
        fi
      "

  functional_sqlite:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    links:
      - minio
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    tmpfs:
      - ${ROOT_DIR}/.Build/Web/typo3temp/var/tests/functional-sqlite-dbs/:rw,noexec,nosuid,uid=${HOST_UID}
    environment:
      typo3DatabaseDriver: pdo_sqlite
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -v | grep '^PHP';
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          export XDEBUG_MODE=\"off\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-sqlite ${TEST_FILE};
        else
          export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          export XDEBUG_MODE=\"debug,develop\"
          export XDEBUG_TRIGGER=\"foo\"
          export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-sqlite ${TEST_FILE};
        fi
      "

  lint:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -v | grep '^PHP';
        find . -name \\*.php ! -path "./.Build/\\*" -print0 | xargs -0 -n1 -P4 php -dxdebug.mode=off -l >/dev/null
      "

  unit:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
      - ${HOST_HOME}:${HOST_HOME}
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -v | grep '^PHP'
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          export XDEBUG_MODE=\"off\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        else
          export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          export XDEBUG_MODE=\"debug,develop\"
          export XDEBUG_TRIGGER=\"foo\"
          export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
          bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        fi
      "
