version: "3.9"
services:
    kuadrado_server:
        build:
            context: .
            dockerfile: ./dev.Dockerfile
        container_name: "kuadrado_server"
        depends_on:
            - ${DATABASE_NAME}
        restart: unless-stopped
        ports:
            - 80:${SERVER_PORT}
            - 443:${SERVER_PORT_TLS}
        volumes:
            - ./src:/usr/src/kuadrado_server/src:ro
            - ./Cargo.toml:/usr/src/kuadrado_server/Cargo.toml:ro
            - ./public:${RESOURCES_DIR}/public:ro
            - /etc/letsencrypt/:${RESOURCES_DIR}/certs:ro
        command: cargo run
        env_file:
            - ./.env
    kuadradodb:
        build: ./mongo/
        container_name: ${DATABASE_NAME}
        environment:
            - MONGO_INITDB_DATABASE=${DATABASE_NAME}
            - MONGO_INITDB_ROOT_USERNAME=${DB_ROOT_USERNAME}
            - MONGO_INITDB_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
            - MONGO_INITDB_NON_ROOT_USERNAME=${DB_USERNAME}
            - MONGO_INITDB_NON_ROOT_PASSWORD=${DB_USER_PASSWORD}
        volumes:
            - ./mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
            - /var/${DATABASE_NAME}-volume:/data/db
            - ./mongo/scripts:/mongo-scripts
        ports:
            - "27017-27019:27017-27019"
