version: "3.8"

services:
    db:
        build:
            context: ./database
            dockerfile: Dockerfile
        network_mode: "host"
        environment:
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
        command: -p 55432
        healthcheck:
            test: ["CMD-SHELL", "pg_isready -U postgres -p 55432"]
            interval: 1s
            timeout: 5s
            retries: 10
    machines-app:
        build:
            context: ./machines
            dockerfile: Dockerfile
        network_mode: "host"
        environment:
            - APPPORT=4000
            - DBHOST=localhost
            - DBPORT=55432
            - DBNAME=komponiranje
            - DBUSER=pero
            - DBPASSWORD=pero.000
            - PRODUCTSAPPURL=http://localhost:10000
        depends_on:
            db:
                condition: service_healthy
    products-app:
        build:
            context: ./products
            dockerfile: Dockerfile
        network_mode: "host"
        environment:
            - APPPORT=4001
            - DBHOST=localhost
            - DBPORT=55432
            - DBNAME=komponiranje
            - DBUSER=pero
            - DBPASSWORD=pero.000
        depends_on:
            db:
                condition: service_healthy
    proxy:
        image: envoyproxy/envoy:v1.28-latest
        network_mode: "host"
        volumes:
            - ./proxy/envoy-local.yaml:/etc/envoy/envoy.yaml
        depends_on:
            - machines-app
            - products-app
    frontend-app:
        build:
            context: ./frontend
            dockerfile: Dockerfile
            args:
                - REACT_APP_MACHINES_API_URL=http://localhost:10000
                - REACT_APP_PRODUCTS_API_URL=http://localhost:10000
        network_mode: "host"
        depends_on:
            - proxy
