Skip to content

Commit 19bcca8

Browse files
committed
Enable zlib in runtime image and pin phpdoc-md for PHP 5.3
1 parent 5b862a1 commit 19bcca8

5 files changed

Lines changed: 36 additions & 14 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ RUN /usr/local/bin/setup-phpdocumentor-cache.sh /opt/phpdocumentor-cache "$PHPDO
1414

1515
FROM php:${PHP_VERSION}-cli
1616

17+
COPY --chmod=0755 bin/install-runtime-zlib.sh /usr/local/bin/install-runtime-zlib.sh
18+
RUN /usr/local/bin/install-runtime-zlib.sh \
19+
&& rm -f /usr/local/bin/install-runtime-zlib.sh
20+
1721
COPY --from=phpdocmd-builder /opt/phpdoc-md /opt/phpdoc-md
1822
COPY --from=phpdocmd-builder /opt/phpdocumentor-cache /opt/phpdocumentor-cache
1923
COPY --chmod=0755 bin/entrypoint.sh /usr/local/bin/entrypoint.sh

bin/entrypoint.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ else
6464
PHPDOC_VERSION_NO_PREFIX=${PHPDOC_VERSION#v}
6565
CACHED_PHPDOC_TAR_GZ_PATH="$PHPDOC_CACHE_PATH/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.tgz"
6666
CACHED_PHPDOC_PHAR_PATH="$PHPDOC_CACHE_PATH/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.phar"
67-
CACHED_PHPDOC_BIN_PATH="$PHPDOC_CACHE_PATH/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}/bin/phpdoc"
6867
PHPDOC_TAR_GZ_URL="https://github.com/phpDocumentor/phpDocumentor/releases/download/v${PHPDOC_VERSION_NO_PREFIX}/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.tgz"
6968
PHPDOC_PHAR_URL="https://github.com/phpDocumentor/phpDocumentor/releases/download/v${PHPDOC_VERSION_NO_PREFIX}/phpDocumentor.phar"
7069

7170
if ! php -r 'exit(extension_loaded("zlib") ? 0 : 1);'; then
72-
if [[ -f "$CACHED_PHPDOC_BIN_PATH" ]]; then
73-
PHPDOC_COMMAND=(php "$CACHED_PHPDOC_BIN_PATH")
74-
PHPDOC_COMMAND_SET=1
75-
elif [[ -f "$CACHED_PHPDOC_PHAR_PATH" ]]; then
71+
if [[ -f "$CACHED_PHPDOC_PHAR_PATH" ]]; then
7672
cp "$CACHED_PHPDOC_PHAR_PATH" "$PHPDOC_PHAR_PATH"
7773
PHPDOC_COMMAND=(php "$PHPDOC_PHAR_PATH" run)
7874
PHPDOC_COMMAND_SET=1

bin/install-runtime-zlib.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
if php -r 'exit(extension_loaded("zlib") ? 0 : 1);'; then
6+
exit 0
7+
fi
8+
9+
if php -d extension=zlib.so -r 'exit(function_exists("gzcompress") ? 0 : 1);'; then
10+
echo "extension=zlib.so" > /usr/local/etc/php/conf.d/zz-zlib.ini
11+
exit 0
12+
fi
13+
14+
if ! command -v apt-get >/dev/null 2>&1 || ! command -v docker-php-ext-install >/dev/null 2>&1; then
15+
echo "Unable to install zlib extension automatically." >&2
16+
exit 1
17+
fi
18+
19+
apt-get update
20+
if [ -n "${PHPIZE_DEPS:-}" ]; then
21+
apt-get install -y --no-install-recommends $PHPIZE_DEPS zlib1g-dev
22+
else
23+
apt-get install -y --no-install-recommends zlib1g-dev
24+
fi
25+
docker-php-ext-install zlib
26+
rm -rf /var/lib/apt/lists/*
27+
28+
php -r 'if (!function_exists("gzcompress")) { fwrite(STDERR, "zlib extension is required but unavailable.\n"); exit(1); }'

bin/setup-phpdoc-md.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ set -euo pipefail
44

55
TARGET_DIR=${1:-/opt/phpdoc-md}
66
COMPOSER_HOME_DIR=${2:-/tmp/composer}
7+
PHPDOC_MD_REF=${3:-0.1.1}
78

89
GIT_SSH_OPTIONS="ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5"
910

10-
if ! GIT_SSH_COMMAND="$GIT_SSH_OPTIONS" git clone --depth 1 git@github.com:evert/phpdoc-md.git "$TARGET_DIR"; then
11-
git clone --depth 1 https://github.com/evert/phpdoc-md.git "$TARGET_DIR"
11+
if ! GIT_SSH_COMMAND="$GIT_SSH_OPTIONS" git clone --depth 1 --branch "$PHPDOC_MD_REF" git@github.com:evert/phpdoc-md.git "$TARGET_DIR"; then
12+
git clone --depth 1 --branch "$PHPDOC_MD_REF" https://github.com/evert/phpdoc-md.git "$TARGET_DIR"
1213
fi
1314

1415
php -r '$composer = json_decode(file_get_contents($argv[1]), true); unset($composer["require-dev"]); file_put_contents($argv[1], json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);' "$TARGET_DIR/composer.json"

bin/setup-phpdocumentor-cache.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ PHPDOC_TAR_GZ_URL="https://github.com/phpDocumentor/phpDocumentor/releases/downl
99
PHPDOC_PHAR_URL="https://github.com/phpDocumentor/phpDocumentor/releases/download/v${PHPDOC_VERSION_NO_PREFIX}/phpDocumentor.phar"
1010
TARGET_FILE="${TARGET_DIR}/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.tgz"
1111
PHAR_TARGET_FILE="${TARGET_DIR}/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}.phar"
12-
EXTRACTED_ROOT="${TARGET_DIR}/phpDocumentor-${PHPDOC_VERSION_NO_PREFIX}"
13-
XML_WRITER_PATH="${EXTRACTED_ROOT}/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml.php"
1412

1513
mkdir -p "$TARGET_DIR"
1614

1715
php -r '$url = isset($argv[1]) ? $argv[1] : null; $target = isset($argv[2]) ? $argv[2] : null; if (!$url || !$target) { fwrite(STDERR, "Missing download arguments\n"); exit(1); } $data = @file_get_contents($url); if ($data === false) { fwrite(STDERR, "Unable to download file: $url\n"); exit(1); } if (@file_put_contents($target, $data) === false) { fwrite(STDERR, "Unable to write file: $target\n"); exit(1); }' "$PHPDOC_TAR_GZ_URL" "$TARGET_FILE"
1816
php -r '$url = isset($argv[1]) ? $argv[1] : null; $target = isset($argv[2]) ? $argv[2] : null; if (!$url || !$target) { fwrite(STDERR, "Missing download arguments\n"); exit(1); } $data = @file_get_contents($url); if ($data === false) { fwrite(STDERR, "Unable to download file: $url\n"); exit(1); } if (@file_put_contents($target, $data) === false) { fwrite(STDERR, "Unable to write file: $target\n"); exit(1); }' "$PHPDOC_PHAR_URL" "$PHAR_TARGET_FILE"
19-
20-
rm -rf "$EXTRACTED_ROOT"
21-
php -r '$archive = isset($argv[1]) ? $argv[1] : null; $target = isset($argv[2]) ? $argv[2] : null; if (!$archive || !$target) { fwrite(STDERR, "Missing extract arguments\n"); exit(1); } if (!is_dir(dirname($target)) && !mkdir(dirname($target), 0777, true)) { fwrite(STDERR, "Unable to create target parent directory\n"); exit(1); } $root = dirname($target); $tarPath = preg_replace("/\\.tgz$/", ".tar", $archive); if ($tarPath === null) { fwrite(STDERR, "Unable to derive tar path\n"); exit(1); } try { if (!file_exists($tarPath)) { $tgz = new PharData($archive); $tgz->decompress(); } $tar = new PharData($tarPath); $tar->extractTo($root, null, true); } catch (Exception $e) { fwrite(STDERR, "Unable to extract phpDocumentor archive: " . $e->getMessage() . "\n"); exit(1); }' "$TARGET_FILE" "$EXTRACTED_ROOT"
22-
23-
php -r '$path = isset($argv[1]) ? $argv[1] : null; if (!$path || !file_exists($path)) { fwrite(STDERR, "Xml writer file not found: " . ($path ?: "null") . "\n"); exit(1); } $content = file_get_contents($path); if ($content === false) { fwrite(STDERR, "Unable to read xml writer file\n"); exit(1); } $needle = '\''base64_encode(gzcompress($file->getSource()))'\''; $replacement = '\''(function_exists("gzcompress") ? base64_encode(gzcompress($file->getSource())) : "")'\''; $updated = str_replace($needle, $replacement, $content, $count); if ($count < 1) { fwrite(STDERR, "Unable to patch xml writer for missing zlib support\n"); exit(1); } if (file_put_contents($path, $updated) === false) { fwrite(STDERR, "Unable to write patched xml writer file\n"); exit(1); }' "$XML_WRITER_PATH"

0 commit comments

Comments
 (0)