services:
    app:
        build:
            context: .
            dockerfile: "./docker/php/Dockerfile"
        container_name: ${DOCKER_APP_CONTAINER_NAME}
        restart: "no"
        working_dir: /var/www/html
        volumes:
            - .:/var/www/html
            - ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
        environment:
            - PHP_IDE_CONFIG=serverName=laravel-docker
            - XDEBUG_CONFIG=client_host=host.docker.internal
            - PHP_MEMORY_LIMIT=4096M
        networks:
            - application
        depends_on:
            - db
            - redis

    nginx:
        build:
            context: .
            dockerfile: "./docker/nginx/Dockerfile"
        container_name: ${DOCKER_WEBSERVER_CONTAINER_NAME}
        restart: "no"
        ports:
            - "80:80"
        volumes:
            - .:/var/www/html
            - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
        networks:
            - application
        depends_on:
            - app

    db:
        image: mariadb:10.6
        container_name: ${DOCKER_DATABASE_CONTAINER_NAME}
        restart: "no"
        environment:
            MARIADB_ROOT_PASSWORD: root
            MARIADB_DATABASE: laravel
            MARIADB_USER: laravel
            MARIADB_PASSWORD: laravel
            MARIADB_CHARSET: utf8mb4
            MARIADB_COLLATION: utf8mb4_unicode_ci
        command:
            - --character-set-server=utf8mb4
            - --collation-server=utf8mb4_unicode_ci
            - --innodb-file-per-table=1
        volumes:
            - mysql_data:/var/lib/mysql
        ports:
            - "3306:3306"
        networks:
            - application

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        container_name: ${DOCKER_PHPMYADMIN_CONTAINER_NAME}
        ports:
            - "7002:80"
        environment:
            PMA_HOST: db
            PMA_USER: root
            PMA_PASSWORD: root
            UPLOAD_LIMIT: 10G
        networks:
            - application
        depends_on:
            - db

    redis:
        image: redis:7-alpine
        container_name: ${DOCKER_REDIS_CONTAINER_NAME}
        restart: "no"
        ports:
            - "6379:6379"
        volumes:
            - redis_data:/data
        networks:
            - application

    node:
        image: node:20-alpine
        container_name: ${DOCKER_NODE_CONTAINER_NAME:-readingful-node}
        restart: "no"
        working_dir: /var/www/html
        volumes:
            - .:/var/www/html
        ports:
            - "5173:5173"
        command: sh -c "npm install && npm run dev -- --host 0.0.0.0"
        networks:
            - application

    storybook:
        image: node:20-alpine
        container_name: ${DOCKER_STORYBOOK_CONTAINER_NAME}
        restart: "no"
        working_dir: /var/www/html
        volumes:
            - .:/var/www/html
        ports:
            - "6006:6006"
        command: sh -c "npm install && npm run storybook -- --host 0.0.0.0"
        networks:
            - application

    mailhog:
        image: mailhog/mailhog:latest
        container_name: ${DOCKER_MAILHOG_CONTAINER_NAME}
        restart: "no"
        ports:
            - "8025:8025"
            - "1025:1025"
        networks:
            - application

volumes:
    mysql_data:
    redis_data:

networks:
    application:
        name: ${DOCKER_NETWORK_INTERNAL_NAME}
        driver: bridge
