################################
# 🦎 KOMODO COMPOSE - MONGO 🦎 #
################################

## This compose file will deploy:
##   1. MongoDB
##   2. Komodo Core
##   3. Komodo Periphery
name: komodo
services:
    mongo:
        image: mongo
        labels:
            komodo.skip: # Prevent Komodo from stopping with StopAllContainers
        command: --quiet --wiredTigerCacheSizeGB 0.25
        restart: unless-stopped
        logging:
            driver: ${COMPOSE_LOGGING_DRIVER:-local}
        networks:
            - default
        # ports:
        #   - 27017:27017
        volumes:
            - /mnt/DockerStorage/komodo/mongo/data:/data/db:rw
            - /mnt/DockerStorage/komodo/mongo/config:/data/configdb:rw
        environment:
            MONGO_INITDB_ROOT_USERNAME: ${DB_USERNAME}
            MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD}

    core:
        image: ghcr.io/mbecker20/komodo:${COMPOSE_KOMODO_IMAGE_TAG:-latest}
        labels:
            komodo.skip: # Prevent Komodo from stopping with StopAllContainers
        restart: unless-stopped
        depends_on:
            - mongo
        logging:
            driver: ${COMPOSE_LOGGING_DRIVER:-local}
        networks:
            - default
        ports:
            - 9120:9120
        env_file: ./komodo.env
        environment:
            KOMODO_DATABASE_ADDRESS: mongo:27017
            KOMODO_DATABASE_USERNAME: ${DB_USERNAME}
            KOMODO_DATABASE_PASSWORD: ${DB_PASSWORD}
        volumes:
            ## Core cache for repos for latest commit hash / contents
            - /mnt/DockerStorage/komodo/cache:/repo-cache:rw
            ## Store sync files on server
            - /mnt/DockerStorage/komodo/syncs:/syncs
            ## Optionally mount a custom core.config.toml
            - /mnt/DockerStorage/komodo/core.config.toml:/config/config.toml
        ## Allows for systemd Periphery connection at
        ## "http://host.docker.internal:8120"
        # extra_hosts:
        #   - host.docker.internal:host-gateway

    ## Deploy Periphery container using this block,
    ## or deploy the Periphery binary with systemd using
    ## https://github.com/mbecker20/komodo/tree/main/scripts
    periphery:
        image: ghcr.io/mbecker20/periphery:${COMPOSE_KOMODO_IMAGE_TAG:-latest}
        labels:
            komodo.skip: # Prevent Komodo from stopping with StopAllContainers
        restart: unless-stopped
        logging:
            driver: ${COMPOSE_LOGGING_DRIVER:-local}
        networks:
            - default
        env_file: ./komodo.env
        volumes:
            ## Mount external docker socket
            - /var/run/docker.sock:/var/run/docker.sock
            ## Allow Periphery to see processes outside of container
            - /proc:/proc
            ## use self signed certs in docker volume,
            ## or mount your own signed certs.
            - /mnt/DockerStorage/komodo/ssl:/etc/komodo/ssl:rw
            ## manage repos in a docker volume,
            ## or change it to an accessible host directory.
            - /mnt/DockerStorage/komodo/repos:/etc/komodo/repos:rw
            ## manage stack files in a docker volume,
            ## or change it to an accessible host directory.
            - /mnt/DockerStorage/komodo/stacks:/etc/komodo/stacks:rw
            ## Optionally mount a path to store compose files
            # - /path/to/compose:/host/compose

volumes:
    # Mongo
    mongo-data:
    mongo-config:
    # Core
    repo-cache:
    # Periphery
    ssl-certs:
    repos:
    stacks:

networks:
    default: {}
