version: "3.6"
services:
  database:
    image: mdillon/postgis:10
    volumes:
      - db-data:/var/lib/postgresql/data
    env_file:
      - env/vhr18.env
      - env/vhr18_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/vhr18.env
      - env/vhr18_db.env
      - env/vhr18_django.env
      - env/vhr18_obs.env
    environment:
      INSTANCE_ID: "prism-view-server_renderer"
      INSTALL_DIR: "/var/www/pvs/dev/"
      COLLECT_STATIC: "false"
      INIT_SCRIPTS: "/configure.sh /init-db.sh /initialized.sh"
      STARTUP_SCRIPTS: "/wait-initialized.sh"
      WAIT_SERVICES: "database:5432"
    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/vhr18.env
      - env/vhr18_db.env
      - env/vhr18_obs.env
    environment:
      INSTANCE_ID: "prism-view-server_cache"
      RENDERER_HOST: renderer
      WAIT_SERVICES: "database:5432 renderer:80"
      WAIT_TIMEOUT: 300  # wait up to 5 minutes
    deploy:
      replicas: 1
    logging:
      options:
        tag: "docker.apache2"
    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/vhr18.env
      - env/vhr18_obs.env
      - env/vhr18_redis.env
    environment:
      INSTANCE_ID: "prism-view-server_seeder"
      RENDERER_HOST: renderer
      WAIT_SERVICES: "redis:6379 database:5432"
    deploy:
      replicas: 0
    networks:
      - intnet
    command:
      ["/run-seeder.sh"]
  preprocessor:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_preprocessor:latest
    env_file:
      - env/vhr18.env
      - env/vhr18_obs.env
      - env/vhr18_redis.env
      - env/vhr18_preprocessor.env
    environment:
      INSTANCE_ID: "prism-view-server_preprocessor"
      WAIT_SERVICES: "redis:6379"
    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/vhr18.env
      - env/vhr18_db.env
      - env/vhr18_obs.env
      - env/vhr18_redis.env
    environment:
      INSTANCE_ID: "prism-view-server_registrar"
      INSTALL_DIR: "/var/www/pvs/dev/"
      SCALEFACTOR: "1"
      IN_MEMORY: "false"
      COLLECT_STATIC: "false"
      INIT_SCRIPTS: "/configure.sh /init-db.sh /initialized.sh"
      STARTUP_SCRIPTS: "/wait-initialized.sh"
      WAIT_SERVICES: "redis:6379 database:5432"
    configs:
      - source: init-db
        target: /init-db.sh
    deploy:
      replicas: 1
    networks:
      - intnet
    command:
      ["/run-registrar.sh"]
  client:
    image: registry.gitlab.eox.at/esa/prism/vs/pvs_client:latest
    deploy:
      replicas: 1
  sftp:
    image: atmoz/sftp:latest
    volumes:
      - type: volume
        source: to-panda
        target: /home/eox/data/to/panda
      - type: volume
        source: from-fepd
        target: /home/eox/data/from/fepd
    configs:
      - source: sftp-users
        target: /etc/sftp/users.conf

    ports:
        - "2222:22"
    deploy:
      replicas: 1
configs:
  sftp-users:
    file: ./config/vhr18_sftp_users.conf
  init-db:
    file: ./config/vhr18_init-db.sh
  mapcache-dev:
    file: ./config/vhr18_mapcache-dev.xml
  mapcache-ops:
    file: ./config/vhr18_mapcache-ops.xml
  client-dev:
    file: ./config/vhr18_index-dev.html
  client-ops:
    file: ./config/vhr18_index-ops.html
volumes:
  db-data:
  redis-data:
  cache-db:
  instance-data:
networks:
  intnet:
