networks:
    traefik:
        external: true

volumes:
    pimcore-database:
    pimcore-tmp-storage:

services:
    php-fpm:
        build:
            context: .
            dockerfile: .docker/php-fpm/Dockerfile
        container_name: ${APP_NAME}_app
        tty: true
        working_dir: /var/www/html
        depends_on:
            - db
        volumes:
            - .:/var/www/html:cached
            - .docker/crontabs:/etc/crontabs/root:ro
            - .docker/supervisor/supervisor.d/:/etc/supervisor.d/:ro
            - pimcore-tmp-storage:/tmp:cached
            # https://docs.docker.com/desktop/networking/#ssh-agent-forwarding
            -   type: bind
                source: /run/host-services/ssh-auth.sock
                target: /run/host-services/ssh-auth.sock
        environment:
            - "ENV_SUBSTITUTION_ENABLE=true"
            - "PHP_FPM_LISTEN=9000"
            - "PHP_FPM_USER=www-data"
            - "PHP_FPM_GROUP=www-data"
            - "PHP_FPM_LISTEN_OWNER=www-data"
            - "PHP_FPM_LISTEN_GROUP=www-data"
            - "PHP_MAX_EXECUTION_TIME=300"
            - "PHP_POST_MAX_SIZE=128M"
            - "PHP_UPLOAD_MAX_FILESIZE=128M"
            - "PHP_MEMORY_LIMIT=512M"
            - "SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock"

    nginx:
        image: nginx:stable-alpine
        container_name: ${APP_NAME}_nginx
        tty: true
        volumes:
            - .:/var/www/html:ro
            - .docker/nginx/config/vhost.conf:/etc/nginx/conf.d/default.conf:ro
        depends_on:
            - php-fpm
        networks:
            - default
            - traefik
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.${APP_NAME}_php.rule=Host(`${APP_NAME}.app.localhost`)"
            - "traefik.http.routers.${APP_NAME}_php.priority=-10"
            - "traefik.http.services.${APP_NAME}_php.loadbalancer.server.port=80"
            - "traefik.http.routers.${APP_NAME}_php.tls=true"
            - "traefik.http.routers.${APP_NAME}_php.middlewares=securityheaders"

    db:
        image: mariadb:10.11
        container_name: ${APP_NAME}_database
        working_dir: /var/lib/mysql
        command: [
            "mysqld",
            "--character-set-server=utf8mb4",
            "--collation-server=utf8mb4_general_ci",
            "--innodb-file-per-table=1",
            "--skip-log-bin"
        ]
        volumes:
            - pimcore-database:/var/lib/mysql
        environment:
            - "MYSQL_ROOT_PASSWORD=${DOCKER_MYSQL_ROOT_PASSWORD}"
            - "MYSQL_DATABASE=${DOCKER_MYSQL_DATABASE}"
            - "MYSQL_USER=${DOCKER_MYSQL_USER}"
            - "MYSQL_PASSWORD=${DOCKER_MYSQL_PASSWORD}"

    redis:
        image: redis:alpine
        container_name: ${APP_NAME}_redis
        command: [
            "redis-server",
            "--maxmemory", "128mb",
            "--maxmemory-policy", "volatile-lru",
            "--save", ""
        ]
    adminer:
        image: adminer
        container_name: ${APP_NAME}_adminer
        networks:
            - default
            - traefik
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.${APP_NAME}_adminer.rule=Host(`${APP_NAME}.adminer.localhost`)"
            - "traefik.http.routers.${APP_NAME}_adminer.tls=true"
            - "traefik.http.routers.${APP_NAME}_adminer.middlewares=securityheaders"

    mailhog:
        image: mailhog/mailhog
        container_name: ${APP_NAME}_mailhog
        networks:
            - default
            - traefik
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.${APP_NAME}_mailhog.rule=Host(`${APP_NAME}.mailhog.localhost`)"
            - "traefik.http.routers.${APP_NAME}_mailhog.tls=true"
            - "traefik.http.services.${APP_NAME}_mailhog.loadbalancer.server.port=8025"
            - "traefik.http.routers.${APP_NAME}_mailhog.middlewares=securityheaders"
