version: "3.0"

networks:
  xstudio-network:

# named volumes: mount a "volume" (not visible on the host's file system and only manageable thru docker's command line) on the container(s)
volumes:
  # this volume CAN be manually deleted when required as it contains only log files
  xstudio-volume-tomcat-logs:
  
  # this volume CAN be manually deleted when required as it contains only the database backup files
  xstudio-volume-backup:
  
  # these volumes must NEVER be deleted as they contain PERSISTANT data (incl. the database content)
  xstudio-volume-mariadb-dbdata:
  xstudio-volume-mariadb-conf:
  xstudio-volume-tomcat-conf:
  
services:
  # +------------------------------------------+
  # |                  MariaDB                 |
  # +------------------------------------------+
  mariadb-service:
    image: xqual/xstudio-mariadb:v96
    container_name: xstudio-mariadb-container
    # command: --max_allowed_packet=104857600  # Set max_allowed_packet to 100M
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
      MYSQL_DATABASE: $MYSQL_DATABASE
      MYSQL_USER: $MYSQL_USER
      MYSQL_PASSWORD: $MYSQL_PASSWORD
    ports:
      - "3306:3306"
    networks:
      - xstudio-network
    volumes:
      # named volume: to persistantly store the database data
      - xstudio-volume-mariadb-dbdata:/var/lib/mysql
      # named volume: to persistantly store the database conf
      - xstudio-volume-mariadb-conf:/etc/mysql
      # named volume: to persistantly store/share the backup files
      - xstudio-volume-backup:/home/backup
      
      
  # +------------------------------------------+
  # |                  Tomcat                  |
  # +------------------------------------------+
  tomcat-service:
    image: xqual/xstudio-tomcat:v13sp8
    container_name: xstudio-tomcat-container
    restart: always
    environment:
      SERVER_NAME: $SERVER_NAME
      SERVER_PROTOCOL: $SERVER_PROTOCOL
      SERVER_PORT: $SERVER_PORT
      MYSQL_DATABASE: $MYSQL_DATABASE
      MYSQL_USER: $MYSQL_USER
      MYSQL_PASSWORD_ENCRYPTED: $MYSQL_PASSWORD_ENCRYPTED
      XSTUDIO_USER: $XSTUDIO_USER
      XSTUDIO_PASSWORD_ENCRYPTED: $XSTUDIO_PASSWORD_ENCRYPTED
      LICENSE_KEY: $LICENSE_KEY
      SSL_KEYSTORE_ALIAS: $SSL_KEYSTORE_ALIAS
      SSL_KEYSTORE_PASSWORD: $SSL_KEYSTORE_PASSWORD
    ports:
      - "8080:8080"
    networks:
      - xstudio-network
    depends_on:
      - mariadb-service
    volumes:
      # named volume: to persistantly store the logs
      - xstudio-volume-tomcat-logs:/var/lib/tomcat8/logs
      # named volume: to persistantly save a copy of the previous configuration files
      - xstudio-volume-tomcat-conf:/root/conf
      
      
  # +------------------------------------------+
  # |         Daily and Weekly backups         |
  # +------------------------------------------+
  backup-service:
    image: xqual/xstudio-backup:v1
    container_name: xstudio-backup-container
    environment:
      MYSQL_DATABASE: $MYSQL_DATABASE
      MYSQL_USER: $MYSQL_USER
      MYSQL_PASSWORD: $MYSQL_PASSWORD
      CUSTOMER_INSTANCE_NAME: $CUSTOMER_INSTANCE_NAME
      BACKUP_FTP_HOST: $BACKUP_FTP_HOST
      BACKUP_FTP_USER: $BACKUP_FTP_USER
      BACKUP_FTP_PASSWORD: $BACKUP_FTP_PASSWORD
    depends_on:
      - mariadb-service
    networks:
      - xstudio-network
    volumes:
      # named volume: to persistantly store/share the backup files
      - xstudio-volume-backup:/home/backup   
    command: crond -f -d 8
    restart: always     
      
      
      