version: "3.3"
    
services:
  db:
    image: mysql:5.7
    container_name: mysqlwordpressContainer${USER_ID:-1}
    volumes:
      - mysqlwordpress:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wordpress-network

  cli:
    build:
      context: .
      dockerfile: ./Dockerfile   
    environment:
      WORDPRESS_DB_HOST: mysqlwordpressContainer${USER_ID:-1}:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_URL: ${URL_WORDPRESS}
      WORDPRESS_USER : admin
      WORDPRESS_PWD : admin
      WORDPRESS_MAIL : admin@admin.fr 
    restart: always
    depends_on:
      - db
    volumes: 
      - datawordpress:/var/www/html
    networks:
      - wordpress-network
      - traefik-proxy
    
    
  wordpress:
    image: wordpress:latest
    depends_on:
      - db
      - cli
    volumes:
      - datawordpress:/var/www/html
    logging:
      options:
        max-size: '12m'
        max-file: '5'
      driver: json-file
    labels:
      - traefik.enable=true
      - traefik.http.routers.wordpress${USER_ID:-1}.rule=Host(`${URL_WORDPRESS}`)
      - traefik.http.routers.wordpress${USER_ID:-1}.entrypoints=websecure
      - traefik.http.routers.wordpress${USER_ID:-1}.tls=true
      - traefik.http.routers.wordpress${USER_ID:-1}.tls.certresolver=lets-encrypt
      - traefik.http.services.wordpress${USER_ID:-1}.loadbalancer.server.port=80
      - traefik.docker.network=${NETWORK_TRAEFIK}
    restart: always
    environment:
      WORDPRESS_DB_HOST: mysqlwordpressContainer${USER_ID:-1}:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_URL: ${URL_WORDPRESS}
      WORDPRESS_USER : admin
      WORDPRESS_PWD : admin
      WORDPRESS_MAIL : admin@admin.fr
    networks:
      - traefik-proxy
      - wordpress-network

networks:
  traefik-proxy:
    external:
      name: ${NETWORK_TRAEFIK}
  wordpress-network:
    internal: true

volumes:
 mysqlwordpress:
    driver: local
    driver_opts:
      type: none
      device: ${VOLUME_MYSQL_WORDPRESS}
      o: bind

 datawordpress:
    driver: local
    driver_opts:
      type: none
      device: ${VOLUME_DATA_WORDPRESS}
      o: bind
