services:
  app:
    build:
      context: ./docker/php
    restart: unless-stopped
    env_file:
      - .env
    environment:
      TZ: ${TZ}
      MIDAS_DB_HOST: db
      MIDAS_DB_NAME: ${MARIADB_DATABASE}
      MIDAS_DB_USER: ${MARIADB_USER}
      MIDAS_DB_PASS: ${MARIADB_PASSWORD}
      MIDAS_SITE_URL: ${SITE_URL}
      MIDAS_API_KEY_FRONTEND: ${API_KEY_FRONTEND}
    volumes:
      - ${MIDAS_CODE_PATH}:/var/www/html
    labels:
      - traefik.enable=true
      - traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${APP_HOST}`)
      - traefik.http.routers.${COMPOSE_PROJECT_NAME}.entrypoints=websecure
      - traefik.http.routers.${COMPOSE_PROJECT_NAME}.tls.certresolver=letsencrypt
      - traefik.http.services.${COMPOSE_PROJECT_NAME}.loadbalancer.server.port=${APP_PORT}

  db:
    image: mariadb:11.4
    restart: unless-stopped
    env_file:
      - .env
    environment:
      TZ: ${TZ}
      MARIADB_DATABASE: ${MARIADB_DATABASE}
      MARIADB_USER: ${MARIADB_USER}
      MARIADB_PASSWORD: ${MARIADB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --innodb-flush-log-at-trx-commit=1
      - --max-connections=100
    volumes:
      - mariadb_data:/var/lib/mysql

volumes:
  mariadb_data:
