
version: '3'

services:
  db:
    image: mariadb:10.5.6
    container_name: mariaDB
    logging:
      driver: "json-file"
      options:
        max-size: "5m"
        max-file: "3"
    restart: always
    environment:
      - PUID=1000
      - PGID=1000
    networks:
      - backend
    volumes:
      - ${DIR}/database:/var/lib/mysql:rw
    ports:
      - "3307:3306"
    labels:
      - diun.enable=true
      - "traefik.enable=false"
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USERNAME}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}

  web_db:
    image: adminer
    container_name: adminer
    logging:
      driver: "json-file"
      options:
        max-size: "5m"
        max-file: "3"
    restart: always
    networks:
      - backend
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      - "traefik.http.middlewares.webdb-mid.ipallowlist.sourcerange=127.0.0.1/32, 10.0.0.1/24"
      - "traefik.http.routers.webdb-secure.middlewares=webdb-mid"
      - "traefik.http.routers.webdb-secure.entrypoints=web-secure"
      - "traefik.http.routers.webdb-secure.rule=Host(`webdb.${DOMAIN}`)"
      - "traefik.http.routers.webdb-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.webdb-secure.tls=true"
      - "traefik.http.services.webdb-service.loadbalancer.server.port=8080"
    depends_on:
      - db
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USERNAME}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - PMA_ARBITRARY=1

  postgres:
    image: postgres:13.6
    container_name: postgres
    logging:
      driver: "json-file"
      options:
        max-size: "5m"
        max-file: "3"
    restart: always
    environment:
      - PUID=1000
      - PGID=1000
    networks:
      - backend
    volumes:
      - ${DIR}/database_pg/data:/var/lib/postgresql/data
    labels:
      - diun.enable=true
      - "traefik.enable=false"
    environment:
      - TZ=${TZ}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}


  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4
    logging:
      driver: "json-file"
      options:
        max-size: "5m"
        max-file: "3"
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
    volumes:
      - ${DIR}/database_pg/pgadmin:/root/.pgadmin
    networks:
      - backend
    restart: unless-stopped
    depends_on:
      - postgres
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      #      - "traefik.http.middlewares.webpg-mid.ipwhitelist.sourcerange=127.0.0.1/32, 10.0.0.1/24"
      #- "traefik.http.routers.webpg-secure.middlewares=webpg-mid"
      - "traefik.http.routers.webpg-secure.entrypoints=web-secure"
      - "traefik.http.routers.webpg-secure.rule=Host(`webpg.${DOMAIN}`)"
      - "traefik.http.routers.webpg-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.webpg-secure.tls=true"
      #- "traefik.http.services.webpg-service.loadbalancer.server.port=8080"

  redis:
    image: redis:7.0-alpine
    container_name: redis
    logging:
      driver: "json-file"
      options:
        max-size: "5m"
        max-file: "3"
    restart: always
    networks:
      - backend
    volumes:
        - ${DIR}/redis:/var/lib/redis
        #entrypoint: redis-server --appendonly yes --requirepass $REDIS_PASSWORD --maxmemory 512mb --maxmemory-policy allkeys-lru
    labels:
      - diun.enable=true

networks:
  frontend:
    external: true
  backend:
    external: false

