#
# Use this configuration to test the production configuration locally.
#
# This configuration builds the frontend and backend services as Docker images,
# and uses the paths for the services, instead of ports.
#
services:
    web:
        build:
            context: .
            dockerfile: frontend/Dockerfile
        ports:
            - '8080:8080/tcp'
        restart: unless-stopped
        labels:
            - 'traefik.http.routers.web.rule=PathPrefix(`/`)'
            - 'traefik.http.services.web.loadbalancer.server.port=8080'

    api:
        build:
            context: .
            dockerfile: backend/Dockerfile
        ports:
            - '3000:3000/tcp'
        restart: unless-stopped
        volumes:
            - ./backend/.env.staging:/app/dwengo/backend/.env
        depends_on:
            - db
            - logging
        labels:
            - 'traefik.http.routers.api.rule=PathPrefix(`/api`)'
            - 'traefik.http.services.api.loadbalancer.server.port=3000'

    db:
        extends:
            file: ./compose.yml
            service: db

    idp:
        extends:
            file: ./compose.yml
            service: idp
        labels:
            - 'traefik.http.routers.idp.rule=PathPrefix(`/idp`)'
            - 'traefik.http.services.idp.loadbalancer.server.port=7080'
        environment:
            PROXY_ADDRESS_FORWARDING: 'true'
            KC_HTTP_RELATIVE_PATH: '/idp'

    reverse-proxy:
        image: traefik:v3.3
        command:
            # Enable web UI
            - '--api.insecure=true'

            # Add Docker provider
            - '--providers.docker=true'
            - '--providers.docker.exposedbydefault=true'

            # Add web entrypoint
            - '--entrypoints.web.address=:80/tcp'
        ports:
            - '9000:8080'
            - '80:80/tcp'
        restart: unless-stopped
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:ro

    logging:
        image: grafana/loki:latest
        ports:
            - '9001:3102'
            - '9095:9095'
        command: -config.file=/etc/loki/config.yaml
        restart: unless-stopped
        volumes:
            - ./config/loki/config.yml:/etc/loki/config.yaml
            - dwengo_loki_data:/loki

    dashboards:
        image: grafana/grafana:latest
        ports:
            - '9002:3000'
        volumes:
            - dwengo_grafana_data:/var/lib/grafana
        restart: unless-stopped

volumes:
    dwengo_grafana_data:
    dwengo_loki_data:
    dwengo_postgres_data:
