Skip to content

Commit f3772ca

Browse files
author
lacatoire
committed
docker doc setup
1 parent 2def8c3 commit f3772ca

File tree

4 files changed

+216
-12
lines changed

4 files changed

+216
-12
lines changed

.docker/Dockerfile

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
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+
# 🔧 PhD dependencies
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+
# 📦 Install 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
1734

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}
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"]

.docker/entrypoint.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
# 🧩 Step 1. Verify prerequisites (avoid silent empty mounts)
14+
echo "🔍 Checking required documentation repositories..."
15+
16+
# Check doc-base presence (must contain configure.php)
17+
if [ ! -f /var/www/doc-base/configure.php ]; then
18+
echo "❌ doc-base is missing or incomplete!"
19+
echo "👉 Please clone it before running Docker:"
20+
echo " git clone https://github.com/php/doc-base ../doc-base"
21+
echo ""
22+
exit 1
23+
fi
24+
25+
# Check language documentation presence
26+
if [ ! -d "/var/www/$LANGUAGE" ] || [ ! -f "/var/www/$LANGUAGE/sources.xml" ]; then
27+
echo "❌ doc-${LANGUAGE} is missing or incomplete!"
28+
echo "👉 Please clone it before running Docker:"
29+
echo " git clone https://github.com/php/doc-${LANGUAGE} ../doc-${LANGUAGE}"
30+
echo ""
31+
echo "💡 Tip: remove any empty folders and rebuild containers with '--force-recreate'."
32+
exit 1
33+
fi
34+
35+
done
36+
echo "✅ All prerequisites found."
37+
echo ""
38+
39+
echo "🧩 Building PHP documentation..."
40+
echo "Language: $LANGUAGE"
41+
echo "Format: $FORMAT"
42+
echo "Docbook: $MANUAL_PATH"
43+
44+
# Add the PHP package to the include_path for PhD.
45+
export PHP_INCLUDE_PATH="$PHD_DIR/phpdotnet/phd/Package:$PHD_DIR/phpdotnet/phd/Package/PHP:$PHP_INCLUDE_PATH"
46+
47+
# 🧹 Clean if necessary
48+
if [ -f "$MANUAL_PATH" ]; then
49+
echo "🧹 Removing old .manual.xml..."
50+
rm -f "$MANUAL_PATH" || true
51+
fi
52+
53+
echo "ℹ️ Generating .manual.xml for $LANGUAGE..."
54+
cd /var/www/doc-base
55+
php configure.php \
56+
--disable-segfault-error \
57+
--basedir="/var/www/doc-base" \
58+
--output="$MANUAL_PATH" \
59+
--lang="$LANGUAGE"
60+
61+
if [ ! -f "$MANUAL_PATH" ]; then
62+
echo "❌ Failed to generate $MANUAL_PATH"
63+
exit 1
64+
fi
65+
echo "✅ Generated $MANUAL_PATH"
66+
67+
# Verify PHP package presence
68+
if [ ! -d "$PHD_DIR/phpdotnet/phd/Package/PHP" ]; then
69+
echo "❌ PHP package not found in $PHD_DIR/phpdotnet/phd/Package/PHP"
70+
exit 1
71+
fi
72+
73+
# Normalize Windows CRLF endings and adjust doc-base paths
74+
echo "🩹 Patching entity paths to use doc-base…"
75+
tr -d '\r' < "$MANUAL_PATH" > "$MANUAL_PATH.clean" && mv "$MANUAL_PATH.clean" "$MANUAL_PATH"
76+
sed -i "s#/var/www/$LANGUAGE/entities/#/var/www/doc-base/entities/#g" "$MANUAL_PATH"
77+
sed -i "s#/var/www/$LANGUAGE/version.xml#/var/www/doc-base/version.xml#g" "$MANUAL_PATH"
78+
sed -i "s#/var/www/$LANGUAGE/sources.xml#/var/www/doc-base/sources.xml#g" "$MANUAL_PATH"
79+
head -n 25 "$MANUAL_PATH"
80+
81+
# 🧩 Include the PHP package for PhD
82+
export PHP_INCLUDE_PATH="$PHD_DIR/phpdotnet/phd/Package:$PHD_DIR/phpdotnet/phd/Package/PHP:$PHP_INCLUDE_PATH"
83+
84+
cd /var/www/$LANGUAGE
85+
86+
# 🏗️ Render the documentation
87+
php -d include_path="$PHP_INCLUDE_PATH" \
88+
"$PHD_DIR/render.php" \
89+
--docbook "$MANUAL_PATH" \
90+
--package "$PACKAGE" \
91+
--format "$FORMAT"
92+
93+
# 🔎 Locate the output directory
94+
OUTDIR=""
95+
for d in php-chunked-xhtml xhtml phpweb php; do
96+
if [ -d "/var/www/$LANGUAGE/output/$d" ]; then
97+
OUTDIR="/var/www/$LANGUAGE/output/$d"
98+
break
99+
fi
100+
done
101+
102+
if [ -d "$OUTDIR" ]; then
103+
echo "✅ Build complete: $OUTDIR"
104+
echo "View the documentation on http://localhost:8000"
105+
else
106+
echo "❌ No output directory found in /var/www/$LANGUAGE/output/"
107+
ls -R "/var/www/$LANGUAGE/output" || true
108+
exit 1
109+
fi

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,50 @@ 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+
44+
- Docker ≥ 24 and Docker Compose ([install guide](https://docs.docker.com/get-docker/))
45+
- Local clone structure:
46+
```
47+
php-doc/
48+
├─ doc-base/ ← common build files, scripts, entities, configure.php
49+
├─ doc-en/ ← English manual (contains this Docker setup)
50+
└─ doc-fr/ ← French manual or your official language repository (doc-es, doc-ja...)
51+
```
52+
53+
#### Usage
54+
55+
From inside `php-doc/doc-en/`:
56+
57+
```bash
58+
# Default build (English)
59+
docker compose up --build
60+
```
61+
To build another translation:
62+
**Linux / macOS**
63+
```
64+
LANGUAGE=fr docker compose up --build
65+
```
66+
**Windows PowerShell**
67+
```bash
68+
$env:LANGUAGE="fr"; docker compose up --build
69+
70+
Remove-Item Env:LANGUAGE # Revert back to English
71+
```
72+
The process will:
73+
74+
1. Build a minimal PHP 8.2 environment with PhD.
75+
2. Generate `.manual.xml` and render the manual in HTML (php-chunked-xhtml).
76+
3. Start a local PHP web server on http://localhost:8000 where you can view the documentation.
77+
3478
## Translations
3579

3680
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)