diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c9b1c8c..7900715 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -20,12 +20,14 @@ on: inputs: mybb_version: description: 'MyBB version to build (e.g., 1839)' - required: false + required: true default: '1839' env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + # Latest MyBB version - update this when new MyBB versions are released + LATEST_MYBB_VERSION: '1839' jobs: build-and-push: @@ -73,11 +75,12 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - MYBB_VERSION=${{ github.event.inputs.mybb_version || '1839' }} + MYBB_VERSION=${{ github.event.inputs.mybb_version || env.LATEST_MYBB_VERSION }} cache-from: type=gha cache-to: type=gha,mode=max - # Build multiple MyBB versions on release + # Build images for the 2 latest MyBB versions on release + # Update this matrix when new MyBB versions are released build-versions: if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest @@ -86,7 +89,9 @@ jobs: packages: write strategy: matrix: - mybb_version: ['1836', '1837', '1838', '1839'] + # Only the 2 latest MyBB versions are built to reduce maintenance burden + # Update these versions when new MyBB releases come out + mybb_version: ['1838', '1839'] steps: - name: Checkout repository diff --git a/Dockerfile b/Dockerfile index b58a17e..76ca8ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,19 @@ FROM php:8.2-apache # OCI Labels for GitHub Container Registry LABEL org.opencontainers.image.source="https://github.com/visualcookie/mybb" -LABEL org.opencontainers.image.description="MyBB Forum Software - Flexible Docker image supporting any MyBB version" +LABEL org.opencontainers.image.description="MyBB Forum Software - Pre-built Docker image with MyBB included" LABEL org.opencontainers.image.licenses="MIT" LABEL org.opencontainers.image.title="MyBB Docker" LABEL org.opencontainers.image.vendor="visualcookie" -# Build argument for MyBB version (can be overridden at build time) -ARG MYBB_VERSION=1839 +# Build argument for MyBB version (REQUIRED at build time) +ARG MYBB_VERSION # Environment variables ENV MYBB_VERSION=${MYBB_VERSION} ENV APACHE_DOCUMENT_ROOT=/var/www/html +# Directory where MyBB is pre-installed at build time +ENV MYBB_SOURCE_DIR=/opt/mybb-source # Install system dependencies RUN apt-get update && apt-get install -y \ @@ -25,6 +27,7 @@ RUN apt-get update && apt-get install -y \ unzip \ curl \ wget \ + rsync \ && rm -rf /var/lib/apt/lists/* # Configure and install PHP extensions required by MyBB @@ -61,6 +64,29 @@ RUN { \ echo 'opcache.fast_shutdown=1'; \ } > /usr/local/etc/php/conf.d/opcache-recommended.ini +# Download and install MyBB at build time (not runtime) +# This ensures the image contains a specific MyBB version and eliminates runtime download risks +RUN set -eux; \ + if [ -z "${MYBB_VERSION}" ]; then \ + echo "ERROR: MYBB_VERSION build argument is required"; \ + exit 1; \ + fi; \ + mkdir -p ${MYBB_SOURCE_DIR}; \ + echo "Downloading MyBB version ${MYBB_VERSION}..."; \ + wget -q -O /tmp/mybb.zip "https://github.com/mybb/mybb/releases/download/mybb_${MYBB_VERSION}/mybb_${MYBB_VERSION}.zip" \ + || wget -q -O /tmp/mybb.zip "https://resources.mybb.com/downloads/mybb_${MYBB_VERSION}.zip"; \ + unzip -q /tmp/mybb.zip -d /tmp/mybb_extract; \ + if [ -d "/tmp/mybb_extract/Upload" ]; then \ + cp -r /tmp/mybb_extract/Upload/* ${MYBB_SOURCE_DIR}/; \ + elif [ -d "/tmp/mybb_extract/upload" ]; then \ + cp -r /tmp/mybb_extract/upload/* ${MYBB_SOURCE_DIR}/; \ + else \ + cp -r /tmp/mybb_extract/*/* ${MYBB_SOURCE_DIR}/ 2>/dev/null || cp -r /tmp/mybb_extract/* ${MYBB_SOURCE_DIR}/; \ + fi; \ + rm -rf /tmp/mybb.zip /tmp/mybb_extract; \ + echo "MyBB ${MYBB_VERSION} installed to ${MYBB_SOURCE_DIR}"; \ + echo "${MYBB_VERSION}" > ${MYBB_SOURCE_DIR}/.mybb_version + # Set working directory WORKDIR /var/www/html @@ -75,7 +101,8 @@ RUN mkdir -p /var/www/html/uploads \ /var/www/html/admin/backups # Set proper permissions -RUN chown -R www-data:www-data /var/www/html +RUN chown -R www-data:www-data /var/www/html \ + && chown -R www-data:www-data ${MYBB_SOURCE_DIR} # Expose port 80 EXPOSE 80 diff --git a/README.md b/README.md index 79b30ba..578b849 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,16 @@ ![GitHub License](https://img.shields.io/github/license/visualcookie/mybb?style=for-the-badge) ![GHCR](https://img.shields.io/badge/ghcr.io-visualcookie%2Fmybb-blue?style=for-the-badge&logo=docker) ![Assisted Using Claude](https://img.shields.io/badge/Claude-D97757?style=for-the-badge&logo=claude&logoColor=white) -A flexible Docker image for [MyBB](https://mybb.com/) forum software that supports any version of MyBB. +A Docker image for [MyBB](https://mybb.com/) forum software with MyBB baked into the image at build time. ## Features - 🐳 Easy deployment with Docker or Docker Compose -- 🔄 Support for any MyBB version (configurable) +- 📦 MyBB pre-installed in the image (no runtime downloads) - 💾 Persistent data storage with Docker volumes - 🔒 Secure default configuration - 🚀 Optimized PHP configuration for MyBB -- ⬆️ Safe upgrade mode preserving configs, uploads, themes, and plugins +- ⬆️ Automatic file sync preserving existing configs on upgrade - ❤️ Health checks for container orchestration - 📂 Optional SFTP server for file management (themes, plugins, updates) - 📦 Optional phpMyAdmin for database management @@ -29,7 +29,7 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo 1. **Build the image:** ```bash - docker build -t mybb . + docker build --build-arg MYBB_VERSION=1839 -t mybb . ``` 2. **Create a network:** @@ -56,7 +56,6 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo --name mybb-forum \ --network mybb-network \ -p 8080:80 \ - -e MYBB_VERSION=1839 \ -e DB_HOST=mybb-db \ -e DB_USER=mybb \ -e DB_PASSWORD=mybb_password \ @@ -84,28 +83,30 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo | Variable | Description | Default | |----------|-------------|---------| -| `MYBB_VERSION` | MyBB version number (e.g., 1839) | `1839` | +| `MYBB_VERSION` | MyBB version (build argument) | `1839` | | `MYBB_PORT` | Web server port | `8080` | | `DB_HOST` | Database hostname | - | | `DB_PORT` | Database port | `3306` | | `DB_USER` | Database username | `root` | | `DB_PASSWORD` | Database password | - | | `DB_NAME` | Database name | `mybb` | -| `FORCE_REINSTALL` | Force reinstall MyBB | `false` | -| `SFTP_PORT` | SFTP server port | `2222` | -| `SFTP_USER` | SFTP username | `mybb` | -| `SFTP_PASSWORD` | SFTP password | `mybb_sftp_pass` | -| `PMA_PORT` | phpMyAdmin port | `8081` | | `TZ` | Timezone | `UTC` | -| `UPGRADE_MODE` | Enable safe upgrade mode | `false` | -| `PRESERVE_PLUGINS` | Keep plugins during upgrade | `true` | -| `PRESERVE_THEMES` | Keep themes during upgrade | `true` | ### MyBB Versions -You can use any MyBB version by setting `MYBB_VERSION` in your `.env` file. The version is downloaded at container startup. +MyBB is baked into the image at build time. Pre-built images are available for the 2 latest versions: + +```bash +docker pull ghcr.io/visualcookie/mybb:latest # 1839 +docker pull ghcr.io/visualcookie/mybb:1839 +docker pull ghcr.io/visualcookie/mybb:1838 +``` + +To build a different version locally: -Find all available versions at: https://github.com/mybb/mybb/releases +```bash +docker build --build-arg MYBB_VERSION=1837 -t mybb:1837 . +``` ## Volumes @@ -215,97 +216,25 @@ After starting the containers, complete the MyBB setup: docker exec mybb-forum rm -rf /var/www/html/install ``` -## Upgrading MyBB (Safe Upgrade Mode) - -This image includes a **safe upgrade mode** that preserves your configuration, uploads, themes, and plugins while updating MyBB core files. - -### Quick Upgrade Steps - -1. **Edit `.env`** - Set the new version and enable upgrade mode: - ```bash - MYBB_VERSION=1839 - UPGRADE_MODE=true - ``` - -2. **Rebuild and restart:** - ```bash - docker compose down - docker compose build --no-cache - docker compose up -d - ``` +## Upgrading MyBB -3. **Complete the upgrade:** - - Visit `http://localhost:8080/install/upgrade.php` - - Follow the upgrade wizard (this migrates your database) - -4. **Cleanup:** - ```bash - # Remove the install folder - docker exec mybb-forum rm -rf /var/www/html/install - - # Remove the upgrade reminder file - docker exec mybb-forum rm -f /var/www/html/UPGRADE_IN_PROGRESS.txt - - # Disable upgrade mode in .env - # UPGRADE_MODE=false (or remove the line) - ``` - -### What Gets Preserved - -| Item | Preserved | Notes | -|------|-----------|-------| -| `inc/config.php` | ✅ Always | Database configuration | -| `inc/settings.php` | ✅ Always | Forum settings | -| `uploads/` | ✅ Always | User avatars, attachments | -| `inc/plugins/` | ✅ Default | Set `PRESERVE_PLUGINS=false` to reset | -| `images/` | ✅ Default | Set `PRESERVE_THEMES=false` to reset | -| `inc/languages/` | ✅ Always | Language customizations | - -### What Gets Updated - -- All core PHP files -- JavaScript files -- Default images/icons -- Install/upgrade scripts - -### Upgrade Environment Variables - -| Variable | Description | Default | -|----------|-------------|---------| -| `UPGRADE_MODE` | Enable safe upgrade mode | `false` | -| `PRESERVE_PLUGINS` | Keep existing plugins | `true` | -| `PRESERVE_THEMES` | Keep existing themes | `true` | - -### Automatic Backups - -Before upgrading, the script automatically backs up critical files to `/var/www/html/admin/backups/`: -- `pre_upgrade_TIMESTAMP_config.php` -- `pre_upgrade_TIMESTAMP_settings.php` -- `pre_upgrade_TIMESTAMP_plugins_list.txt` -- `pre_upgrade_TIMESTAMP_themes_list.txt` - -### Manual Backup (Recommended) - -For extra safety, create a full backup before upgrading: +To upgrade, pull/build a new image and restart. The entrypoint syncs new files while preserving existing ones (config, uploads, plugins, themes). ```bash -# Backup files -docker exec mybb-forum tar -czvf /tmp/mybb-backup.tar.gz /var/www/html -docker cp mybb-forum:/tmp/mybb-backup.tar.gz ./mybb-backup.tar.gz +# Update image tag in docker-compose.ghcr.yml, then: +docker compose down && docker compose pull && docker compose up -d -# Backup database -docker exec mybb-database mysqldump -u mybb -p mybb > mybb-database-backup.sql +# Or rebuild locally with new version: +docker compose down +docker compose build --build-arg MYBB_VERSION=1840 +docker compose up -d ``` -### Alternative: Manual Upgrade via SFTP +After restart, visit `/install/upgrade.php` if MyBB requires database migrations, then delete the install folder: -If you prefer manual control, use SFTP: - -1. Download new MyBB from [mybb.com](https://mybb.com/download/) -2. Connect via SFTP (see SFTP section above) -3. Upload new files, but **skip** `inc/config.php` -4. Visit `/install/upgrade.php` -5. Delete the install folder +```bash +docker exec mybb-forum rm -rf /var/www/html/install +``` ## Troubleshooting @@ -331,14 +260,6 @@ docker exec mybb-forum chmod -R 777 /var/www/html/uploads /var/www/html/cache - Verify credentials in `.env` match the installation wizard inputs - Check if the network is properly configured -### Force reinstall MyBB -```bash -docker run -d \ - --name mybb-forum \ - -e FORCE_REINSTALL=true \ - ... -``` - ## Security Recommendations 1. **Change default passwords** in `.env` (database, SFTP) diff --git a/docker-compose.ghcr.yml b/docker-compose.ghcr.yml index f83b2b5..1d3910e 100644 --- a/docker-compose.ghcr.yml +++ b/docker-compose.ghcr.yml @@ -1,6 +1,3 @@ -# Docker Compose file using pre-built image from GitHub Container Registry -# Usage: docker compose -f docker-compose.ghcr.yml up -d - services: mybb: image: ghcr.io/visualcookie/mybb:${MYBB_TAG:-latest} @@ -9,17 +6,12 @@ services: ports: - "${MYBB_PORT:-8080}:80" environment: - - MYBB_VERSION=${MYBB_VERSION:-1839} - DB_HOST=mybb-db - DB_PORT=3306 - DB_USER=${MYSQL_USER:-mybb} - DB_PASSWORD=${MYSQL_PASSWORD:-mybb_password} - DB_NAME=${MYSQL_DATABASE:-mybb} - TZ=${TZ:-UTC} - # Upgrade mode options - - UPGRADE_MODE=${UPGRADE_MODE:-false} - - PRESERVE_PLUGINS=${PRESERVE_PLUGINS:-true} - - PRESERVE_THEMES=${PRESERVE_THEMES:-true} volumes: - mybb_data:/var/www/html depends_on: diff --git a/docker-compose.yml b/docker-compose.yml index eafc8ed..5d2d32b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,17 +10,12 @@ services: ports: - "${MYBB_PORT:-8080}:80" environment: - - MYBB_VERSION=${MYBB_VERSION:-1839} - DB_HOST=mybb-db - DB_PORT=3306 - DB_USER=${MYSQL_USER:-mybb} - DB_PASSWORD=${MYSQL_PASSWORD:-mybb_password} - DB_NAME=${MYSQL_DATABASE:-mybb} - TZ=${TZ:-UTC} - # Upgrade mode options - - UPGRADE_MODE=${UPGRADE_MODE:-false} - - PRESERVE_PLUGINS=${PRESERVE_PLUGINS:-true} - - PRESERVE_THEMES=${PRESERVE_THEMES:-true} volumes: # Main webroot volume (shared with SFTP) - mybb_data:/var/www/html diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index abad48c..5644b2d 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,388 +5,102 @@ set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color +NC='\033[0m' -log_info() { - echo -e "${GREEN}[INFO]${NC} $1" -} - -log_warn() { - echo -e "${YELLOW}[WARN]${NC} $1" -} +MYBB_SOURCE="/opt/mybb-source" -log_error() { - echo -e "${RED}[ERROR]${NC} $1" -} +log_info() { echo -e "${GREEN}[INFO]${NC} $1"; } +log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } +log_error() { echo -e "${RED}[ERROR]${NC} $1"; } -log_important() { - echo -e "${BLUE}[IMPORTANT]${NC} $1" +get_image_version() { + cat "${MYBB_SOURCE}/.mybb_version" 2>/dev/null || echo "unknown" } -# Function to download MyBB -download_mybb() { - local version=$1 - local download_url="https://github.com/mybb/mybb/releases/download/mybb_${version}/mybb_${version}.zip" - - log_info "Downloading MyBB version ${version}..." - - # Download MyBB - if ! wget -q --show-progress -O /tmp/mybb.zip "$download_url"; then - log_error "Failed to download MyBB version ${version}" - log_info "Trying alternative URL format..." - - # Try alternative URL format (some versions use different naming) - download_url="https://resources.mybb.com/downloads/mybb_${version}.zip" - if ! wget -q --show-progress -O /tmp/mybb.zip "$download_url"; then - log_error "Failed to download MyBB. Please check if version ${version} exists." - log_info "Available versions: https://github.com/mybb/mybb/releases" - return 1 - fi - fi - - return 0 -} +# Sync MyBB files from image to volume +# By default, skip files that already exist (preserves user configs) +sync_mybb() { + local skip_existing="$1" + local version=$(get_image_version) -# Function to extract MyBB to a target directory -extract_mybb() { - local target_dir=$1 - - log_info "Extracting MyBB..." - - # Extract to temporary directory - rm -rf /tmp/mybb_extract - unzip -q /tmp/mybb.zip -d /tmp/mybb_extract - - # Find the Upload directory (MyBB packages contain Upload folder) - if [ -d "/tmp/mybb_extract/Upload" ]; then - cp -r /tmp/mybb_extract/Upload/* "$target_dir/" - elif [ -d "/tmp/mybb_extract/upload" ]; then - cp -r /tmp/mybb_extract/upload/* "$target_dir/" - else - # Some versions might extract directly - cp -r /tmp/mybb_extract/*/* "$target_dir/" 2>/dev/null || cp -r /tmp/mybb_extract/* "$target_dir/" + if [ ! -d "${MYBB_SOURCE}" ]; then + log_error "MyBB source not found in image" + return 1 fi - - # Cleanup - rm -rf /tmp/mybb.zip /tmp/mybb_extract - - log_info "MyBB extracted successfully" -} -# Function to install MyBB (fresh install) -install_mybb() { - extract_mybb "/var/www/html" -} + log_info "Syncing MyBB ${version} to volume..." -# Function to create backup before upgrade -create_backup() { - local backup_dir="/var/www/html/admin/backups" - local timestamp=$(date +%Y%m%d_%H%M%S) - local backup_name="pre_upgrade_${timestamp}" - - log_info "Creating backup before upgrade..." - - mkdir -p "$backup_dir" - - # Backup critical configuration files - if [ -f /var/www/html/inc/config.php ]; then - cp /var/www/html/inc/config.php "$backup_dir/${backup_name}_config.php" - log_info "Backed up: config.php" - fi - - if [ -f /var/www/html/inc/settings.php ]; then - cp /var/www/html/inc/settings.php "$backup_dir/${backup_name}_settings.php" - log_info "Backed up: settings.php" - fi - - # Create a list of installed plugins - if [ -d /var/www/html/inc/plugins ]; then - ls -1 /var/www/html/inc/plugins/ > "$backup_dir/${backup_name}_plugins_list.txt" 2>/dev/null || true - log_info "Backed up: plugins list" - fi - - # Backup custom themes list - if [ -d /var/www/html/images ]; then - ls -1 /var/www/html/images/ > "$backup_dir/${backup_name}_themes_list.txt" 2>/dev/null || true - log_info "Backed up: themes list" - fi - - # Store current version info if available - if [ -f /var/www/html/inc/class_core.php ]; then - grep -o "public \$version = '[^']*'" /var/www/html/inc/class_core.php > "$backup_dir/${backup_name}_version.txt" 2>/dev/null || true + if [ "$skip_existing" = "true" ]; then + # Copy only new files, don't overwrite existing (upgrade-safe) + rsync -a --ignore-existing "${MYBB_SOURCE}/" /var/www/html/ + log_info "Synced new files (preserved existing)" + else + # Fresh install - copy everything + rsync -a "${MYBB_SOURCE}/" /var/www/html/ + log_info "Synced all files" fi - - log_info "Backup created in: $backup_dir" - echo "$backup_dir/${backup_name}" > /tmp/last_backup_path -} -# Function to perform safe upgrade -upgrade_mybb() { - local target_version=$1 - - log_info "==========================================" - log_info " MyBB SAFE UPGRADE MODE" - log_info "==========================================" - log_info "Target version: ${target_version}" - - # Check if MyBB is actually installed - if [ ! -f /var/www/html/inc/config.php ]; then - log_error "No existing MyBB installation found!" - log_error "Cannot upgrade - config.php is missing." - log_error "Use normal install mode instead (remove UPGRADE_MODE)." - return 1 - fi - - # Check if config.php has database settings (not empty template) - if ! grep -q "database" /var/www/html/inc/config.php 2>/dev/null; then - log_error "config.php appears to be empty or unconfigured." - log_error "Cannot upgrade an unconfigured installation." - return 1 - fi - - # Step 1: Create backup - log_info "" - log_info "Step 1/5: Creating backup..." - create_backup - - # Step 2: Save files that must be preserved - log_info "" - log_info "Step 2/5: Preserving critical files..." - - mkdir -p /tmp/mybb_preserve - - # Preserve config.php (CRITICAL - contains database settings) - cp /var/www/html/inc/config.php /tmp/mybb_preserve/config.php - log_info "Preserved: inc/config.php" - - # Preserve settings.php if it exists - if [ -f /var/www/html/inc/settings.php ]; then - cp /var/www/html/inc/settings.php /tmp/mybb_preserve/settings.php - log_info "Preserved: inc/settings.php" - fi - - # Preserve uploads directory (user avatars, attachments) - if [ -d /var/www/html/uploads ]; then - cp -r /var/www/html/uploads /tmp/mybb_preserve/uploads - log_info "Preserved: uploads/ directory" - fi - - # Preserve custom plugins (optional - admin may want fresh plugins) - if [ "${PRESERVE_PLUGINS:-true}" = "true" ] && [ -d /var/www/html/inc/plugins ]; then - cp -r /var/www/html/inc/plugins /tmp/mybb_preserve/plugins - log_info "Preserved: inc/plugins/ directory" - fi - - # Preserve custom themes/images - if [ "${PRESERVE_THEMES:-true}" = "true" ] && [ -d /var/www/html/images ]; then - cp -r /var/www/html/images /tmp/mybb_preserve/images - log_info "Preserved: images/ directory" - fi - - # Preserve language customizations - if [ -d /var/www/html/inc/languages ]; then - cp -r /var/www/html/inc/languages /tmp/mybb_preserve/languages - log_info "Preserved: inc/languages/ directory" - fi - - # Step 3: Download new version - log_info "" - log_info "Step 3/5: Downloading MyBB ${target_version}..." - if ! download_mybb "${target_version}"; then - log_error "Download failed! Aborting upgrade." - log_info "Your current installation is unchanged." - rm -rf /tmp/mybb_preserve - return 1 - fi - - # Step 4: Extract new version (overwrite core files) - log_info "" - log_info "Step 4/5: Installing new version..." - extract_mybb "/var/www/html" - - # Step 5: Restore preserved files - log_info "" - log_info "Step 5/5: Restoring preserved files..." - - # Restore config.php (CRITICAL) - cp /tmp/mybb_preserve/config.php /var/www/html/inc/config.php - log_info "Restored: inc/config.php" - - # Restore settings.php - if [ -f /tmp/mybb_preserve/settings.php ]; then - cp /tmp/mybb_preserve/settings.php /var/www/html/inc/settings.php - log_info "Restored: inc/settings.php" - fi - - # Restore uploads - if [ -d /tmp/mybb_preserve/uploads ]; then - rm -rf /var/www/html/uploads - cp -r /tmp/mybb_preserve/uploads /var/www/html/uploads - log_info "Restored: uploads/ directory" - fi - - # Restore plugins if preserved - if [ -d /tmp/mybb_preserve/plugins ]; then - # Merge plugins - keep new core plugins, restore custom ones - cp -rn /tmp/mybb_preserve/plugins/* /var/www/html/inc/plugins/ 2>/dev/null || true - log_info "Restored: custom plugins" - fi - - # Restore themes/images if preserved - if [ -d /tmp/mybb_preserve/images ]; then - # Merge - keep new default images, restore custom themes - cp -rn /tmp/mybb_preserve/images/* /var/www/html/images/ 2>/dev/null || true - log_info "Restored: custom themes/images" - fi - - # Restore languages - if [ -d /tmp/mybb_preserve/languages ]; then - cp -rn /tmp/mybb_preserve/languages/* /var/www/html/inc/languages/ 2>/dev/null || true - log_info "Restored: language files" - fi - - # Cleanup - rm -rf /tmp/mybb_preserve - - # Set permissions - set_permissions - - # Success message - log_info "" - log_info "==========================================" - log_info " UPGRADE FILES INSTALLED SUCCESSFULLY" - log_info "==========================================" - log_important "" - log_important "╔════════════════════════════════════════════════════════════╗" - log_important "║ ACTION REQUIRED: Complete the upgrade! ║" - log_important "╠════════════════════════════════════════════════════════════╣" - log_important "║ ║" - log_important "║ 1. Visit: http://your-server/install/upgrade.php ║" - log_important "║ 2. Follow the upgrade wizard ║" - log_important "║ 3. Delete install folder when complete: ║" - log_important "║ docker exec mybb-forum rm -rf /var/www/html/install ║" - log_important "║ ║" - log_important "╚════════════════════════════════════════════════════════════╝" - log_important "" - - # Remove the installer lock file so upgrade wizard can run - if [ -f /var/www/html/install/lock ]; then - rm -f /var/www/html/install/lock - log_info "Removed install/lock file for upgrade wizard" - fi - - # Create a flag file to remind about upgrade - echo "Upgrade to version ${target_version} started at $(date)" > /var/www/html/UPGRADE_IN_PROGRESS.txt - echo "Visit /install/upgrade.php to complete the upgrade" >> /var/www/html/UPGRADE_IN_PROGRESS.txt - echo "Delete this file after completing the upgrade" >> /var/www/html/UPGRADE_IN_PROGRESS.txt - - return 0 + echo "${version}" > /var/www/html/.mybb_version } -# Function to set permissions set_permissions() { - log_info "Setting file permissions..." - - # Set ownership chown -R www-data:www-data /var/www/html - - # Set directory permissions find /var/www/html -type d -exec chmod 755 {} \; - - # Set file permissions find /var/www/html -type f -exec chmod 644 {} \; - - # Make specific directories writable (required by MyBB) + + # MyBB requires these to be writable chmod -R 777 /var/www/html/cache 2>/dev/null || true chmod -R 777 /var/www/html/uploads 2>/dev/null || true - chmod -R 777 /var/www/html/inc/settings.php 2>/dev/null || true - chmod -R 777 /var/www/html/inc/config.php 2>/dev/null || true + chmod 666 /var/www/html/inc/settings.php 2>/dev/null || true + chmod 666 /var/www/html/inc/config.php 2>/dev/null || true chmod -R 777 /var/www/html/admin/backups 2>/dev/null || true - - # Create config.php if it doesn't exist (for installer) + + # Create config.php if missing (for installer) if [ ! -f /var/www/html/inc/config.php ]; then touch /var/www/html/inc/config.php chmod 666 /var/www/html/inc/config.php chown www-data:www-data /var/www/html/inc/config.php fi - - log_info "Permissions set successfully" } -# Main execution -main() { - log_info "Starting MyBB Docker container..." - log_info "MyBB Version: ${MYBB_VERSION}" - - # Check for upgrade mode FIRST - if [ "${UPGRADE_MODE:-false}" = "true" ]; then - log_warn "UPGRADE MODE ENABLED" - - if upgrade_mybb "${MYBB_VERSION}"; then - log_info "Upgrade preparation complete." - else - log_error "Upgrade failed!" - exit 1 - fi - # Check for fresh install or forced reinstall - elif [ ! -f /var/www/html/index.php ] || [ "${FORCE_REINSTALL:-false}" = "true" ]; then - if [ "${FORCE_REINSTALL:-false}" = "true" ]; then - log_warn "FORCE REINSTALL enabled - this will overwrite existing files!" - fi - log_info "Installing MyBB..." - - # Download and install MyBB - if download_mybb "${MYBB_VERSION}"; then - install_mybb - set_permissions - log_info "MyBB installation complete!" - log_info "Please visit http://your-server/install/ to complete the setup." - else - log_error "MyBB installation failed!" - exit 1 - fi - else - log_info "MyBB already installed. Skipping download." - - # Check for upgrade reminder - if [ -f /var/www/html/UPGRADE_IN_PROGRESS.txt ]; then - log_warn "==========================================" - log_warn " UPGRADE IN PROGRESS - ACTION REQUIRED" - log_warn "==========================================" - cat /var/www/html/UPGRADE_IN_PROGRESS.txt - log_warn "==========================================" - fi - - # Still set permissions in case of volume mount issues - set_permissions +wait_for_db() { + if [ -z "${DB_HOST}" ]; then + return fi - - # Wait for database if DB_HOST is set - if [ -n "${DB_HOST}" ]; then - log_info "Waiting for database at ${DB_HOST}:${DB_PORT:-3306}..." - - max_tries=30 - counter=0 - - while ! php -r "new mysqli('${DB_HOST}', '${DB_USER:-root}', '${DB_PASSWORD:-}', '', ${DB_PORT:-3306});" 2>/dev/null; do - counter=$((counter + 1)) - if [ $counter -ge $max_tries ]; then - log_warn "Could not connect to database after ${max_tries} attempts. Continuing anyway..." - break - fi - log_info "Database not ready. Waiting... (${counter}/${max_tries})" - sleep 2 - done - - if [ $counter -lt $max_tries ]; then - log_info "Database is ready!" + + log_info "Waiting for database..." + local max_tries=30 + local counter=0 + + while ! php -r "new mysqli('${DB_HOST}', '${DB_USER:-root}', '${DB_PASSWORD:-}', '', ${DB_PORT:-3306});" 2>/dev/null; do + counter=$((counter + 1)) + if [ $counter -ge $max_tries ]; then + log_warn "Database not ready after ${max_tries} attempts, continuing..." + return fi + sleep 2 + done + log_info "Database ready" +} + +main() { + local version=$(get_image_version) + log_info "Starting MyBB Docker (image version: ${version})" + + # Check if MyBB is already installed + if [ -f /var/www/html/inc/config.php ] && grep -q "database" /var/www/html/inc/config.php 2>/dev/null; then + # Existing installation - sync new files but preserve existing + sync_mybb "true" + else + # Fresh install - copy everything + sync_mybb "false" + log_info "Visit http://your-server/install/ to complete setup" fi - + + set_permissions + wait_for_db + log_info "Starting Apache..." - - # Execute the main command exec "$@" } diff --git a/env.example b/env.example index 2b3c3a8..dbeb9a2 100644 --- a/env.example +++ b/env.example @@ -1,11 +1,13 @@ # MyBB Docker Configuration # Copy this file to .env and modify as needed -# MyBB Version (e.g., 1839 for v1.8.39, 1838 for v1.8.38) -# Find versions at: https://github.com/mybb/mybb/releases +# MyBB version (used as build arg for docker-compose.yml) MYBB_VERSION=1839 -# Web Port (MyBB will be accessible at http://localhost:MYBB_PORT) +# Image tag for pre-built images (docker-compose.ghcr.yml) +MYBB_TAG=latest + +# Web Port MYBB_PORT=8080 # Database Configuration @@ -26,17 +28,3 @@ PMA_PORT=8081 # Timezone TZ=UTC - -# =========================================== -# UPGRADE MODE (for existing installations) -# =========================================== -# Set UPGRADE_MODE=true to safely upgrade MyBB -# This will: -# - Backup your config files -# - Download the new MYBB_VERSION -# - Preserve uploads, themes, plugins -# - Remind you to run /install/upgrade.php -# -# UPGRADE_MODE=true -# PRESERVE_PLUGINS=true -# PRESERVE_THEMES=true