version: '3'

services:
    client:
        build:
            context: ./client
            dockerfile: ./Dockerfile.dev
        ports:
            - 4200:4200
        working_dir: /project
        volumes:
            - ./client:/project
        command: ng serve --host=0.0.0.0 --disable-host-check --port 4200
    server:
        build:
            context: ./server
            dockerfile: ./Dockerfile.dev
        environment:
            docker: "true"
            DISPLAY_ERROR_DETAILS: "true"
            DATABASE_DEV_MODE: 1
            DATABASE_CO_DRIVER: "pdo_pgsql"
            DATABASE_CO_HOST: "db"
            DATABASE_CO_PORT: 5432
            DATABASE_CO_DBNAME: "anis_metamodel"
            DATABASE_CO_USER: "postgres"
            DATABASE_CO_PASSWORD: "postgres"
            DATA_PATH: "/data"
            LOGGER_NAME: "anis-metamodel"
            LOGGER_PATH: "php://stderr"
            LOGGER_LEVEL: "debug"
            SERVICES_URL: "http://localhost:5000"
            BASE_HREF: "/"
            SSO_AUTH_URL: "http://localhost:8180/auth"
            SSO_REALM: "anis"
            SSO_CLIENT_ID: "anis-client"
            TOKEN_ENABLED: 0
            TOKEN_JWKS_URL: "http://keycloak:8180/auth/realms/anis/protocol/openid-connect/certs"
            TOKEN_ADMIN_ROLES: anis_admin,superuser
            RMQ_HOST: rmq
            RMQ_PORT: 5672
            RMQ_USER: admin
            RMQ_PASSWORD: admin
        ports:
            - 8080:80
        volumes:
            - ./server:/project
            - ./conf-dev/dev-php.ini:/usr/local/etc/php/conf.d/dev-php.ini
            - ./conf-dev/init-keycloak.sh:/mnt/init-keycloak.sh
            - ./conf-dev/create-db.sh:/mnt/create-db.sh
            - ./data:/data
    services:
        image: python:3.8
        environment:
            PYTHONPATH: "/project/src"
            FLASK_ENV: development
            DATA_PATH: /data
            SERVER_URL: http://server
        working_dir: /project
        ports:
            - 5000:5000
        volumes:
            - ./services:/project
            - ./data:/data
        command: /bin/bash -c "source /project/venv/bin/activate && exec python src/anis_services/app.py"
    tasks:
        image: python:3.8
        # stdin_open: true
        # tty: true
        # command: sleep infinity
        environment:
            PYTHONPATH: "/project/src"
            DATA_PATH: /data
            SERVER_URL: http://server
            RMQ_HOST: rmq
            RMQ_PORT: 5672
            RMQ_USER: admin
            RMQ_PASSWORD: admin
        working_dir: /project
        volumes:
            - ./tasks:/project
            - ./data:/data
        command: /bin/bash -c "source /project/venv/bin/activate && exec python src/anis_tasks/app.py"
    keycloak:
        image: jboss/keycloak
        environment:
            DB_VENDOR: POSTGRES
            DB_ADDR: db
            DB_DATABASE: keycloakdb
            DB_USER: keycloak
            DB_PASSWORD: keycloak
            DB_SCHEMA: public
            KEYCLOAK_USER: admin
            KEYCLOAK_PASSWORD: admin
            KEYCLOAK_IMPORT: /tmp/keycloak-anis-realm.json
        ports:
            - 8180:8180
        volumes:
            - ./conf-dev/keycloak-anis-realm.json:/tmp/keycloak-anis-realm.json
        command: -b 0.0.0.0 -Djboss.http.port=8180
    db:
        image: postgres
        environment:
            POSTGRES_PASSWORD: "postgres"
        volumes:
            - pgdata:/var/lib/postgresql/data
            - ./conf-dev/data_test.sql:/sql/data_test.sql
            - ./conf-dev/init-postgres.sh:/docker-entrypoint-initdb.d/init-postgres.sh
    rmq:
        image: rabbitmq:3-management
        environment:
            RABBITMQ_DEFAULT_USER: admin
            RABBITMQ_DEFAULT_PASS: admin
        ports:
            - 15672:15672
    mailer:
        image: djfarrelly/maildev
        ports:
            - 1080:80
volumes:
    pgdata:
