version: "3.2"
services:
    gateway:
        volumes:
            - "/var/run/docker.sock:/var/run/docker.sock"
        ports:
            - 8080:8080
        image: functions/gateway:0.6.14
        networks:
            - functions
        environment:
            read_timeout: 10    # set both here, and on your functions
            write_timeout: 10   # set both here, and on your functions
            dnsrr: "true"  # Temporarily use dnsrr in place of VIP while issue persists on PWD
            faas_nats_address: "nats"
            faas_nats_port: 4222
        deploy:
            resources:
                limits:
                    memory: 100M
                reservations:
                    memory: 50M
            restart_policy:
                condition: on-failure
                delay: 5s
                max_attempts: 20
                window: 380s
            placement:
                constraints:
                    - 'node.role == manager'
                    - 'node.platform.os == linux'

    nats:
        image: nats-streaming:0.6.0
        # Uncomment the following port mappings if you wish to expose the 
        # NATS client and/or management ports
        # ports:
        #     - 4222:4222
        #     - 8222:8222
        command: "--store memory --cluster_id faas-cluster"
        networks:
            - functions
        deploy:
            resources:
                limits:
                    memory: 125M
                reservations:
                    memory: 50M
            placement:
                constraints:
                    - 'node.platform.os == linux'

    queue-worker:
        image: functions/queue-worker:0.4
        networks:
            - functions
        environment:
            max_inflight: "1"
            ack_timeout: "30s"    # Max duration of any async task / request
        deploy:
            resources:
                limits:
                    memory: 50M
                reservations:
                    memory: 20M
            restart_policy:
                condition: on-failure
                delay: 5s
                max_attempts: 20
                window: 380s
            placement:
                constraints:
                    - 'node.platform.os == linux'

    # End

    # Start monitoring

    prometheus:
        image: functions/prometheus:latest  # autobuild from Dockerfile in repo.
        command: "-config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000 --alertmanager.url=http://alertmanager:9093"
        ports:
            - 9090:9090
        environment:
            no_proxy: "gateway"
        networks:
            - functions
        deploy:
            resources:
                limits:
                    memory: 500M
                reservations:
                    memory: 200M
            placement:
                constraints:
                    - 'node.role == manager'
                    - 'node.platform.os == linux'

    alertmanager:
        image: functions/alertmanager:latest    # autobuild from Dockerfile in repo.
        environment:
            no_proxy: "gateway"
        command:
            - '-config.file=/alertmanager.yml'
        networks:
            - functions
        # Uncomment the following port mapping if you wish to expose the Prometheus
        # Alertmanager UI.
        # ports:
        #     - 9093:9093
        deploy:
            resources:
                limits:
                    memory: 50M
                reservations:
                    memory: 20M
            placement:
                constraints: 
                    - 'node.role == manager'
                    - 'node.platform.os == linux'

    # Sample functions go here.

    # Pass a username as an argument to find how many images user has pushed to Docker Hub.
    hubstats:
        image: functions/hubstats:latest
        labels:
            function: "true"
        networks:
            - functions
        environment:
            no_proxy: "gateway"
            https_proxy: $https_proxy
        deploy:
            resources:
                limits:
                    memory: 50M
                reservations:
                    memory: 20M
            placement:
                constraints:
                    - 'node.platform.os == linux'

    # Node.js gives OS info about the node (Host)
    nodeinfo:
        image: functions/nodeinfo:latest
        labels:
            function: "true"
        networks:
            - functions
        environment:
            no_proxy: "gateway"
            https_proxy: $https_proxy
        deploy:
            resources:
                limits:
                    memory: 50M
                reservations:
                    memory: 20M
            placement:
                constraints:
                    - 'node.platform.os == linux'

    # Uses `cat` to echo back response, fastest function to execute.
    echoit:
        image: functions/alpine:latest
        labels:
            function: "true"
        networks:
            - functions
        environment:
            fprocess: "cat"
            no_proxy: "gateway"
            https_proxy: $https_proxy
        deploy:
            resources:
                limits:
                    memory: 50M
                reservations:
                    memory: 20M
            placement:
                constraints:
                    - 'node.platform.os == linux'

networks:
    functions:
        driver: overlay
        #attachable: true
