Skip to content

Commit 59500e1

Browse files
author
lacatoire
committed
docker doc setup
1 parent c80bf6d commit 59500e1

File tree

4 files changed

+210
-12
lines changed

4 files changed

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