version: "3.6"
services:
  database:
    image: mdillon/postgis:10
    volumes:
      - db-data:/var/lib/postgresql/data
    env_file:
      - env/emg.env
      - env/emg_db.env
    environment:
      INSTANCE_ID: "prism-view-server_database"
    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - intnet
  redis:
    image: redis
    volumes:
      - redis-data:/data
    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - intnet
  renderer:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_core:latest
    volumes:
      - type: tmpfs
        target: /tmp
      - type: volume
        source: cache-db
        target: /cache-db
      - type: volume
        source: instance-data
        target: /var/www/pvs
    env_file:
      - env/emg.env
      - env/emg_db.env
      - env/emg_django.env
      - env/emg_obs.env
    environment:
      INSTANCE_ID: "prism-view-server_renderer"
      INSTALL_DIR: "/var/www/pvs/dev/"
      INIT_SCRIPTS: "/configure.sh /init-db.sh"
    configs:
      - source: init-db
        target: /init-db.sh
    deploy:
      replicas: 1
    networks:
      - intnet
    command:
      ["/run-httpd.sh"]
  cache:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_cache:latest
    volumes:
      - type: tmpfs
        target: /tmp
      - type: volume
        source: cache-db
        target: /cache-db
    env_file:
      - env/emg.env
      - env/emg_db.env
      - env/emg_obs.env
    environment:
      INSTANCE_ID: "prism-view-server_cache"
      RENDERER_HOST: renderer
    deploy:
      replicas: 1
    networks:
      - intnet
    command:
      ["/run-httpd.sh"]
  seeder:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_cache:latest
    volumes:
      - type: tmpfs
        target: /tmp
      - type: volume
        source: cache-db
        target: /cache-db
    env_file:
      - env/emg.env
      - env/emg_obs.env
      - env/emg_redis.env
    environment:
      INSTANCE_ID: "prism-view-server_seeder"
      RENDERER_HOST: renderer
    deploy:
      replicas: 0
    networks:
      - intnet
    command:
      ["/run-seeder.sh"]
  preprocessor:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_preprocessor:latest
    env_file:
      - env/emg.env
      - env/emg_obs.env
      - env/emg_redis.env
    environment:
      INSTANCE_ID: "prism-view-server_preprocessor"
    deploy:
      replicas: 1
    networks:
      - intnet
    command:
      ["/run-preprocessor.sh"]
  registrar:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_core:latest
    volumes:
      - type: tmpfs
        target: /tmp
      - type: volume
        source: instance-data
        target: /var/www/pvs
    env_file:
      - env/emg.env
      - env/emg_db.env
      - env/emg_obs.env
      - env/emg_redis.env
    environment:
      INSTANCE_ID: "prism-view-server_registrar"
      INSTALL_DIR: "/var/www/pvs/dev/"
      SCALEFACTOR: "1"
      IN_MEMORY: "false"
      INIT_SCRIPTS: "/configure.sh /init-db.sh"
    configs:
      - source: init-db
        target: /init-db.sh
    deploy:
      replicas: 1
    networks:
      - intnet
    command:
      ["/run-registrar.sh"]
  # redis-manager:
  #   image: registry.gitlab.eox.at/esa/prism/vs/pvs_core:latest
  #   volumes:
  #     - type: tmpfs
  #       target: /tmp
  #     - type: volume
  #       source: cache-db
  #       target: /cache-db
  #   env_file:
  #     - env/emg.env
  #     - env/emg_db.env
  #     - env/emg_redis.env
  #   environment:
  #     INSTANCE_ID: "prism-view-server_redis-manager"
  #     INSTALL_DIR: "/var/www/pvs/dev/"
  #     CACHE_DB_PATH: "/cache-db/emg_mapcache_cache.sqlite"
  #   deploy:
  #     replicas: 0
  #   networks:
  #     - intnet
  #   command:
  #     ["/run-redis-manager.sh"]
  client:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_client:latest
    deploy:
      replicas: 1
configs:
  init-db:
    file: ./config/emg_init-db.sh
  mapcache-dev:
    file: ./config/emg_mapcache-dev.xml
  mapcache-ops:
    file: ./config/emg_mapcache-ops.xml
  client-dev:
    file: ./config/emg_index-dev.html
  client-ops:
    file: ./config/emg_index-ops.html
volumes:
  db-data:
  redis-data:
  cache-db:
  instance-data:
networks:
  intnet:
