version: '3.4'

services:
  app:
    build: ./.docker/php
    container_name: "${COMPOSE_PROJECT_NAME}_app"
    restart: unless-stopped
    tty: true
    depends_on:
      - database
    volumes:
      - ./.docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
      - ./.docker/php/000-default.conf:/etc/apache2/sites-enabled/000-default.conf
      - ${APPSERVER_PUBLIC}:/var/www/html
    env_file:
      - .env
    labels:
      - "traefik.docker.network=${NETWORK}"
      - "traefik.enable=true"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${DOMAINS}`)"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.entrypoints=websecure"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.tls.certresolver=myresolver"
    networks:
      - default
      - web

  database:
    image: mariadb:latest
    container_name: "${COMPOSE_PROJECT_NAME}_database"
    restart: always
    env_file:
      - .env
    volumes:
      - db:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: "${COMPOSE_PROJECT_NAME}_phpmyadmin"
    restart: unless-stopped
    depends_on:
      - database
    environment:
      PMA_HOST: "${COMPOSE_PROJECT_NAME}_database"
    labels:
      - "traefik.docker.network=${NETWORK}"
      - "traefik.enable=true"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}-db.rule=Host(`db.${BASE_DOMAIN}`)"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}-db.entrypoints=websecure"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}-db.tls.certresolver=myresolver"
    networks:
      - default
      - web

  wpcli:
    image: wordpress:cli
    container_name: "${COMPOSE_PROJECT_NAME}_wpcli"
    volumes:
      - ./.docker/php/local.ini:/usr/local/etc/php/conf.d/conf.ini
      - ${APPSERVER_PUBLIC}:/var/www/html
    depends_on:
      - database
      - app

  mailhog:
    image: mailhog/mailhog
    container_name: "${COMPOSE_PROJECT_NAME}_mailhog"
    labels:
      - "traefik.docker.network=${NETWORK}"
      - "traefik.enable=true"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}-mailhog.rule=Host(`mailhog.${BASE_DOMAIN}`)"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}-mailhog.entrypoints=websecure"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}-mailhog.tls.certresolver=myresolver"
      - "traefik.http.services.${COMPOSE_PROJECT_NAME}-mailhog.loadbalancer.server.port=8025"
    networks:
      - default
      - web

volumes:
  db:
    name: "${COMPOSE_PROJECT_NAME}_db"
    external: false

networks:
  web:
    external:
       name: ${NETWORK}
  default:
    driver: bridge
