x-app: &app
  build:
    context: .
    args:
      RUBY_VERSION: '3.1'
  # Increase the version number in the image tag every time Dockerfile or its arguments is changed
  image: ontologies_api:0.0.6
  environment: &env
    BUNDLE_PATH: /srv/ontoportal/bundle
    # default bundle config resolves to /usr/local/bundle/config inside of the container
    # we are setting it to local app directory if we need to use 'bundle config local'
    BUNDLE_APP_CONFIG: /srv/ontoportal/ontologies_api/.bundle
    COVERAGE: 'true'
    GOO_REDIS_HOST: redis-ut
    REDIS_GOO_CACHE_HOST: redis-ut
    REDIS_HTTP_CACHE_HOST: redis-ut
    REDIS_PERSISTENT_HOST: redis-ut
    REDIS_PORT: 6379
    SOLR_TERM_SEARCH_URL: http://solr-ut:8983/solr/term_search_core1
    SOLR_PROP_SEARCH_URL: http://solr-ut:8983/solr/prop_search_core1
    MGREP_HOST: mgrep-ut
    MGREP_PORT: 55556
  stdin_open: true
  tty: true
  command: "bundle exec rackup -o 0.0.0.0 --port 9393"
  ports:
    - 9393:9393
  volumes:
    # bundle volume for hosting gems installed by bundle; it helps in local development with gem udpates
    - bundle:/srv/ontoportal/bundle
    # api code
    - .:/srv/ontoportal/ontologies_api
    # mount directory containing development version of the gems if you need to use 'bundle config local'
    #- /Users/alexskr/ontoportal:/Users/alexskr/ontoportal
  depends_on: &depends_on
    solr-ut:
      condition: service_healthy
    redis-ut:
      condition: service_healthy
    mgrep-ut:
      condition: service_healthy

services:
  api:
    <<: *app
    environment:
      <<: *env
      GOO_BACKEND_NAME: 4store
      GOO_PORT: 9000
      GOO_HOST: 4store-ut
      GOO_PATH_QUERY: /sparql/
      GOO_PATH_DATA: /data/
      GOO_PATH_UPDATE: /update/
    profiles:
      - 4store
    depends_on:
      <<: *depends_on
      4store-ut:
        condition: service_started

  api-agraph:
    <<: *app
    environment:
      <<: *env
      GOO_BACKEND_NAME: ag
      GOO_PORT: 10035
      GOO_HOST: agraph-ut
      GOO_PATH_QUERY: /repositories/ontoportal_test
      GOO_PATH_DATA: /repositories/ontoportal_test/statements
      GOO_PATH_UPDATE: /repositories/ontoportal_test/statements
    profiles:
      - agraph
    depends_on:
      <<: *depends_on
      agraph-ut:
        condition: service_healthy

  redis-ut:
    image: redis
    healthcheck:
      test: redis-cli ping
      interval: 10s
      timeout: 3s
      retries: 10

  4store-ut:
    image: bde2020/4store
    platform: linux/amd64
    #volume: fourstore:/var/lib/4store
    command: >
      bash -c "4s-backend-setup --segments 4 ontoportal_kb
      && 4s-backend ontoportal_kb
      && 4s-httpd -D -s-1 -p 9000 ontoportal_kb"
    profiles:
      - 4store

  solr-ut:
    image: solr:8
    volumes:
      - ./test/solr/configsets:/configsets:ro
    ports:
      - "8983:8983"
    command: >
      bash -c "precreate-core term_search_core1 /configsets/term_search
      && precreate-core prop_search_core1 /configsets/property_search
      && solr-foreground"
    healthcheck:
      test: [ "CMD-SHELL", "curl -sf http://localhost:8983/solr/term_search_core1/admin/ping?wt=json | grep -iq '\"status\":\"OK\"}' || exit 1" ]
      start_period: 5s
      interval: 10s
      timeout: 5s
      retries: 5

  mgrep-ut:
    image: ontoportal/mgrep:0.0.2
    platform: linux/amd64
    healthcheck:
      test: ["CMD", "nc", "-z", "-v", "127.0.0.1", "55556"]
      start_period: 3s
      interval: 10s
      timeout: 5s
      retries: 5

  agraph-ut:
    image: franzinc/agraph:v8.1.0
    platform: linux/amd64
    environment:
      - AGRAPH_SUPER_USER=test
      - AGRAPH_SUPER_PASSWORD=xyzzy
    shm_size: 1g
    # ports:
    #  - 10035:10035
    command: >
       bash -c "/agraph/bin/agraph-control --config /agraph/etc/agraph.cfg start
       ; agtool repos create ontoportal_test
       ; agtool users add anonymous
       ; agtool users grant anonymous root:ontoportal_test:rw
       ; tail -f /agraph/data/agraph.log"
    healthcheck:
      test: ["CMD-SHELL", "agtool storage-report ontoportal_test || exit 1"]
      start_period: 30s
      interval: 20s
      timeout: 10s
      retries: 10
    profiles:
      - agraph

volumes:
  bundle:

