services:
  web:
    build:
      context: .
      dockerfile: ./docker/nginx/Dockerfile
    container_name: vichan_web
    restart: unless-stopped
    volumes:
      - ./local-instances/${INSTANCE:-0}/www:/var/www/html
      - ./docker/nginx/vichan.conf:/etc/nginx/conf.d/default.conf
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/proxy.conf:/etc/nginx/conf.d/proxy.conf
#      - ./docker/nginx/ssl:/etc/nginx/ssl # optional For SSL
    ports:
      - "9080:80"
#      - "9081:443" # optional for SSL
    depends_on:
      - db
      - php
    links:
      - php

  php:
    build:
      context: .
      dockerfile: ./docker/php/Dockerfile
    container_name: vichan_php
    restart: unless-stopped
    volumes:
      - ./local-instances/${INSTANCE:-0}/www:/var/www
      - ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
      - ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini
      - ./docker/php/php.ini:/usr/local/etc/php/php.ini
    environment:
      # Database settings
      VICHAN_MYSQL_HOST: ${VICHAN_MYSQL_HOST}
      VICHAN_MYSQL_USER: ${VICHAN_MYSQL_USER}
      VICHAN_MYSQL_NAME: ${VICHAN_MYSQL_NAME}
      VICHAN_MYSQL_PASSWORD: ${VICHAN_MYSQL_PASSWORD}
      # Security
      VICHAN_SECURE_LOGIN_ONLY: ${VICHAN_SECURE_LOGIN_ONLY}
      # Cache settings
      VICHAN_CACHE_ENGINE: ${VICHAN_CACHE_ENGINE}
      VICHAN_CACHE_HOST: ${VICHAN_CACHE_HOST}
      VICHAN_CACHE_PORT: ${VICHAN_CACHE_PORT}
      VICHAN_CACHE_PASSWORD: ${VICHAN_CACHE_PASSWORD}
      # Cookies
      VICHAN_COOKIES_MOD: ${VICHAN_COOKIES_MOD}
      # Flood Control
      VICHAN_FLOOD_TIME: ${VICHAN_FLOOD_TIME}
      VICHAN_FLOOD_TIME_IP: ${VICHAN_FLOOD_TIME_IP}
      VICHAN_FLOOD_TIME_SAME: ${VICHAN_FLOOD_TIME_SAME}
      VICHAN_MAX_BODY: ${VICHAN_MAX_BODY}
      VICHAN_REPLY_LIMIT: ${VICHAN_REPLY_LIMIT}
      VICHAN_MAX_LINKS: ${VICHAN_MAX_LINKS}
      # Images
      VICHAN_IMAGES_MAX_FILESIZE: ${VICHAN_IMAGES_MAX_FILESIZE}
      VICHAN_IMAGES_THUMB_WIDTH: ${VICHAN_IMAGES_THUMB_WIDTH}
      VICHAN_IMAGES_THUMB_HEIGHT: ${VICHAN_IMAGES_THUMB_HEIGHT}
      VICHAN_IMAGES_MAX_WIDTH: ${VICHAN_IMAGES_MAX_WIDTH}
      VICHAN_IMAGES_MAX_HEIGHT: ${VICHAN_IMAGES_MAX_HEIGHT}
      # Display
      VICHAN_DISPLAY_THREADS_PER_PAGE: ${VICHAN_DISPLAY_THREADS_PER_PAGE}
      VICHAN_DISPLAY_MAX_PAGES: ${VICHAN_DISPLAY_MAX_PAGES}
      VICHAN_DISPLAY_THREADS_PREVIEW: ${VICHAN_DISPLAY_THREADS_PREVIEW}
      # Directories
      VICHAN_DIRECTORIES_ROOT: ${VICHAN_DIRECTORIES_ROOT}
    depends_on:
      - db

  db:
    image: mysql:lts
    # image: mariadb:lts # optional for more higher performance
    container_name: vichan_db
    restart: unless-stopped
    volumes:
      - ./local-instances/${INSTANCE:-0}/db:/var/lib/mysql
    # ports:
    #   - "9082:3306" # optional for external access
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}

  redis:
    image: redis:latest
    container_name: vichan_redis
    restart: unless-stopped
    volumes:
      - ./local-instances/${INSTANCE:-0}/redis:/data
    environment:
      REDIS_PASSWORD: ${VICHAN_CACHE_PASSWORD}
    command: redis-server --requirepass ${VICHAN_CACHE_PASSWORD}
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "${VICHAN_CACHE_PASSWORD}", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s