services:

  # inspired by ~/git/apache/fineract/config/docker/compose/mariadb.yml
  #
  # test connection with:
  #
  #    docker run --rm -it --network=host mariadb:11.2 mariadb -hlocalhost -uroot -pmysql --protocol=tcp
  #
  mariadb:
    # run as non-root -- NOPE, need root for health check
    #user: 1000:1000
    # 11.2 goes EOL on Nov 21, 2024
    # see https://mariadb.org/about/#maintenance-policy
    image: mariadb:11.5
    volumes:
      # use utf-8
      - /home/user/git/apache/fineract/config/docker/mysql/conf.d/server_collation.cnf:/etc/mysql/conf.d/server_collation.cnf:ro
      # create dbs - conflicts with `./gradlew createDB -PdbName=fineract_tenants` etc. instructions at https://fineract-academy.com/how-to-build-fineract-with-intellij-idea.html
      #- /home/user/git/apache/fineract/config/docker/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:Z,ro
      # surprisingly, not mentioned in https://github.com/apache/fineract/blob/develop/config/docker/compose/mariadb.yml
      # FIXME - also change in integration-tests.sh
      #- /home/user/.local/share/fineract/mariadb:/var/lib/mysql
      - /home/user/.local/share/fineract/mariadb-ramdisk:/var/lib/mysql
    restart: unless-stopped
    environment:
      MARIADB_AUTO_UPGRADE: yes
      MARIADB_ROOT_PASSWORD: mysql
    ports:
      - 3306:3306
    # shouldn't be necessary, published ports are good enough
    #network_mode: host
    # disable health check? no... seems to be necessary. 😭
    # see https://github.com/docker-library/faq#healthcheck
    healthcheck:
      test: [ "CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
      timeout: 10s
      retries: 10

  # inspired by ~/git/apache/fineract/config/docker/compose/postgresql.yml
  #
  # see ~/git/apache/fineract/config/docker/postgresql/docker-entrypoint-initdb.d/01-init.sh
  postgres:
    # run as non-root
    user: 1000:1000
    image: postgres:17.4
    volumes:
      #- /etc/passwd:/etc/passwd:ro
      # FIXME - also change in integration-tests.sh
      #- /home/user/.local/share/fineract/postgres:/var/lib/postgresql/data
      - /home/user/.local/share/fineract/postgres-ramdisk:/var/lib/postgresql/data
    restart: unless-stopped
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: postgres
    ports:
      - 5432:5432
    healthcheck:
      test: [ "CMD", "pg_isready", "-q", "-d", "postgres", "-U", "root" ]
      timeout: 10s
      retries: 10

  mock-oauth2-server:
    user: 1000:1000
    image: ghcr.io/navikt/mock-oauth2-server:2.1.10
    ports:
      - 9000:9000
    environment:
      SERVER_PORT: 9000
      JSON_CONFIG: '{ "interactiveLogin": true, "httpServer": "NettyWrapper", "tokenCallbacks": [ { "issuerId": "auth/realms/fineract", "tokenExpiry": 120, "requestMappings": [{ "requestParam": "scope", "match": "fineract", "claims": { "sub": "mifos", "scope": [ "test" ] } } ] } ] }'
    restart: unless-stopped

  # must run as root? filesystem permissions issues otherwise
  activemq:
    image: symptoma/activemq:5.18.3
    ports:
      - 6161:6161
      - 61616:61616
      - 8161:8161
    restart: unless-stopped

  localstack:
    image: localstack/localstack:2.1
    environment:
      AWS_ENDPOINT_URL: http://localhost:4566
      AWS_ACCESS_KEY_ID: localstack
      AWS_SECRET_ACCESS_KEY: localstack
      AWS_REGION: us-east-1
    ports:
      - 4566:4566
      - 4510-4559:4510-4559
    restart: unless-stopped
