version: '2.4'

services:
  composer:
    build: devops/docker/composer
    working_dir: /usr/local/vufind
    volumes:
      - .:/usr/local/vufind:z
      - composer-data:/tmp
      - ${SSH_AUTH_SOCK}:/ssh-agent
      - $HOME/.ssh/known_hosts:/etc/ssh/ssh_known_hosts
    environment:
      SSH_AUTH_SOCK: /ssh-agent
    command: echo "Skipping composer."

  php:
    image: ubleipzig/vufind-php:7.1-8-debug
    volumes:
      - ./:/usr/local/vufind
    environment:
      VUFIND_LOCAL_DIR: /usr/local/vufind/fid/dev
      VUFIND_CACHE_DIR: /usr/local/vufind/data/cache
      VUFIND_ENV: development
      PHP_IDE_CONFIG: serverName=fid
      XDEBUG_CONFIG: >-
        remote_autostart=1
        remote_mode=req
        remote_handler=dbgp
        remote_connect_back=0
        remote_port=9000
        remote_enable=1
        remote_host=10.111.0.1

  httpd:
    image: ubleipzig/vufind-httpd:2.4-2
    ports:
      - 127.0.0.1:11100:80
    volumes:
      - ./:/usr/local/vufind:ro
      - ./data/cache:/var/cache/vufind:ro
    depends_on:
      - php
    command: httpd -D FOREGROUND -c "ProxyTimeout 3600"

  db:
    image: mariadb:10.2
    ports:
      - 127.0.0.1:11101:3306
    volumes:
      - mariadb-data:/var/lib/mysql:z
    environment:
      MYSQL_ROOT_PASSWORD: adminpw
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci

  smtp:
    image: useltmann/mailcollect:8-1
    ports:
      - 25:25
      - 143:143
    volumes:
      - mail-data:/home/dev/Maildir:z

  grunt:
    image: ubleipzig/vufind-php:7.2-8-debug
    volumes:
      - ./:/usr/local/vufind:z
      - npm-data:/home/www-data/.npm
    environment:
      NODE_ENV: development
    command: npm install && node_modules/.bin/grunt watch

  autoconfig:
    image: ubleipzig/vufind-php:7.1-8-debug
    volumes:
      - ./:/usr/local/vufind:z
    environment:
      VUFIND_SITE: fid
      VUFIND_INSTANCE: dev
      VUFIND_DB_CLIENT: "%"
      VUFIND_DB_ADMIN_PASSWORD: adminpw
      VF_config_ini__Authentication__hash_passwords: "true"
      VF_config_ini__Authentication__encrypt_ils_password: "true"
      VF_config_ini__Database__database: mysql://vufind:vufindpw@db/vufind
      VF_config_ini__Index__url: https://index.ub.uni-leipzig.de/solr
      VF_config_ini__Mail__host: smtp
      VF_config_ini__Mail__port: 25
      VF_config_ini__Mail__username: dev
      VF_config_ini__Mail__pasword: dev
    entrypoint: >
      sh -c 'sh -c "exit 1";
      while [ $$? -eq 1 ]; do nc -zv db:3306 &> /dev/null; done;
      /docker-entrypoint $$0 $$@'
    command: autoconfig vufind deploy
    depends_on:
      - db

volumes:
  npm-data: {}
  mail-data: {}
  mariadb-data: {}
  composer-data: {}

networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 10.111.0.0/24
          gateway: 10.111.0.1
