version: '3'

services:
  # WordPress (includes PHP and web server)
  wordpress:
    build: .
    volumes:
      - wordpress-data:/var/www/html
      - ./wp-content:/var/www/html/wp-content
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./api-key:/api-key
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: wppassword
      WORDPRESS_TABLE_PREFIX: wp_
    depends_on:
      - mysql
    networks:
      - app-network
      - elastic
    restart: unless-stopped

  # Nginx web server (front-end for WordPress)
  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - wordpress-data:/var/www/html
      - ./wp-content:/var/www/html/wp-content 
      - ./certbot/conf:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
    depends_on:
      - wordpress
    networks:
      - app-network
    restart: unless-stopped

  # WP-CLI container for WordPress management
  wp-cli:
    image: wordpress:cli-php8.2
    volumes:
      - wordpress-data:/var/www/html
      - ./wp-content:/var/www/html/wp-content
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./api-key:/api-key
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: wppassword
      WORDPRESS_TABLE_PREFIX: wp_
    depends_on:
      - wordpress
      - mysql
    networks:
      - app-network
    entrypoint: wp
    command: "--info"
    restart: "no"

  # MySQL database
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: wppassword
    volumes:
      - mysql-data:/var/lib/mysql
    networks:
      - app-network
    restart: unless-stopped

  # Certbot
  certbot:
    image: certbot/certbot
    volumes:
      - ./certbot/conf:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
    depends_on:
      - nginx
    command: certonly --webroot --webroot-path=/var/www/certbot --email steve@wojodesign.com --agree-tos --no-eff-email -d maxmarineelectronics.wojodesign.com

  # Portainer - Docker management UI
  portainer:
    image: portainer/portainer-ce:latest
    ports:
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer-data:/data
    restart: unless-stopped

networks:
  app-network:
  elastic:

volumes:
  mysql-data:
  portainer-data:
  wordpress-data:



