version: '2.4'

services:
  env:
    image: linkyard/yaml:1.1.1
    volumes:
      - .:/usr/local/vufind:rw
    working_dir: /usr/local/vufind
    entrypoint: ["devops/docker/env/entrypoint.sh"]

  composer:
    build: devops/docker/composer
    working_dir: /usr/local/vufind
    volumes:
      - .:/usr/local/vufind:rw
      - ${SSH_AUTH_SOCK}:/ssh-agent
      - $HOME/.ssh/known_hosts:/etc/ssh/ssh_known_hosts
    depends_on:
      - env
    entrypoint: ["devops/docker/composer/entrypoint.sh"]
    command: ["install"]

  php:
    build: devops/docker/php
    working_dir: /usr/local/vufind
    volumes:
      - ./:/usr/local/vufind
    depends_on:
      - env
      - db
    entrypoint: ["devops/docker/php/entrypoint.sh"]
    command: ["php-fpm"]

  httpd:
    image: ubleipzig/vufind-httpd:2.4-5
    ports:
      - 127.0.0.1:${HTTPD_PORT:-11100}:80
    volumes:
      - ./:/usr/local/vufind:ro
    depends_on:
      - php

  db:
    image: mariadb:10.3.17
    ports:
      - 127.0.0.1:${DB_PORT:-11101}:3306
    working_dir: /usr/local/vufind
    volumes:
      - ./:/usr/local/vufind:rw
      - db-data:/var/lib/mysql
    depends_on:
      - env
    entrypoint: ["devops/docker/db/entrypoint.sh"]
    command: [
      "mysqld",
      "--character-set-server=utf8mb4",
      "--collation-server=utf8mb4_unicode_ci"
    ]

  mail:
    image: useltmann/mailcollect:8-1
    working_dir: /usr/local/vufind
    ports:
      - 127.0.0.1:${SMTP_PORT:-11102}:25
      - 127.0.0.1:${IMAP_PORT:-11103}:143
    volumes:
      - mail-data:/home/dev/Maildir:z
      - ./:/usr/local/vufind:rw
    depends_on:
      - env
    entrypoint: ["devops/docker/mail/entrypoint.sh"]
    command: ["run"]

  grunt:
    image: node:7.10.1-slim
    working_dir: /usr/local/vufind
    volumes:
      - ./:/usr/local/vufind:rw
    depends_on:
      - env
    entrypoint: ["devops/docker/grunt/entrypoint.sh"]
    command: ["watch"]

  autoconfig:
    image: node:7.10.1-alpine
    working_dir: /usr/local/vufind
    volumes:
      - ./:/usr/local/vufind:rw
    depends_on:
      - env
      - db
    entrypoint: ["devops/docker/autoconfig/entrypoint.sh"]
    command: ["vufind", "deploy"]

volumes:
  db-data: {}
  mail-data: {}

networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: ${NET_MASK:-10.111}.0.0/24
          gateway: ${NET_MASK:-10.111}.0.1
