-
Notifications
You must be signed in to change notification settings - Fork 831
Add a Docker Compose setup for building and serving PHP documentation locally #4962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lacatoire
wants to merge
1
commit into
php:master
Choose a base branch
from
lacatoire:docker-doc-setup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,48 @@ | ||
| FROM php:8.2-cli | ||
| FROM php:8.2-cli-alpine | ||
|
|
||
| RUN apt-get update && \ | ||
| apt-get install -y git default-jre-headless | ||
| LABEL maintainer="PHP Documentation Team <[email protected]>" | ||
| LABEL description="Image for building and serving PHP documentation (php-chunked-xhtml format)" | ||
|
|
||
| WORKDIR /var/www | ||
| ENV LANG=C.UTF-8 \ | ||
| LC_ALL=C.UTF-8 \ | ||
| DOC_DIR=/var/www \ | ||
| PHD_DIR=/opt/phd | ||
|
|
||
| ADD https://api.github.com/repos/php/phd/git/refs/heads/master version-phd.json | ||
| ADD https://api.github.com/repos/php/doc-base/git/refs/heads/master version-doc-base.json | ||
| # 🔧 PhD dependencies | ||
| RUN apk add --no-cache \ | ||
| git \ | ||
| icu-dev \ | ||
| libxml2-dev \ | ||
| libxslt-dev \ | ||
| gettext \ | ||
| autoconf \ | ||
| g++ \ | ||
| pkgconfig \ | ||
| && docker-php-ext-install intl xsl | ||
|
|
||
| RUN git clone --depth 1 https://github.com/php/phd.git && \ | ||
| git clone --depth 1 https://github.com/php/doc-base.git | ||
| # 📦 Install Composer | ||
| RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
|
|
||
| RUN echo 'memory_limit = 512M' >> /usr/local/etc/php/conf.d/local.ini | ||
| # Install PhD and the PHP package (stable compatible version --addpackage) | ||
| RUN git clone https://github.com/php/phd.git "$PHD_DIR" \ | ||
| && cd "$PHD_DIR" \ | ||
| && git checkout c3e2d8c \ | ||
| && git clone https://github.com/php/phd-php.git "$PHD_DIR/phpdotnet/phd/Package/PHP" \ | ||
| && composer install --no-dev --no-progress --prefer-dist || true | ||
|
|
||
| ENV FORMAT=xhtml | ||
| WORKDIR $DOC_DIR | ||
|
|
||
| CMD php doc-base/configure.php --disable-segfault-error && \ | ||
| php phd/render.php --docbook doc-base/.manual.xml --output=/var/www/en/output --package PHP --format ${FORMAT} | ||
| # Default formats and package | ||
| ENV FORMAT=php-chunked-xhtml | ||
| ENV PACKAGE=PHP | ||
|
|
||
| # Grant full permissions to /var/www (useful on Windows/WSL2) | ||
| RUN mkdir -p /var/www/output && chmod -R 777 /var/www | ||
|
|
||
| # Entry script | ||
| COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh | ||
| RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh && chmod +x /usr/local/bin/entrypoint.sh | ||
|
|
||
| EXPOSE 8000 | ||
| RUN chmod -R 777 /var/www | ||
| ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #!/bin/sh | ||
|
|
||
| # POSIX-compliant entrypoint for building PHP documentation | ||
| # Fully compatible with Linux, Alpine, and macOS environments | ||
|
|
||
| set -e | ||
|
|
||
| LANGUAGE=${1:-en} | ||
| FORMAT=${2:-xhtml} | ||
| PACKAGE=${PACKAGE:-PHP} | ||
| MANUAL_PATH="/var/www/$LANGUAGE/.manual.xml" | ||
|
|
||
| # 🧩 Step 1. Verify prerequisites (avoid silent empty mounts) | ||
| echo "🔍 Checking required documentation repositories..." | ||
|
|
||
| # Check doc-base presence (must contain configure.php) | ||
| if [ ! -f /var/www/doc-base/configure.php ]; then | ||
| echo "❌ doc-base is missing or incomplete!" | ||
| echo "👉 Please clone it before running Docker:" | ||
| echo " git clone https://github.com/php/doc-base ../doc-base" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check language documentation presence | ||
| if [ ! -d "/var/www/$LANGUAGE" ] || [ ! -f "/var/www/$LANGUAGE/sources.xml" ]; then | ||
| echo "❌ doc-${LANGUAGE} is missing or incomplete!" | ||
| echo "👉 Please clone it before running Docker:" | ||
| echo " git clone https://github.com/php/doc-${LANGUAGE} ../doc-${LANGUAGE}" | ||
| echo "" | ||
| echo "💡 Tip: remove any empty folders and rebuild containers with '--force-recreate'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| done | ||
| echo "✅ All prerequisites found." | ||
| echo "" | ||
|
|
||
| echo "🧩 Building PHP documentation..." | ||
| echo "Language: $LANGUAGE" | ||
| echo "Format: $FORMAT" | ||
| echo "Docbook: $MANUAL_PATH" | ||
|
|
||
| # Add the PHP package to the include_path for PhD. | ||
| export PHP_INCLUDE_PATH="$PHD_DIR/phpdotnet/phd/Package:$PHD_DIR/phpdotnet/phd/Package/PHP:$PHP_INCLUDE_PATH" | ||
|
|
||
| # 🧹 Clean if necessary | ||
| if [ -f "$MANUAL_PATH" ]; then | ||
| echo "🧹 Removing old .manual.xml..." | ||
| rm -f "$MANUAL_PATH" || true | ||
| fi | ||
|
|
||
| echo "ℹ️ Generating .manual.xml for $LANGUAGE..." | ||
| cd /var/www/doc-base | ||
| php configure.php \ | ||
| --disable-segfault-error \ | ||
| --basedir="/var/www/doc-base" \ | ||
| --output="$MANUAL_PATH" \ | ||
| --lang="$LANGUAGE" | ||
|
|
||
| if [ ! -f "$MANUAL_PATH" ]; then | ||
| echo "❌ Failed to generate $MANUAL_PATH" | ||
| exit 1 | ||
| fi | ||
| echo "✅ Generated $MANUAL_PATH" | ||
|
|
||
| # Verify PHP package presence | ||
| if [ ! -d "$PHD_DIR/phpdotnet/phd/Package/PHP" ]; then | ||
| echo "❌ PHP package not found in $PHD_DIR/phpdotnet/phd/Package/PHP" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Normalize Windows CRLF endings and adjust doc-base paths | ||
| echo "🩹 Patching entity paths to use doc-base…" | ||
| tr -d '\r' < "$MANUAL_PATH" > "$MANUAL_PATH.clean" && mv "$MANUAL_PATH.clean" "$MANUAL_PATH" | ||
| sed -i "s#/var/www/$LANGUAGE/entities/#/var/www/doc-base/entities/#g" "$MANUAL_PATH" | ||
| sed -i "s#/var/www/$LANGUAGE/version.xml#/var/www/doc-base/version.xml#g" "$MANUAL_PATH" | ||
| sed -i "s#/var/www/$LANGUAGE/sources.xml#/var/www/doc-base/sources.xml#g" "$MANUAL_PATH" | ||
| head -n 25 "$MANUAL_PATH" | ||
|
|
||
| # 🧩 Include the PHP package for PhD | ||
| export PHP_INCLUDE_PATH="$PHD_DIR/phpdotnet/phd/Package:$PHD_DIR/phpdotnet/phd/Package/PHP:$PHP_INCLUDE_PATH" | ||
|
|
||
| cd /var/www/$LANGUAGE | ||
|
|
||
| # 🏗️ Render the documentation | ||
| php -d include_path="$PHP_INCLUDE_PATH" \ | ||
| "$PHD_DIR/render.php" \ | ||
| --docbook "$MANUAL_PATH" \ | ||
| --package "$PACKAGE" \ | ||
| --format "$FORMAT" | ||
|
|
||
| # 🔎 Locate the output directory | ||
| OUTDIR="" | ||
| for d in php-chunked-xhtml xhtml phpweb php; do | ||
| if [ -d "/var/www/$LANGUAGE/output/$d" ]; then | ||
| OUTDIR="/var/www/$LANGUAGE/output/$d" | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| if [ -d "$OUTDIR" ]; then | ||
| echo "✅ Build complete: $OUTDIR" | ||
| echo "View the documentation on http://localhost:8000" | ||
| else | ||
| echo "❌ No output directory found in /var/www/$LANGUAGE/output/" | ||
| ls -R "/var/www/$LANGUAGE/output" || true | ||
| exit 1 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| services: | ||
| phpdoc: | ||
| build: | ||
| dockerfile: .docker/Dockerfile | ||
| container_name: phpdoc-builder | ||
| working_dir: /var/www | ||
| user: "0:0" | ||
| volumes: | ||
| - ../doc-${LANGUAGE:-en}:/var/www/${LANGUAGE:-en} | ||
| - ../doc-en:/var/www/en | ||
| - ../doc-base:/var/www/doc-base | ||
lacatoire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| command: ["${LANGUAGE:-en}", "xhtml"] | ||
|
|
||
| phpdoc-web: | ||
| image: php:8.2-cli-alpine | ||
| container_name: phpdoc-web | ||
| working_dir: /var/www/${LANGUAGE:-en}/output | ||
| volumes: | ||
| - ../doc-${LANGUAGE:-en}/output/php-chunked-xhtml:/var/www/${LANGUAGE:-en}/output | ||
| ports: | ||
| - "8000:8000" | ||
| command: ["php", "-S", "0.0.0.0:8000", "-t", "/var/www/${LANGUAGE:-en}/output"] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.