services:
  nginx:
    image: nginx:alpine
    container_name: smartsolvin_nginx
    restart: unless-stopped
    ports:
      - "7771:80"
    volumes:
      - ./wp:/var/www/html
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php
    networks:
      - smartsolvin_network

  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: smartsolvin_php
    restart: unless-stopped
    volumes:
      - ./wp:/var/www/html
      - ./php/custom.ini:/usr/local/etc/php/conf.d/99-custom.ini:ro
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
    depends_on:
      db:
        condition: service_healthy
    networks:
      - smartsolvin_network

  db:
    image: mariadb:10.6
    container_name: smartsolvin_db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${WORDPRESS_DB_NAME}
      MYSQL_USER: ${WORDPRESS_DB_USER}
      MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql
      - ./backups:/backups
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - smartsolvin_network

  wpcli:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: smartsolvin_cli
    volumes:
      - ./wp:/var/www/html
    entrypoint: ["wp", "--allow-root"]
    working_dir: /var/www/html
    depends_on:
      db:
        condition: service_healthy
    networks:
      - smartsolvin_network 
    profiles:
      - cli

volumes:
  db_data:

networks:
  smartsolvin_network:
    driver: bridge