From c2eefba7fb253fec929fe2aba817ce94861623e1 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Feb 2026 08:11:55 +0000 Subject: [PATCH 1/3] Bake MyBB into Docker image at build time Previously, MyBB was downloaded at container runtime which posed risks of data loss if downloads failed during container recreation. Now: - MyBB is downloaded and installed during Docker image build - Each image contains a specific MyBB version (no runtime downloads) - GitHub Actions builds images for the 2 latest MyBB versions (1838, 1839) - Container startup copies pre-installed MyBB from image to volume - Version mismatch detection warns when image differs from installed version - Upgrade mode still works for migrating between versions https://claude.ai/code/session_017iViynCSN8iwn6NiUetwsp --- .github/workflows/docker-publish.yml | 13 +++- Dockerfile | 34 +++++++- README.md | 65 ++++++++++++---- docker-compose.ghcr.yml | 5 +- docker-compose.yml | 8 +- docker-entrypoint.sh | 111 +++++++++++++++++++++------ env.example | 27 +++++-- 7 files changed, 206 insertions(+), 57 deletions(-) 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..b7a2f7d 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 \ @@ -61,6 +63,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 +100,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..0136812 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,13 @@ ![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 pre-installed at build time for reliability and security. ## Features - 🐳 Easy deployment with Docker or Docker Compose -- 🔄 Support for any MyBB version (configurable) +- 📦 MyBB pre-installed in the image (no runtime downloads) +- 🏷️ Version-tagged images for the 2 latest MyBB releases - 💾 Persistent data storage with Docker volumes - 🔒 Secure default configuration - 🚀 Optimized PHP configuration for MyBB @@ -27,9 +28,14 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo ### Using Docker CLI -1. **Build the image:** +1. **Build the image (with MyBB version baked in):** ```bash - docker build -t mybb . + docker build --build-arg MYBB_VERSION=1839 -t mybb . + ``` + + Or pull a pre-built image: + ```bash + docker pull ghcr.io/visualcookie/mybb:latest ``` 2. **Create a network:** @@ -56,7 +62,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,7 +89,7 @@ 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 (set at build time, read-only at runtime) | Baked into image | | `MYBB_PORT` | Web server port | `8080` | | `DB_HOST` | Database hostname | - | | `DB_PORT` | Database port | `3306` | @@ -103,9 +108,31 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo ### 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 pre-installed in the image at build time, eliminating runtime download risks and ensuring consistent deployments. + +**Available pre-built images:** + +| Tag | MyBB Version | Notes | +|-----|--------------|-------| +| `latest` | 1839 | Latest stable, recommended | +| `1839` | 1839 | Specific version | +| `1838` | 1838 | Previous version | + +**Pull a specific version:** +```bash +docker pull ghcr.io/visualcookie/mybb:1839 +docker pull ghcr.io/visualcookie/mybb:1838 +``` + +**Building for a different version:** + +If you need a MyBB version not available as a pre-built image, you can build locally: + +```bash +docker build --build-arg MYBB_VERSION=1837 -t mybb:1837 . +``` -Find all available versions at: https://github.com/mybb/mybb/releases +Find all MyBB versions at: https://github.com/mybb/mybb/releases ## Volumes @@ -221,16 +248,24 @@ This image includes a **safe upgrade mode** that preserves your configuration, u ### Quick Upgrade Steps -1. **Edit `.env`** - Set the new version and enable upgrade mode: +1. **Update the image tag** - Use a newer image with the desired MyBB version: ```bash - MYBB_VERSION=1839 - UPGRADE_MODE=true + # In docker-compose.ghcr.yml, update the image tag: + image: ghcr.io/visualcookie/mybb:1839 + ``` + + Or if building locally, rebuild with the new version: + ```bash + docker build --build-arg MYBB_VERSION=1839 -t mybb . ``` -2. **Rebuild and restart:** +2. **Enable upgrade mode and restart:** + ```bash + # In .env: + UPGRADE_MODE=true + ``` ```bash docker compose down - docker compose build --no-cache docker compose up -d ``` @@ -242,10 +277,10 @@ This image includes a **safe upgrade mode** that preserves your configuration, u ```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) ``` diff --git a/docker-compose.ghcr.yml b/docker-compose.ghcr.yml index f83b2b5..a7390ff 100644 --- a/docker-compose.ghcr.yml +++ b/docker-compose.ghcr.yml @@ -1,15 +1,18 @@ # Docker Compose file using pre-built image from GitHub Container Registry +# MyBB version is determined by the image tag (e.g., :latest, :1839, :1838) # Usage: docker compose -f docker-compose.ghcr.yml up -d services: mybb: + # Available tags: latest, 1839, 1838 + # Change the tag to use a different MyBB version image: ghcr.io/visualcookie/mybb:${MYBB_TAG:-latest} container_name: mybb-forum restart: unless-stopped ports: - "${MYBB_PORT:-8080}:80" environment: - - MYBB_VERSION=${MYBB_VERSION:-1839} + # Note: MyBB version is baked into the image, determined by the image tag - DB_HOST=mybb-db - DB_PORT=3306 - DB_USER=${MYSQL_USER:-mybb} diff --git a/docker-compose.yml b/docker-compose.yml index eafc8ed..43bc79e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,13 @@ +# Docker Compose file for local development (builds image locally) +# MyBB is downloaded and baked into the image at build time +# Usage: docker compose up -d + services: mybb: build: context: . args: + # MyBB version is baked into the image at build time MYBB_VERSION: ${MYBB_VERSION:-1839} image: mybb:${MYBB_VERSION:-1839} container_name: mybb-forum @@ -10,7 +15,8 @@ services: ports: - "${MYBB_PORT:-8080}:80" environment: - - MYBB_VERSION=${MYBB_VERSION:-1839} + # Note: MYBB_VERSION is determined by the image, not this env var + # This is passed for reference/logging only - DB_HOST=mybb-db - DB_PORT=3306 - DB_USER=${MYSQL_USER:-mybb} diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index abad48c..a19f25d 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,6 +8,9 @@ YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# Source directory where MyBB is pre-installed at build time +MYBB_SOURCE_DIR="${MYBB_SOURCE_DIR:-/opt/mybb-source}" + log_info() { echo -e "${GREEN}[INFO]${NC} $1" } @@ -24,18 +27,38 @@ log_important() { echo -e "${BLUE}[IMPORTANT]${NC} $1" } -# Function to download MyBB +# Function to get the pre-installed MyBB version from the image +get_image_version() { + if [ -f "${MYBB_SOURCE_DIR}/.mybb_version" ]; then + cat "${MYBB_SOURCE_DIR}/.mybb_version" + else + echo "${MYBB_VERSION:-unknown}" + fi +} + +# Function to get the installed MyBB version from the volume +get_installed_version() { + if [ -f "/var/www/html/.mybb_version" ]; then + cat "/var/www/html/.mybb_version" + elif [ -f "/var/www/html/inc/class_core.php" ]; then + grep -oP "public \\\$version = '\K[^']+" /var/www/html/inc/class_core.php 2>/dev/null || echo "unknown" + else + echo "none" + fi +} + +# Function to download MyBB (used only for upgrades to versions not in the image) 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 @@ -44,20 +67,20 @@ download_mybb() { return 1 fi fi - + return 0 } -# Function to extract MyBB to a target directory +# Function to extract MyBB to a target directory (used for upgrades) 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/" @@ -67,16 +90,33 @@ extract_mybb() { # Some versions might extract directly cp -r /tmp/mybb_extract/*/* "$target_dir/" 2>/dev/null || cp -r /tmp/mybb_extract/* "$target_dir/" fi - + # Cleanup rm -rf /tmp/mybb.zip /tmp/mybb_extract - + log_info "MyBB extracted successfully" } -# Function to install MyBB (fresh install) +# Function to install MyBB from the pre-built image (fresh install) install_mybb() { - extract_mybb "/var/www/html" + local image_version=$(get_image_version) + + log_info "Installing MyBB ${image_version} from pre-built image..." + + # Verify source directory exists and contains MyBB + if [ ! -d "${MYBB_SOURCE_DIR}" ] || [ ! -f "${MYBB_SOURCE_DIR}/index.php" ]; then + log_error "MyBB source not found in image at ${MYBB_SOURCE_DIR}" + log_error "This image may not have been built correctly." + return 1 + fi + + # Copy MyBB from the pre-installed source to web root + cp -r "${MYBB_SOURCE_DIR}"/* /var/www/html/ + + # Track the installed version + echo "${image_version}" > /var/www/html/.mybb_version + + log_info "MyBB ${image_version} installed successfully from image" } # Function to create backup before upgrade @@ -248,10 +288,13 @@ upgrade_mybb() { # Cleanup rm -rf /tmp/mybb_preserve - + + # Track the upgraded version + echo "${target_version}" > /var/www/html/.mybb_version + # Set permissions set_permissions - + # Success message log_info "" log_info "==========================================" @@ -316,13 +359,20 @@ set_permissions() { # Main execution main() { + local image_version=$(get_image_version) + local installed_version=$(get_installed_version) + log_info "Starting MyBB Docker container..." - log_info "MyBB Version: ${MYBB_VERSION}" - + log_info "MyBB version in image: ${image_version}" + + if [ "${installed_version}" != "none" ]; then + log_info "MyBB version installed: ${installed_version}" + fi + # 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 @@ -335,10 +385,9 @@ main() { 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 + + # Install MyBB from the pre-built image (no download needed) + if install_mybb; then set_permissions log_info "MyBB installation complete!" log_info "Please visit http://your-server/install/ to complete the setup." @@ -347,8 +396,20 @@ main() { exit 1 fi else - log_info "MyBB already installed. Skipping download." - + log_info "MyBB already installed. Skipping installation." + + # Check if image has a newer version than installed + if [ "${image_version}" != "${installed_version}" ] && [ "${installed_version}" != "unknown" ]; then + log_warn "==========================================" + log_warn " VERSION MISMATCH DETECTED" + log_warn "==========================================" + log_warn "Installed version: ${installed_version}" + log_warn "Image version: ${image_version}" + log_warn "" + log_warn "To upgrade, set UPGRADE_MODE=true and restart the container." + log_warn "==========================================" + fi + # Check for upgrade reminder if [ -f /var/www/html/UPGRADE_IN_PROGRESS.txt ]; then log_warn "==========================================" @@ -357,7 +418,7 @@ main() { cat /var/www/html/UPGRADE_IN_PROGRESS.txt log_warn "==========================================" fi - + # Still set permissions in case of volume mount issues set_permissions fi diff --git a/env.example b/env.example index 2b3c3a8..732540d 100644 --- a/env.example +++ b/env.example @@ -1,9 +1,22 @@ # 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) +# =========================================== +# MyBB VERSION CONFIGURATION +# =========================================== +# MyBB is baked into the Docker image at build time for reliability. +# +# For docker-compose.yml (local build): +# MYBB_VERSION is used as a build argument +# Rebuild with: docker compose build --no-cache +# +# For docker-compose.ghcr.yml (pre-built images): +# Use MYBB_TAG to select the image version (latest, 1839, 1838) +# MYBB_VERSION is ignored when using pre-built images +# # Find versions at: https://github.com/mybb/mybb/releases MYBB_VERSION=1839 +MYBB_TAG=latest # Web Port (MyBB will be accessible at http://localhost:MYBB_PORT) MYBB_PORT=8080 @@ -30,12 +43,12 @@ 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 +# To upgrade MyBB: +# 1. Update MYBB_VERSION (local build) or MYBB_TAG (pre-built image) +# 2. Set UPGRADE_MODE=true +# 3. Rebuild/restart: docker compose down && docker compose up -d +# 4. Visit /install/upgrade.php to complete the database migration +# 5. Delete install folder and set UPGRADE_MODE=false # # UPGRADE_MODE=true # PRESERVE_PLUGINS=true From 340b527e658cc641858555c548430fd14c044993 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Feb 2026 08:28:21 +0000 Subject: [PATCH 2/3] Remove runtime downloads, use image-baked MyBB for upgrades - Remove download_mybb/extract_mybb functions from entrypoint - Upgrade mode now uses pre-installed MyBB from image instead of downloading - Simplify docker-compose files and documentation - Clean up verbose comments https://claude.ai/code/session_017iViynCSN8iwn6NiUetwsp --- README.md | 62 +++++++------------------- docker-compose.ghcr.yml | 7 --- docker-compose.yml | 7 --- docker-entrypoint.sh | 98 +++++++++-------------------------------- env.example | 30 +++---------- 5 files changed, 40 insertions(+), 164 deletions(-) diff --git a/README.md b/README.md index 0136812..d316612 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,12 @@ ![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 Docker image for [MyBB](https://mybb.com/) forum software with MyBB pre-installed at build time for reliability and security. +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 - 📦 MyBB pre-installed in the image (no runtime downloads) -- 🏷️ Version-tagged images for the 2 latest MyBB releases - 💾 Persistent data storage with Docker volumes - 🔒 Secure default configuration - 🚀 Optimized PHP configuration for MyBB @@ -28,16 +27,11 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo ### Using Docker CLI -1. **Build the image (with MyBB version baked in):** +1. **Build the image:** ```bash docker build --build-arg MYBB_VERSION=1839 -t mybb . ``` - Or pull a pre-built image: - ```bash - docker pull ghcr.io/visualcookie/mybb:latest - ``` - 2. **Create a network:** ```bash docker network create mybb-network @@ -89,7 +83,7 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo | Variable | Description | Default | |----------|-------------|---------| -| `MYBB_VERSION` | MyBB version (set at build time, read-only at runtime) | Baked into image | +| `MYBB_VERSION` | MyBB version (build argument) | `1839` | | `MYBB_PORT` | Web server port | `8080` | | `DB_HOST` | Database hostname | - | | `DB_PORT` | Database port | `3306` | @@ -108,32 +102,20 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo ### MyBB Versions -MyBB is pre-installed in the image at build time, eliminating runtime download risks and ensuring consistent deployments. - -**Available pre-built images:** +MyBB is baked into the image at build time. Pre-built images are available for the 2 latest versions: -| Tag | MyBB Version | Notes | -|-----|--------------|-------| -| `latest` | 1839 | Latest stable, recommended | -| `1839` | 1839 | Specific version | -| `1838` | 1838 | Previous version | - -**Pull a specific version:** ```bash +docker pull ghcr.io/visualcookie/mybb:latest # 1839 docker pull ghcr.io/visualcookie/mybb:1839 docker pull ghcr.io/visualcookie/mybb:1838 ``` -**Building for a different version:** - -If you need a MyBB version not available as a pre-built image, you can build locally: +To build a different version locally: ```bash docker build --build-arg MYBB_VERSION=1837 -t mybb:1837 . ``` -Find all MyBB versions at: https://github.com/mybb/mybb/releases - ## Volumes The following volumes are created for data persistence: @@ -248,41 +230,27 @@ This image includes a **safe upgrade mode** that preserves your configuration, u ### Quick Upgrade Steps -1. **Update the image tag** - Use a newer image with the desired MyBB version: - ```bash - # In docker-compose.ghcr.yml, update the image tag: - image: ghcr.io/visualcookie/mybb:1839 - ``` - - Or if building locally, rebuild with the new version: - ```bash - docker build --build-arg MYBB_VERSION=1839 -t mybb . - ``` +1. **Update to a new image** with the desired MyBB version (change image tag or rebuild) -2. **Enable upgrade mode and restart:** +2. **Enable upgrade mode** in `.env`: ```bash - # In .env: UPGRADE_MODE=true ``` + +3. **Restart the container:** ```bash - docker compose down - docker compose up -d + docker compose down && docker compose up -d ``` -3. **Complete the upgrade:** +4. **Complete the upgrade:** - Visit `http://localhost:8080/install/upgrade.php` - - Follow the upgrade wizard (this migrates your database) + - Follow the upgrade wizard -4. **Cleanup:** +5. **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) + # Set UPGRADE_MODE=false in .env ``` ### What Gets Preserved diff --git a/docker-compose.ghcr.yml b/docker-compose.ghcr.yml index a7390ff..8f3fb59 100644 --- a/docker-compose.ghcr.yml +++ b/docker-compose.ghcr.yml @@ -1,18 +1,11 @@ -# Docker Compose file using pre-built image from GitHub Container Registry -# MyBB version is determined by the image tag (e.g., :latest, :1839, :1838) -# Usage: docker compose -f docker-compose.ghcr.yml up -d - services: mybb: - # Available tags: latest, 1839, 1838 - # Change the tag to use a different MyBB version image: ghcr.io/visualcookie/mybb:${MYBB_TAG:-latest} container_name: mybb-forum restart: unless-stopped ports: - "${MYBB_PORT:-8080}:80" environment: - # Note: MyBB version is baked into the image, determined by the image tag - DB_HOST=mybb-db - DB_PORT=3306 - DB_USER=${MYSQL_USER:-mybb} diff --git a/docker-compose.yml b/docker-compose.yml index 43bc79e..cef0571 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,8 @@ -# Docker Compose file for local development (builds image locally) -# MyBB is downloaded and baked into the image at build time -# Usage: docker compose up -d - services: mybb: build: context: . args: - # MyBB version is baked into the image at build time MYBB_VERSION: ${MYBB_VERSION:-1839} image: mybb:${MYBB_VERSION:-1839} container_name: mybb-forum @@ -15,8 +10,6 @@ services: ports: - "${MYBB_PORT:-8080}:80" environment: - # Note: MYBB_VERSION is determined by the image, not this env var - # This is passed for reference/logging only - DB_HOST=mybb-db - DB_PORT=3306 - DB_USER=${MYSQL_USER:-mybb} diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a19f25d..2d24555 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -32,7 +32,7 @@ get_image_version() { if [ -f "${MYBB_SOURCE_DIR}/.mybb_version" ]; then cat "${MYBB_SOURCE_DIR}/.mybb_version" else - echo "${MYBB_VERSION:-unknown}" + echo "unknown" fi } @@ -47,76 +47,21 @@ get_installed_version() { fi } -# Function to download MyBB (used only for upgrades to versions not in the image) -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 -} - -# Function to extract MyBB to a target directory (used for upgrades) -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/" - fi - - # Cleanup - rm -rf /tmp/mybb.zip /tmp/mybb_extract - - log_info "MyBB extracted successfully" -} - -# Function to install MyBB from the pre-built image (fresh install) +# Function to install MyBB from the pre-built image install_mybb() { local image_version=$(get_image_version) - log_info "Installing MyBB ${image_version} from pre-built image..." + log_info "Installing MyBB ${image_version} from image..." - # Verify source directory exists and contains MyBB if [ ! -d "${MYBB_SOURCE_DIR}" ] || [ ! -f "${MYBB_SOURCE_DIR}/index.php" ]; then log_error "MyBB source not found in image at ${MYBB_SOURCE_DIR}" - log_error "This image may not have been built correctly." return 1 fi - # Copy MyBB from the pre-installed source to web root cp -r "${MYBB_SOURCE_DIR}"/* /var/www/html/ - - # Track the installed version echo "${image_version}" > /var/www/html/.mybb_version - log_info "MyBB ${image_version} installed successfully from image" + log_info "MyBB ${image_version} installed successfully" } # Function to create backup before upgrade @@ -161,10 +106,10 @@ create_backup() { echo "$backup_dir/${backup_name}" > /tmp/last_backup_path } -# Function to perform safe upgrade +# Function to perform safe upgrade using the version baked into the image upgrade_mybb() { - local target_version=$1 - + local target_version=$(get_image_version) + log_info "==========================================" log_info " MyBB SAFE UPGRADE MODE" log_info "==========================================" @@ -187,12 +132,12 @@ upgrade_mybb() { # Step 1: Create backup log_info "" - log_info "Step 1/5: Creating backup..." + log_info "Step 1/4: Creating backup..." create_backup - + # Step 2: Save files that must be preserved log_info "" - log_info "Step 2/5: Preserving critical files..." + log_info "Step 2/4: Preserving critical files..." mkdir -p /tmp/mybb_preserve @@ -230,24 +175,21 @@ upgrade_mybb() { log_info "Preserved: inc/languages/ directory" fi - # Step 3: Download new version + # Step 3: Install new version from image 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." + log_info "Step 3/4: Installing MyBB ${target_version} from image..." + + if [ ! -d "${MYBB_SOURCE_DIR}" ] || [ ! -f "${MYBB_SOURCE_DIR}/index.php" ]; then + log_error "MyBB source not found in image. Aborting upgrade." rm -rf /tmp/mybb_preserve return 1 fi + + cp -r "${MYBB_SOURCE_DIR}"/* /var/www/html/ - # 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 + # Step 4: Restore preserved files log_info "" - log_info "Step 5/5: Restoring preserved files..." + log_info "Step 4/4: Restoring preserved files..." # Restore config.php (CRITICAL) cp /tmp/mybb_preserve/config.php /var/www/html/inc/config.php @@ -373,7 +315,7 @@ main() { if [ "${UPGRADE_MODE:-false}" = "true" ]; then log_warn "UPGRADE MODE ENABLED" - if upgrade_mybb "${MYBB_VERSION}"; then + if upgrade_mybb; then log_info "Upgrade preparation complete." else log_error "Upgrade failed!" diff --git a/env.example b/env.example index 732540d..16be2ea 100644 --- a/env.example +++ b/env.example @@ -1,24 +1,13 @@ # MyBB Docker Configuration # Copy this file to .env and modify as needed -# =========================================== -# MyBB VERSION CONFIGURATION -# =========================================== -# MyBB is baked into the Docker image at build time for reliability. -# -# For docker-compose.yml (local build): -# MYBB_VERSION is used as a build argument -# Rebuild with: docker compose build --no-cache -# -# For docker-compose.ghcr.yml (pre-built images): -# Use MYBB_TAG to select the image version (latest, 1839, 1838) -# MYBB_VERSION is ignored when using pre-built images -# -# Find versions at: https://github.com/mybb/mybb/releases +# MyBB version (used as build arg for docker-compose.yml) MYBB_VERSION=1839 + +# Image tag for pre-built images (docker-compose.ghcr.yml) MYBB_TAG=latest -# Web Port (MyBB will be accessible at http://localhost:MYBB_PORT) +# Web Port MYBB_PORT=8080 # Database Configuration @@ -40,16 +29,7 @@ PMA_PORT=8081 # Timezone TZ=UTC -# =========================================== -# UPGRADE MODE (for existing installations) -# =========================================== -# To upgrade MyBB: -# 1. Update MYBB_VERSION (local build) or MYBB_TAG (pre-built image) -# 2. Set UPGRADE_MODE=true -# 3. Rebuild/restart: docker compose down && docker compose up -d -# 4. Visit /install/upgrade.php to complete the database migration -# 5. Delete install folder and set UPGRADE_MODE=false -# +# Upgrade mode (set to true when upgrading to a new image) # UPGRADE_MODE=true # PRESERVE_PLUGINS=true # PRESERVE_THEMES=true From fc1fd0d0bfc916afcc111235c45c9ef4cd0b746f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Feb 2026 08:33:25 +0000 Subject: [PATCH 3/3] Simplify entrypoint: use rsync, remove UPGRADE_MODE Follow the approach used by mybb/docker - on every container start, sync files from image to volume using rsync. Existing files are preserved automatically (--ignore-existing), so configs, uploads, plugins, and themes survive upgrades without special handling. Changes: - Rewrite entrypoint to ~100 lines (was ~450) - Remove UPGRADE_MODE, PRESERVE_PLUGINS, PRESERVE_THEMES - Add rsync to Dockerfile - Simplify documentation https://claude.ai/code/session_017iViynCSN8iwn6NiUetwsp --- Dockerfile | 1 + README.md | 108 ++--------- docker-compose.ghcr.yml | 4 - docker-compose.yml | 4 - docker-entrypoint.sh | 405 ++++++---------------------------------- env.example | 5 - 6 files changed, 72 insertions(+), 455 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7a2f7d..76ca8ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,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 diff --git a/README.md b/README.md index d316612..578b849 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A Docker image for [MyBB](https://mybb.com/) forum software with MyBB baked into - 💾 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 @@ -90,15 +90,7 @@ There's an example [Docker compose file](./docker-compose.ghcr.yml) in this repo | `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 @@ -224,91 +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. **Update to a new image** with the desired MyBB version (change image tag or rebuild) - -2. **Enable upgrade mode** in `.env`: - ```bash - UPGRADE_MODE=true - ``` - -3. **Restart the container:** - ```bash - docker compose down && docker compose up -d - ``` - -4. **Complete the upgrade:** - - Visit `http://localhost:8080/install/upgrade.php` - - Follow the upgrade wizard - -5. **Cleanup:** - ```bash - docker exec mybb-forum rm -rf /var/www/html/install - docker exec mybb-forum rm -f /var/www/html/UPGRADE_IN_PROGRESS.txt - # Set UPGRADE_MODE=false in .env - ``` - -### 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 +## Upgrading MyBB -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 @@ -334,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 8f3fb59..1d3910e 100644 --- a/docker-compose.ghcr.yml +++ b/docker-compose.ghcr.yml @@ -12,10 +12,6 @@ services: - 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 cef0571..5d2d32b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,10 +16,6 @@ services: - 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 2d24555..5644b2d 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,391 +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' -# Source directory where MyBB is pre-installed at build time -MYBB_SOURCE_DIR="${MYBB_SOURCE_DIR:-/opt/mybb-source}" +MYBB_SOURCE="/opt/mybb-source" -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_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" -} - -# Function to get the pre-installed MyBB version from the image get_image_version() { - if [ -f "${MYBB_SOURCE_DIR}/.mybb_version" ]; then - cat "${MYBB_SOURCE_DIR}/.mybb_version" - else - echo "unknown" - fi + cat "${MYBB_SOURCE}/.mybb_version" 2>/dev/null || echo "unknown" } -# Function to get the installed MyBB version from the volume -get_installed_version() { - if [ -f "/var/www/html/.mybb_version" ]; then - cat "/var/www/html/.mybb_version" - elif [ -f "/var/www/html/inc/class_core.php" ]; then - grep -oP "public \\\$version = '\K[^']+" /var/www/html/inc/class_core.php 2>/dev/null || echo "unknown" - else - echo "none" - fi -} - -# Function to install MyBB from the pre-built image -install_mybb() { - local image_version=$(get_image_version) +# 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) - log_info "Installing MyBB ${image_version} from image..." - - if [ ! -d "${MYBB_SOURCE_DIR}" ] || [ ! -f "${MYBB_SOURCE_DIR}/index.php" ]; then - log_error "MyBB source not found in image at ${MYBB_SOURCE_DIR}" + if [ ! -d "${MYBB_SOURCE}" ]; then + log_error "MyBB source not found in image" return 1 fi - cp -r "${MYBB_SOURCE_DIR}"/* /var/www/html/ - echo "${image_version}" > /var/www/html/.mybb_version - - log_info "MyBB ${image_version} installed successfully" -} - -# 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 - fi - - log_info "Backup created in: $backup_dir" - echo "$backup_dir/${backup_name}" > /tmp/last_backup_path -} - -# Function to perform safe upgrade using the version baked into the image -upgrade_mybb() { - local target_version=$(get_image_version) - - 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/4: Creating backup..." - create_backup - - # Step 2: Save files that must be preserved - log_info "" - log_info "Step 2/4: 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: Install new version from image - log_info "" - log_info "Step 3/4: Installing MyBB ${target_version} from image..." - - if [ ! -d "${MYBB_SOURCE_DIR}" ] || [ ! -f "${MYBB_SOURCE_DIR}/index.php" ]; then - log_error "MyBB source not found in image. Aborting upgrade." - rm -rf /tmp/mybb_preserve - return 1 - fi + log_info "Syncing MyBB ${version} to volume..." - cp -r "${MYBB_SOURCE_DIR}"/* /var/www/html/ - - # Step 4: Restore preserved files - log_info "" - log_info "Step 4/4: 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" + 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 - - # Cleanup - rm -rf /tmp/mybb_preserve - - # Track the upgraded version - echo "${target_version}" > /var/www/html/.mybb_version - - # 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() { - local image_version=$(get_image_version) - local installed_version=$(get_installed_version) - - log_info "Starting MyBB Docker container..." - log_info "MyBB version in image: ${image_version}" - - if [ "${installed_version}" != "none" ]; then - log_info "MyBB version installed: ${installed_version}" +wait_for_db() { + if [ -z "${DB_HOST}" ]; then + return fi - # Check for upgrade mode FIRST - if [ "${UPGRADE_MODE:-false}" = "true" ]; then - log_warn "UPGRADE MODE ENABLED" + log_info "Waiting for database..." + local max_tries=30 + local counter=0 - if upgrade_mybb; 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!" + 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 - log_info "Installing MyBB..." + sleep 2 + done + log_info "Database ready" +} - # Install MyBB from the pre-built image (no download needed) - if install_mybb; then - 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 installation." +main() { + local version=$(get_image_version) + log_info "Starting MyBB Docker (image version: ${version})" - # Check if image has a newer version than installed - if [ "${image_version}" != "${installed_version}" ] && [ "${installed_version}" != "unknown" ]; then - log_warn "==========================================" - log_warn " VERSION MISMATCH DETECTED" - log_warn "==========================================" - log_warn "Installed version: ${installed_version}" - log_warn "Image version: ${image_version}" - log_warn "" - log_warn "To upgrade, set UPGRADE_MODE=true and restart the container." - log_warn "==========================================" - fi + # 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 - # 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 + set_permissions + wait_for_db - # Still set permissions in case of volume mount issues - set_permissions - 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!" - fi - fi - log_info "Starting Apache..." - - # Execute the main command exec "$@" } diff --git a/env.example b/env.example index 16be2ea..dbeb9a2 100644 --- a/env.example +++ b/env.example @@ -28,8 +28,3 @@ PMA_PORT=8081 # Timezone TZ=UTC - -# Upgrade mode (set to true when upgrading to a new image) -# UPGRADE_MODE=true -# PRESERVE_PLUGINS=true -# PRESERVE_THEMES=true