version: "3"

services:
    dns-proxy-server:
        image: defreitas/dns-proxy-server
        hostname: dns.mageddo
        restart: always
        ports:
            - "5380:5380"
        volumes:
            - ./scripts:/app/conf
            - /var/run/docker.sock:/var/run/docker.sock
            - /etc/resolv.conf:/etc/resolv.conf
        networks:
            - marvel2

    postgres:
        restart: always
        image: postgres
        hostname: postgres
        ports:
            - "5432:5432"
        networks:
            - marvel2
        environment:
            POSTGRES_HOST_AUTH_METHOD: trust
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: postgres
            POSTGRES_DB: marvel_dev

    vault:
        image: vault
        ports:
            - "8200:8200"
        expose:
            - "8200"
        networks:
            - marvel2
        environment:
            VAULT_DEV_ROOT_TOKEN_ID: 00000000-0000-0000-0000-000000000000

    kafka:
        restart: always
        image: confluentinc/cp-kafka:5.2.3
        hostname: kafka
        ports:
            - "9092:9092"
        expose:
            - 9092
        tmpfs: /var/lib/kafka/data
        networks:
            - marvel2
        environment:
            KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
            KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
            KAFKA_BROKER_ID: 1
            KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
            KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
            KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
        depends_on:
            - dns-proxy-server
            - zookeeper

    zookeeper:
        image: zookeeper
        restart: always
        ports:
            - "2181:2181"
        tmpfs: /datalog
        networks:
            - marvel2
        environment:
            ZOO_MY_ID: 1
            ZOO_PORT: 2181
            ZOO_STANDALONE_ENABLED: "true"

    redis:
        image: redis
        restart: always
        ports:
            - "6379:6379"
        networks:
            - marvel2

    restapi:
        restart: always
        image: marvel2-restapi
        build:
            context: ./kong
        hostname: restapi
        networks:
            - marvel2
        ports:
            - "8180:80"
        command: ["/opt/zoox/start_marvel_restapi.sh", "--profile", "local-docker"]
        depends_on:
            - dns-proxy-server
            - postgres
            - vault

    databricks-scheduler-consumer:
        restart: always
        image: marvel2-databricks-scheduler-consumer
        build:
            context: ../ # use driving/sim instead of Kong directory, which will contain all .proto files used by Marvel
            dockerfile: marvel/kong/kafka.Dockerfile
            args:
                project: databricks-scheduler-consumer
        networks:
            - marvel2
        environment:
            SPRING_PROFILES_ACTIVE: local-docker
        depends_on:
            - kafka
            - redis
            - restapi

    notifications-consumer:
        restart: always
        image: marvel2-notifications-consumer
        build:
            context: ./kong
            dockerfile: kafka.Dockerfile
            args:
                project: notifications-consumer
        networks:
            - marvel2
        environment:
            SPRING_PROFILES_ACTIVE: local-docker
        depends_on:
            - kafka
            - restapi

    echo-sim-results-consumer:
        restart: always
        image: marvel2-echo-sim-results-consumer
        build:
            context: ../ # use driving/sim instead of Kong directory, which will contain all .proto files used by Marvel
            dockerfile: marvel/kong/kafka.Dockerfile
            args:
                project: echo-sim-results-consumer
        networks:
            - marvel2
        environment:
            SPRING_PROFILES_ACTIVE: local-docker
        depends_on:
            - kafka

    run-summaries-consumer:
        restart: always
        image: marvel2-run-summaries-consumer
        build:
            context: ../ # use driving/sim instead of Kong directory, which will contain all .proto files used by Marvel
            dockerfile: marvel/kong/kafka.Dockerfile
            args:
                project: run-summaries-consumer
        networks:
            - marvel2
        environment:
            SPRING_PROFILES_ACTIVE: local-docker
        depends_on:
            - kafka
            - redis
            - restapi
    metrics-reader-service:
        restart: always
        image: marvel2-metrics-reader-service
        build:
            context: ./kong
            dockerfile: ./metrics.Dockerfile
        hostname: metrics-reader-service
        networks:
            - marvel2
        ports:
            - "8280:80"
        command: ["/opt/zoox/start_application.sh", "--profile", "local-dev"]

    jobz:
        restart: always
        image: marvel2-jobz
        build:
            context: ./jobz
        hostname: jobz
        networks:
            - marvel2
        ports:
            - "8085:80"
        command: ["/jobz", "--host=local", "--http-port=80"]
        depends_on:
            - restapi # Wait for Kong to finish setting up the DB

    frontend:
        restart: always
        image: marvel2-frontend
        build:
            context: ./frontend
        hostname: frontend
        networks:
            - marvel2
        ports:
            - "8090:80"
        command: ["/entrypoint.sh", "--host=local", "--http-port=80"]
        depends_on:
            - restapi # Wait for Kong to finish setting up the DB

networks:
    marvel2:
