version: "3.8"

services:
    db:
        build:
            context: ./database
            dockerfile: Dockerfile
        ports:
            - 55432:5432
        environment:
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
        healthcheck:
            test: ["CMD-SHELL", "pg_isready -U postgres"]
            interval: 1s
            timeout: 5s
            retries: 10
    machines-app:
        build:
            context: ./machines
            dockerfile: Dockerfile
        environment:
            - APPPORT=3000
            - DBHOST=db
            - DBPORT=5432
            - DBNAME=komponiranje
            - DBUSER=pero
            - DBPASSWORD=pero.000
            - PRODUCTSAPPURL=http://proxy:10000
        depends_on:
            db:
                condition: service_healthy
    products-app:
        build:
            context: ./products
            dockerfile: Dockerfile
        deploy:
            mode: replicated
            replicas: 2
        environment:
            - APPPORT=3000
            - DBHOST=db
            - DBPORT=5432
            - DBNAME=komponiranje
            - DBUSER=pero
            - DBPASSWORD=pero.000
        depends_on:
            db:
                condition: service_healthy
    proxy:
        image: envoyproxy/envoy:v1.28-latest
        ports:
            - "10000:10000"
        volumes:
            - ./proxy/envoy.yaml:/etc/envoy/envoy.yaml
        depends_on:
            - machines-app
            - products-app
    frontend-app:
        build:
            context: ./frontend
            dockerfile: Dockerfile
        environment:
            - REACT_APP_BACKEND_API_URL="http://localhost:10000"
        ports:
            - "8080:80"
        depends_on:
            - proxy
