version: '2'
networks:
  lb_web:
    external: true
  back:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.0.${SUBNET}.0/24
services:
  web:
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    links:
      - app
    volumes_from:
      - app
    environment:
      - VIRTUAL_HOST
    networks:
    - back
    - lb_web
  app:
    image: indiehosters/nextcloud:${NEXTCLOUD_VERSION:-latest}
    links:
      - db
    volumes:
      - ./data/apps:/var/www/html/apps
      - ./data/custom_apps:/var/www/html/custom_apps
      - ./data/config:/var/www/html/config
      - ./data/data:/var/www/html/data
    environment:
      - MAIL_HOST
      - MAIL_FROM
      - MAIL_PASS
      - MAIL_PORT
      - URL
      - MAIL_DOMAIN
      - SMTP_NAME
      - MYSQL_DATABASE=nextcloud
      - MYSQL_HOST=db
      - MYSQL_USER=root
      - MYSQL_PASSWORD
      - NEXTCLOUD_ADMIN_USER=admin
      - NEXTCLOUD_ADMIN_PASSWORD
    networks:
    - back
  db:
    image: mysql:${MYSQL_VERSION:-5.7}
    volumes:
      - ./mysql/runtime:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD
    networks:
    - back
  redis:
    image: redis:${REDIS_VERSION:-latest}
    networks:
    - back
  cron:
    image: indiehosters/nextcloud:${NEXTCLOUD_VERSION:-latest}
    links:
      - db
    volumes_from:
      - app
    user: www-data
    entrypoint: |
      bash -c 'bash -s <<EOF
      trap "break;exit" SIGHUP SIGINT SIGTERM
      while /bin/true; do
        /usr/local/bin/php /var/www/html/cron.php
        sleep 900
      done
      EOF'
    networks:
    - back
