# -*- coding: utf-8 -*-
#
# Copyright (C) 2018-2024 CERN.
#
# invenio-app-ils is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

services:
  backend:
    build:
      context: ./
      dockerfile: ./docker/backend/Dockerfile
      args:
        - ENVIRONMENT=DEV
    image: invenio_app_ils-backend
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:5000:5000"
    environment:
      - "INVENIO_ACCOUNTS_SESSION_REDIS_URL=redis://cache:6379/1"
      - "INVENIO_BROKER_URL=amqp://guest:guest@mq:5672/"
      - "INVENIO_CACHE_REDIS_URL=redis://cache:6379/0"
      - "INVENIO_CACHE_TYPE=redis"
      - "INVENIO_CELERY_BROKER_URL=amqp://guest:guest@mq:5672/"
      - "INVENIO_CELERY_RESULT_BACKEND=redis://cache:6379/2"
      - "INVENIO_SEARCH_ELASTIC_HOSTS=['search:9200']"
      - "INVENIO_SECRET_KEY=CHANGE_ME"
      - "INVENIO_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://test:psw@db/ils"
      - "INVENIO_RATELIMIT_STORAGE_URI=redis://cache:6379/3"
      - "INVENIO_SPA_HOST=https://127.0.0.1"
      - "INVENIO_REST_CSRF_ENABLED=False"
  frontend:
    build:
      context: ./
      dockerfile: ./docker/frontend/Dockerfile
    image: invenio_app_ils-frontend
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:80:80"
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:443:443"
  lb:
    build: ./docker/lb/
    image: invenio_app_ils-lb
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:80:80"
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:443:443"
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:8080:8080"
  cache:
    image: redis:6
    read_only: true
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:6379:6379"
  db:
    image: postgres:14
    environment:
      - "POSTGRES_USER=test"
      - "POSTGRES_PASSWORD=psw"
      - "POSTGRES_DB=ils"
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:5432:5432"
  mq:
    image: rabbitmq:3-management
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:15672:15672"
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:5672:5672"
  search:
    image: opensearchproject/opensearch::3.2.0
    environment:
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - "DISABLE_INSTALL_DEMO_CONFIG=true"
      - "DISABLE_SECURITY_PLUGIN=true"
      - "discovery.type=single-node"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 1g
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:9200:9200"
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:9300:9300"
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:3.2.0
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:5601:5601"
    expose:
      - "5601"
    environment:
      # settings only for development. DO NOT use in production!
      - 'OPENSEARCH_HOSTS=["http://search:9200"]'
      - "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true"
  flower:
    image: mher/flower:0.9.7
    command: --broker=amqp://guest:guest@mq:5672/ --broker_api=http://guest:guest@mq:15672/api/
    ports:
      - "${DOCKER_SERVICES_IP_BIND:-127.0.0.1}:5555:5555"
