# Run docker compose from the top-level WebCalendar directory and not from this "docker" subdirectory.
#   If you need shell access on the webserver container running WebCalendar, you can use
#   the following command:
#     docker compose -f docker/docker-compose-php8-dev.yml exec webcalendar-php8-mariadb /bin/sh

version: '3.1'

services:

  db-mariadb:
    image: mariadb
    container_name: webcalendar-maria-db
    volumes:
      - mysql-data:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
      # install sql at start
      # To test the installer's built-in installer, comment this out
#      - type: bind
#        source: ../install/sql/tables-mysql.sql
#        target: /docker-entrypoint-initdb.d/tables-mysql.sql
      # Set mariadb access policy
      # NOTE: The specified SQL needs to match the password specified
      #       in the ENV vars listed below.
      - type: bind
        source: ../install/sql/permissions-mysql.sql
        target: /docker-entrypoint-initdb.d/permissions-mysql.sql
    environment:
      - MYSQL_ROOT_PASSWORD=Webcalendar.1
      - MYSQL_PASSWORD=Webcalendar.1
      - MYSQL_DATABASE=webcalendar_php8
      - MYSQL_USER=webcalendar
    restart: unless-stopped

  webcalendar-php8-mariadb:
    build:
      context: ../
      dockerfile: docker/Dockerfile-php8-dev
    depends_on:
      - db-mariadb
    ports:
      - 8080:80
    volumes:
      - ..:/var/www/html/
    # You can use env vars instead of putting the details in includes/settings.php.  If WebCalendar
    # sees WEBCALENDAR_USE_ENV is set to true, it will use these env vars and ignore settings.php.
    # The install password below is "Webcalendar.1" (and you should change it).
    # Use the following to generate your password hash (replace "Webcalendar.1" with your password):
    # php -r "echo md5('Webcalendar.1');"
    environment:
      - WEBCALENDAR_USE_ENV=true
      - WEBCALENDAR_INSTALL_PASSWORD=da1437a2c74ee0b35eed71e27d00c618
      - WEBCALENDAR_DB_TYPE=mysqli
      - WEBCALENDAR_DB_DATABASE=webcalendar_php8
      - WEBCALENDAR_DB_LOGIN=webcalendar
      - WEBCALENDAR_DB_PASSWORD=Webcalendar.1
      - WEBCALENDAR_DB_HOST=db-mariadb
      - WEBCALENDAR_DB_PERSISTENT=true
      - WEBCALENDAR_USER_INC=user.php
      - WEBCALENDAR_MODE=dev

  webcalendar-php8-pgsql:
    build:
      context: ../
      dockerfile: docker/Dockerfile-php8-dev
    depends_on:
      - db-pgsql
    ports:
      - 8081:80
    volumes:
      - ..:/var/www/html/
    environment:
      - WEBCALENDAR_USE_ENV=true
      - WEBCALENDAR_INSTALL_PASSWORD=da1437a2c74ee0b35eed71e27d00c618
      - WEBCALENDAR_DB_TYPE=postgresql
      - WEBCALENDAR_DB_DATABASE=webcalendar_php81
      - WEBCALENDAR_DB_LOGIN=webcalendar
      - WEBCALENDAR_DB_PASSWORD=Webcalendar.1 # Change this
      - WEBCALENDAR_DB_HOST=db-pgsql
      - WEBCALENDAR_DB_PERSISTENT=true
      - WEBCALENDAR_USER_INC=user.php
      - WEBCALENDAR_MODE=dev

  # To access the pgsql command line:
  # docker compose -f docker/docker-compose-php8-dev.yml exec db-pgsql /bin/bash
  # Before the webcalendar db is created:
  #   psql -h localhost -p 5432 -U webcalendar -W -d postgres
  db-pgsql:
    image: postgres
    container_name: webcalendar-db-pgsql
    volumes:
      - pgsql-data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - POSTGRES_DB=webcalendar_php81
      - POSTGRES_USER=webcalendar
      - POSTGRES_PASSWORD=Webcalendar.1 # Change this
    restart: unless-stopped

volumes:
  mysql-data: # MySQL/Maria data volume for persistence
  pgsql-data: # PostgreSQL data volume for persistence
