version: "3.7"

services:
    sql:
        image: mariadb:11.0
        volumes:
            - "./data/:/var/lib/mysql"
            - "./imports/:/imports/"
        ports:
            - 127.0.0.1:3306:3306
        labels:
            - "eu.wiss-ki.barrel.distillery=${DOCKER_NETWORK_NAME}"
        environment:
            # This combination of environment variables will configure a passwordless root user
            # that can only connect to the container from 'localhost'.
            # This means we can only connect using 'docker-compose exec sql mysql -C '...' '. 
            - "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
            - "MYSQL_ROOT_HOST=localhost"
        restart: always
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        environment:
            - "PMA_HOST=sql"
            - "HIDE_PHP_VERSION=true"
            - "UPLOAD_LIMIT=100M"
        # phpmyadmin running on localhost:8080 so that we can easily access the system graphically. 
        # By default no admin account is created, so initial shell access to make one is needed. 
        ports:
            - 127.0.0.1:8080:80
        labels:
            - "eu.wiss-ki.barrel.distillery=${DOCKER_NETWORK_NAME}"

            # expose phpmyadmin (removed when disabled in global config)
            - "traefik.enable=True"

            - "traefik.http.routers.core_phpmyadmin.rule=${HOST_RULE}"
            - "traefik.http.routers.core_phpmyadmin.tls=${HTTPS_ENABLED}"
            - "traefik.http.routers.core_phpmyadmin.tls.certresolver=distillery"
            
            - "traefik.http.services.core_phpmyadmin.loadbalancer.server.port=80"
        depends_on:
            - sql
        restart: always


networks:
    default:
        name: ${DOCKER_NETWORK_NAME}
        external: true
