version: '3.4'

services:
  broadcast-channel:
    image: redis:6.2
    restart: always
    #command: redis-server --loglevel warning
    command: /bin/sh -c "redis-server --requirepass $$REDIS_HOST_PASSWORD"
    ports:
      - '7379:6379'
    volumes:
      - cache:/data
    environment:
      - REDIS_HOST_PASSWORD=sS1a8I20TJb1qfMyRapWpkfUuBE3bq7X4AzCaK7cOfE=
  opal-server:
    # by default we run opal-server from latest official image
    image: permitio/opal-server:0.7.3
    environment:
      - OPAL_REPO_WATCHER_ENABLED=false
      #- OPAL_BROADCAST_URI=redis://broadcast-channel:6379
      - OPAL_BROADCAST_URI=redis://:sS1a8I20TJb1qfMyRapWpkfUuBE3bq7X4AzCaK7cOfE=@broadcast-channel:6379
      - OPAL_DATA_CONFIG_SOURCES={"config":{"entries":[]}}
      - UVICORN_NUM_WORKERS=4
      - OPAL_LOG_FORMAT_INCLUDE_PID=true
    ports:
      # exposes opal server on the host machine, you can access the server at: http://localhost:7002
      - "7004:7002"
    depends_on:
      - broadcast-channel
  opal-client:
    # by default we run opal-client from latest official image
    image: permitio/opal-client:0.7.3
    environment:
      - OPAL_SERVER_URL=http://opal-server:7002
      - OPAL_INLINE_OPA_CONFIG={"log_level":"debug", "files":[]}
      - OPAL_OFFLINE_MODE_ENABLED=true
      - OPAL_STORE_BACKUP_INTERVAL=10
      - OPAL_POLICY_UPDATER_ENABLED=false
    ports:
      # exposes opal client on the host machine, you can access the client at: http://localhost:7000
      - "7000:7000"
      # exposes the OPA agent (being run by OPAL) on the host machine
      # you can access the OPA api that you know and love at: http://localhost:8181
      # OPA api docs are at: https://www.openpolicyagent.org/docs/latest/rest-api/
      - "8181:8181"
    volumes:
    #  - ./sample.tar.gz:/opal/sample.tar.gz
      - ./opa.json:/opal/backup/opa.json
    depends_on:
      - opal-server
    # this command is not necessary when deploying OPAL for real, it is simply a trick for dev environments
    # to make sure that opal-server is already up before starting the client.
    command: sh -c "./wait-for.sh opal-server:7002 --timeout=20 -- ./start.sh"
volumes:
  cache:
    driver: local
