version: '3.7'

volumes:
  redisdb:
  mongodb:

networks:
    backend:

secrets:
    qmicloud_config:
        file: ./secrets.json

services:

    redis:
        image: redis
        container_name: qmi-cloud-redis
        volumes:
            - redisdb:/data
        entrypoint: redis-server --appendonly yes
        restart: on-failure
        networks:
            - backend

    mongo:
        image: mongo:4.2
        container_name: qmi-cloud-mongo
        restart: on-failure
        volumes:
            - mongodb:/data/db
        environment:
            MONGO_INITDB_ROOT_USERNAME: root
            MONGO_INITDB_ROOT_PASSWORD: example
        networks:
            - backend
        ports:
            - "27017:27017"

    cli:
        build: 
            context: .
            dockerfile: qmi-cloud-cli/Dockerfile
        image: qlikgear/qmi-cloud-cli:latest


    app:
        build: 
            context: .
            dockerfile: Dockerfile
        image: qlikgear/qmi-cloud-app:latest
        container_name: qmi-cloud-app
        restart: on-failure
        secrets:
            - source: qmicloud_config
              target: config.json
        environment:
            - HOSTNAME_URL=http://localhost:3000
            - BACKEND_LOGS_URL=http://localhost:8888
            - REDIS_URL=redis://redis
            - MONGO_URI=mongodb://root:example@mongo/qmicloud?authSource=admin
            - CERT_PFX_FILENAME=
            - CERT_PFX_PASSWORD=
        command:
            - ./server/wait-for.sh
            - --timeout=20
            - mongo:27017
            - --   
            - sh
            - -c
            - npm run start:dev
        volumes:
            # -- Dev only volumes
            - ./server:/var/www/app/server
            - ./dist:/var/www/app/dist
            # -------------------
            - ../qmi-cloud-provisions:/provisions
            - ./logs:/logs
            - ./costexport:/var/www/app/costexport
            - ./photos:/var/www/app/photos
            #- ./certs:/var/www/app/server/certs
        depends_on:
            - mongo
            - redis
        ports:
            - "3000:3000"
            - "3100:3100"
        networks:
            - backend

    worker:
        build: 
            context: .
            dockerfile: qmi-cloud-worker/Dockerfile
        image: qlikgear/qmi-cloud-worker:latest
        container_name: qmi-cloud-worker
        restart: on-failure
        environment:
            - HOSTNAME_URL=http://localhost:3000
            - REDIS_URL=redis://redis
            - MONGO_URI=mongodb://root:example@mongo/qmicloud?authSource=admin
            - PROJECT_PATH=%PWD%
            - GIT_SCENARIOS=git::git@gitlab.com:qmi/qmi-cloud-scenarios.git
            - GIT_TAG=dev
            - SSHPATH=/Users/aor/.ssh
            - DOCKERIMAGE_AZURE_POWERSHELL=mcr.microsoft.com/azure-powershell:4.2.0-ubuntu-18.04
            - DOCKERIMAGE_TERRAFORM=qlikgear/terraform:1.0.1
        command: "sh -c 'npm run start:dev'"
        volumes:
            # -- Dev only volumes
            - ./qmi-cloud-worker:/app/worker
            # -------------------
            - ./logs:/logs
            - /var/run/docker.sock:/home/docker.sock
        depends_on:
            - mongo
            - redis
        networks:
            - backend
    
    mongo-express:
        image: mongo-express:0.54.0
        container_name: qmi-cloud-mongo-express
        restart: on-failure
        ports:
            - 8081:8081
        depends_on:
            - mongo
        environment:
            ME_CONFIG_MONGODB_ADMINUSERNAME: root
            ME_CONFIG_MONGODB_ADMINPASSWORD: example
            ME_CONFIG_BASICAUTH_USERNAME: qlik
            ME_CONFIG_BASICAUTH_PASSWORD: Qlik1234
        networks:
            - backend
            
    dozzle:
        image: amir20/dozzle:latest
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
        ports:
            - 8888:8080
        #environment: 
        #    DOZZLE_BASE: "/dozzle"
        networks:
            - backend