services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    platform: linux/arm64
    container_name: markatty_app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    environment:
      - DB_HOST=db
      - DB_PORT=3306
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD:-root}
    # So SEARCH_SUGGEST_BASE_URL=http://host.docker.internal:8080 reaches services bound on the host (e.g. vps-search).
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      - markatty-network
    depends_on:
      - db

  apache:
    image: httpd:2.4
    platform: linux/arm64
    container_name: markatty_apache
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html
      - ./docker/apache/000-default.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf
    networks:
      - markatty-network
    depends_on:
      - app
    command:
      - /bin/bash
      - -c
      - |
        echo 'Include conf/extra/httpd-vhosts.conf' >> /usr/local/apache2/conf/httpd.conf
        sed -i 's/#LoadModule proxy_module/LoadModule proxy_module/' /usr/local/apache2/conf/httpd.conf
        sed -i 's/#LoadModule proxy_fcgi_module/LoadModule proxy_fcgi_module/' /usr/local/apache2/conf/httpd.conf
        sed -i 's/#LoadModule rewrite_module modules\/mod_rewrite.so/LoadModule rewrite_module modules\/mod_rewrite.so/' /usr/local/apache2/conf/httpd.conf
        sed -i 's|#ServerName www.example.com:80|ServerName store.127.0.0.1.nip.io|' /usr/local/apache2/conf/httpd.conf
        sed -i 's|Require all denied|Require all granted|g' /usr/local/apache2/conf/httpd.conf
        sed -i 's|    DirectoryIndex index.html|    DirectoryIndex index.php index.html|' /usr/local/apache2/conf/httpd.conf
        echo '' >> /usr/local/apache2/conf/httpd.conf
        sed -i 's|AllowOverride None|AllowOverride All|g' /usr/local/apache2/conf/httpd.conf
        echo '<Directory "/var/www/html">' >> /usr/local/apache2/conf/httpd.conf
        echo '    Options Indexes FollowSymLinks' >> /usr/local/apache2/conf/httpd.conf
        echo '    AllowOverride All' >> /usr/local/apache2/conf/httpd.conf
        echo '    Require all granted' >> /usr/local/apache2/conf/httpd.conf
        echo '</Directory>' >> /usr/local/apache2/conf/httpd.conf
        httpd-foreground

  db:
    image: mysql:8.0
    platform: linux/arm64
    container_name: markatty_db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-markatty}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
      MYSQL_PASSWORD: ${DB_PASSWORD:-root}
      # Only set MYSQL_USER if DB_USERNAME is not "root"
      # MySQL doesn't allow creating a regular user named "root"
    ports:
      - "3306:3306"
    volumes:
      - dbdata:/var/lib/mysql
    command: --max-allowed-packet=256M --innodb-buffer-pool-size=512M --innodb-log-file-size=128M --log-bin-trust-function-creators=1 --skip-log-bin
    networks:
      - markatty-network

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:5.2
    platform: linux/amd64
    container_name: markatty_phpmyadmin
    restart: unless-stopped
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
      UPLOAD_LIMIT: 100M
    networks:
      - markatty-network
    depends_on:
      - db

networks:
  markatty-network:
    driver: bridge

volumes:
  dbdata:
    driver: local

