Skip to content

Commit 93b2950

Browse files
author
lacatoire
committed
dockerize documentation generation
1 parent 85c47f8 commit 93b2950

4 files changed

Lines changed: 188 additions & 12 deletions

File tree

.docker/Dockerfile

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
1-
FROM php:8.2-cli
1+
FROM php:8.2-cli-alpine
22

3-
RUN apt-get update && \
4-
apt-get install -y git default-jre-headless
3+
LABEL maintainer="PHP Documentation Team <doc@php.net>"
4+
LABEL description="Image for building and serving PHP documentation (php-chunked-xhtml format)"
55

6-
WORKDIR /var/www
6+
ENV LANG=C.UTF-8 \
7+
LC_ALL=C.UTF-8 \
8+
DOC_DIR=/var/www \
9+
PHD_DIR=/opt/phd
710

8-
ADD https://api.github.com/repos/php/phd/git/refs/heads/master version-phd.json
9-
ADD https://api.github.com/repos/php/doc-base/git/refs/heads/master version-doc-base.json
11+
# 🔧 Dependancies to PhD
12+
RUN apk add --no-cache \
13+
git \
14+
icu-dev \
15+
libxml2-dev \
16+
libxslt-dev \
17+
gettext \
18+
autoconf \
19+
g++ \
20+
pkgconfig \
21+
&& docker-php-ext-install intl xsl
1022

11-
RUN git clone --depth 1 https://github.com/php/phd.git && \
12-
git clone --depth 1 https://github.com/php/doc-base.git
23+
# 📦 Installer Composer
24+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
1325

14-
RUN echo 'memory_limit = 512M' >> /usr/local/etc/php/conf.d/local.ini
26+
# Install PhD and the PHP package (stable compatible version --addpackage)
27+
RUN git clone https://github.com/php/phd.git "$PHD_DIR" \
28+
&& cd "$PHD_DIR" \
29+
&& git checkout c3e2d8c \
30+
&& git clone https://github.com/php/phd-php.git "$PHD_DIR/phpdotnet/phd/Package/PHP" \
31+
&& composer install --no-dev --no-progress --prefer-dist || true
1532

16-
ENV FORMAT=xhtml
33+
WORKDIR $DOC_DIR
34+
35+
# Default formats and package
36+
ENV FORMAT=php-chunked-xhtml
37+
ENV PACKAGE=PHP
38+
39+
# Grant full permissions to /var/www (useful on Windows/WSL2)
40+
RUN mkdir -p /var/www/output && chmod -R 777 /var/www
41+
42+
# Entry script
43+
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh
44+
RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh && chmod +x /usr/local/bin/entrypoint.sh
45+
46+
EXPOSE 8000
47+
RUN chmod -R 777 /var/www
48+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
1749

18-
CMD php doc-base/configure.php --disable-segfault-error && \
19-
php phd/render.php --docbook doc-base/.manual.xml --output=/var/www/en/output --package PHP --format ${FORMAT}

.docker/entrypoint.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
3+
# POSIX-compliant entrypoint for building PHP documentation
4+
# Fully compatible with Linux, Alpine, and macOS environments
5+
6+
set -e
7+
8+
LANGUAGE=${1:-en}
9+
FORMAT=${2:-xhtml}
10+
PACKAGE=${PACKAGE:-PHP}
11+
MANUAL_PATH="/var/www/$LANGUAGE/.manual.xml"
12+
13+
echo "🧩 Building PHP documentation..."
14+
echo "Language: $LANGUAGE"
15+
echo "Format: $FORMAT"
16+
echo "Docbook: $MANUAL_PATH"
17+
18+
# Add the PHP package to the include_path for PhD.
19+
export PHP_INCLUDE_PATH="$PHD_DIR/phpdotnet/phd/Package:$PHD_DIR/phpdotnet/phd/Package/PHP:$PHP_INCLUDE_PATH"
20+
21+
# 🧹 Clean if necessary
22+
if [ -f "$MANUAL_PATH" ]; then
23+
echo "🧹 Removing old .manual.xml..."
24+
rm -f "$MANUAL_PATH" || true
25+
fi
26+
27+
echo "ℹ️ Generating .manual.xml for $LANGUAGE..."
28+
cd /var/www/doc-base
29+
php configure.php \
30+
--disable-segfault-error \
31+
--basedir="/var/www/doc-base" \
32+
--output="$MANUAL_PATH" \
33+
--lang="$LANGUAGE"
34+
35+
if [ ! -f "$MANUAL_PATH" ]; then
36+
echo "❌ Failed to generate $MANUAL_PATH"
37+
exit 1
38+
fi
39+
echo "✅ Generated $MANUAL_PATH"
40+
41+
# Verify PHP package presence
42+
if [ ! -d "$PHD_DIR/phpdotnet/phd/Package/PHP" ]; then
43+
echo "❌ PHP package not found in $PHD_DIR/phpdotnet/phd/Package/PHP"
44+
exit 1
45+
fi
46+
47+
# Normalize Windows CRLF endings and adjust doc-base paths
48+
echo "🩹 Patching entity paths to use doc-base…"
49+
tr -d '\r' < "$MANUAL_PATH" > "$MANUAL_PATH.clean" && mv "$MANUAL_PATH.clean" "$MANUAL_PATH"
50+
sed -i "s#/var/www/$LANGUAGE/entities/#/var/www/doc-base/entities/#g" "$MANUAL_PATH"
51+
sed -i "s#/var/www/$LANGUAGE/version.xml#/var/www/doc-base/version.xml#g" "$MANUAL_PATH"
52+
sed -i "s#/var/www/$LANGUAGE/sources.xml#/var/www/doc-base/sources.xml#g" "$MANUAL_PATH"
53+
head -n 25 "$MANUAL_PATH"
54+
55+
# 🧩 Inclure le package PHP pour PhD
56+
export PHP_INCLUDE_PATH="$PHD_DIR/phpdotnet/phd/Package:$PHD_DIR/phpdotnet/phd/Package/PHP:$PHP_INCLUDE_PATH"
57+
58+
cd /var/www/$LANGUAGE
59+
60+
# 🏗️ Render the documentation
61+
php -d include_path="$PHP_INCLUDE_PATH" \
62+
"$PHD_DIR/render.php" \
63+
--docbook "$MANUAL_PATH" \
64+
--package "$PACKAGE" \
65+
--format "$FORMAT"
66+
67+
# 🔎 Locate the output directory
68+
OUTDIR=""
69+
for d in php-chunked-xhtml xhtml phpweb php; do
70+
if [ -d "/var/www/$LANGUAGE/output/$d" ]; then
71+
OUTDIR="/var/www/$LANGUAGE/output/$d"
72+
break
73+
fi
74+
done
75+
76+
if [ -d "$OUTDIR" ]; then
77+
echo "✅ Build complete: $OUTDIR"
78+
else
79+
echo "❌ No output directory found in /var/www/$LANGUAGE/output/"
80+
ls -R "/var/www/$LANGUAGE/output" || true
81+
exit 1
82+
fi

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,48 @@ already exist.
3131
You can also build the `web` version of the documentation with `make php`
3232
and the output will be placed in output/php-web
3333

34+
### 🐋 Building with Docker Compose (alternative modern setup)
35+
36+
A `compose.yaml` file is available for contributors who prefer a simple,
37+
cross-platform Docker workflow instead of `make`.
38+
39+
It builds and serves the PHP manual locally in any translation
40+
(English by default, or another language via `LANGUAGE`).
41+
42+
#### Prerequisites
43+
- Docker ≥ 24 and Docker Compose ([install guide](https://docs.docker.com/get-docker/))
44+
- Local clone structure:
45+
```
46+
php-doc/
47+
├─ doc-base/ ← common build files, scripts, entities, configure.php
48+
├─ doc-en/ ← English manual (contains this Docker setup)
49+
└─ doc-fr/ ← French manual or you official language repository (doc-es, doc-ja...)
50+
```
51+
52+
#### Usage
53+
From inside `php-doc/doc-en/`:
54+
55+
```bash
56+
# Default build (English)
57+
docker compose up --build
58+
```
59+
To build another translation:
60+
**Linux / macOS**
61+
```
62+
LANGUAGE=fr docker compose up --build
63+
```
64+
**Windows PowerShell**
65+
```bash
66+
$env:LANGUAGE="fr"; docker compose up --build
67+
68+
Remove-Item Env:LANGUAGE # To remove the variable:
69+
```
70+
The process will:
71+
72+
1. Build a minimal PHP 8.2 environment with PhD
73+
2. Generate `.manual.xml` and render the manual in HTML (php-chunked-xhtml).
74+
3. Start a local PHP web server on http://localhost:8000
75+
3476
## Translations
3577

3678
For the translations of this documentation, see:

compose.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
phpdoc:
3+
build:
4+
dockerfile: .docker/Dockerfile
5+
container_name: phpdoc-builder
6+
working_dir: /var/www
7+
user: "0:0"
8+
volumes:
9+
- ../doc-${LANGUAGE:-en}:/var/www/${LANGUAGE:-en}
10+
- ../doc-en:/var/www/en
11+
- ../doc-base:/var/www/doc-base
12+
command: ["${LANGUAGE:-en}", "xhtml"]
13+
14+
phpdoc-web:
15+
image: php:8.2-cli-alpine
16+
container_name: phpdoc-web
17+
working_dir: /var/www/${LANGUAGE:-en}/output
18+
volumes:
19+
- ../doc-${LANGUAGE:-en}/output/php-chunked-xhtml:/var/www/${LANGUAGE:-en}/output
20+
ports:
21+
- "8000:8000"
22+
command: ["php", "-S", "0.0.0.0:8000", "-t", "/var/www/${LANGUAGE:-en}/output"]

0 commit comments

Comments
 (0)