version: '2.4'
networks:
    mm_stats_postgres:
    mm_stats_webserver:

services:
    mm_stats_postgres:
        container_name: mm_stats_postgres
        build:
            context: postgres/
        shm_size: 2g
        environment:
            POSTGRES_PASSWORD: '${PGPASSWORD}'
            POSTGRES_USER: 'mm_stats'
            PGDATABASE: 'mm_stats'
            PGDATABASE_HOT_TM: 'hot_tm'
            PGDATA: '/var/lib/postgresql/mm_stats'
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U mm_stats"]
          interval: 30s
          timeout: 30s
          retries: 1000
        command: postgres
        volumes:
           - ./postgres-data:/var/lib/postgresql/mm_stats
           - ./postgres/data:/data:Z
        restart: unless-stopped
        ports:
          - "5434:5432"
        networks:
            - mm_stats_postgres

    mm_stats_workers:
        container_name: mm_stats_workers
        build:
            context: python/
        environment:
            POSTGRES_HOST: '${POSTGRES_HOST}'
            POSTGRES_PORT: '${POSTGRES_PORT}'
            POSTGRES_USER: 'mm_stats'
            PGPASSWORD: '${PGPASSWORD}'
            PGDATABASE: 'mm_stats'
            PGDATABASE_HOT_TM: 'hot_tm'
            PGDATA: '/var/lib/postgresql/mm_stats'
            AWS_ACCESS_KEY_ID: '${AWS_ACCESS_KEY_ID}'
            AWS_SECRET_ACCESS_KEY: '${AWS_SECRET_ACCESS_KEY}'
            AWS_BUCKET_NAME: '${AWS_BUCKET_NAME}'
            AWS_PREFIX: '${AWS_PREFIX}'
            JAVA_PATH: '/root/java/'
            OSHDB_FILE_LOCAL: '/root/java/rohingya-refugee-camps.oshdb.mv.db'
            IGNITE_CONFIG_FILE: '/root/ignite_ohsome.xml'
            OSHDB_PORT: '${OSHDB_PORT}'
            OSHDB_USER: '${OSHDB_USER}'
            OSHDB_PASS: '${OSHDB_PASS}'
        depends_on:
            mm_stats_postgres:
                condition: service_healthy
        volumes:
            - ./mm_stats-data/:/root/.local/share/mm_stats
        command: mm_stats --verbose run --analysis_type all --schedule
        restart: "no"
        networks:
            - mm_stats_postgres

    mm_stats_nginx:
        container_name: mm_stats_nginx
        build:
            context: nginx/
        restart: unless-stopped
        ports:
            - '80:80'
            - '443:443'
        volumes:
            - ./nginx/website:/usr/share/nginx/html
            - ./mm_stats-data/api:/usr/share/nginx/html/api/:ro
            - /etc/letsencrypt/:/etc/letsencrypt/:ro
        networks:
            - mm_stats_webserver
