version: '3.1'
services:

    nginx:
        image: nginx:latest
        container_name: nginx
        volumes:
            - "./etc/nginx:/etc/nginx/conf.d"
            - "./Website:/var/www/html"
            - "./etc/nginx/logs:/var/log/nginx"
            - "./etc/letsencrypt:/etc/letsencrypt"
        ports:
            - "80:80"
            - "443:443"
        environment:
            - NGINX_HOST=${NGINX_HOST}
        restart: always
        depends_on:
            - tomcat
            - mysqldb

    myadmin:
        image: phpmyadmin/phpmyadmin:latest
        container_name: phpmyadmin
        ports:
            - "9000:80"
        environment:
            - PMA_ARBITRARY=1
            - PMA_HOST=mysql
        restart: always
        depends_on:
            - mysqldb

    fix-mariadb-permissions:
        image: 'bitnami/mariadb:latest'
        container_name: mariadb-fix-permissions
        user: root
        command: chown -R 1001:1001 /bitnami
        volumes:
          - "./data/db/mysq:/bitnami/mariadb"

    mysqldb:
        image: bitnami/mariadb:latest
        container_name: mysql
        restart: always
        env_file:
            - ".env"
        environment:
            - MARIADB_DATABASE=${MARIADB_DATABASE}
            - MARIADB_ROOT_USER=${MARIADB_ROOT_USER}
            - MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
            - ALLOW_EMPTY_PASSWORD=no
            - MARIADB_USER=${MARIADB_USER}
            - MARIADB_PASSWORD=${MARIADB_PASS}
            - MARIADB_DATABASE=${GHOST_DATABASE_NAME}
        ports:
            - "127.0.0.1:3306:3306"
        volumes:
            - "./data/db/mysq:/bitnami/mariadb"
            - "./etc/mariadb/innodb.cnf:/bitnami/mariadb/conf/innodb.cnf:ro"
        depends_on:
          - fix-mariadb-permissions

    tomcat:
        image: tomcat:latest
        container_name: tomcat
        ports:
            - "8080:8080"
        restart: always
        volumes:
            - "./Website:/usr/local/tomcat/webapps/ROOT"
            - "./etc/tomcat:/usr/local/tomcat/conf"

    fix-ghost-permissions:
        image: 'bitnami/ghost:latest'
        container_name: ghost-fix-permissions
        user: root
        command: chown -R 1001:1001 /bitnami/ghost
        volumes:
          - "./etc/ghost:/bitnami/ghost"
        depends_on:
          - mysqldb

    ghost:
        image: bitnami/ghost:latest
        container_name: ghost
        ports:
            - "127.0.0.1:2368:2368"
        volumes:
            - "./etc/ghost/content:/opt/bitnami/ghost/content"
        env_file:
            - ".env"
        environment:
          - NODE_ENV=production
          - privacy__useUpdateCheck=0
          - URL=${URL}
          - MARIADB_HOST=mysql
          - MARIADB_PORT_NUMBER=3306
          - GHOST_DATABASE_USER=${MARIADB_ROOT_USER}
          - GHOST_DATABASE_PASSWORD=${MARIADB_ROOT_PASSWORD}
          - GHOST_DATABASE_NAME=${GHOST_DATABASE_NAME}
          - ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}
          - GHOST_EMAIL=${GHOST_EMAIL}
          - GHOST_PASSWORD=${GHOST_PASSWORD}
        depends_on:
          - fix-ghost-permissions

    php:
        image: nanoninja/php-fpm:7.2
        container_name: php
        volumes:
            - "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
            - "./Website:/var/www/html/public"
