Skip to content

Commit 2bdfefa

Browse files
author
Tinywan
committed
feat: complete portable dist layout (runtime, root libphp/libphpx, webman-server script)
1 parent 5e61551 commit 2bdfefa

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

‎docker/entrypoint.sh‎

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,21 @@ for bin_or_lib in "$stage_dir/webman-server.bin" "$stage_dir/lib"/*.so* "$stage_
179179
fi
180180
done
181181

182-
# 确保核心运行时动态库存在
182+
# 确保核心运行时动态库存在,并复制到根目录和 lib/ 目录
183183
for required_library in 'libphpx.so*' 'libphp.so*'; do
184-
if ! find "$stage_dir/lib" -maxdepth 1 -type f -name "$required_library" | grep -q .; then
185-
# 尝试从系统目录补充
186-
find /usr -name "$required_library" -type f 2>/dev/null | while read -r sys_lib; do
187-
cp -L "$sys_lib" "$stage_dir/lib/" || true
188-
done
184+
found_lib="$(find "$stage_dir/lib" /usr -name "$required_library" -type f 2>/dev/null | head -n 1 || true)"
185+
if [[ -n "$found_lib" && -f "$found_lib" ]]; then
186+
libname="$(basename "$found_lib")"
187+
clean_libname="${libname%%.*}.so"
188+
cp -L "$found_lib" "$stage_dir/$clean_libname" || true
189+
cp -L "$found_lib" "$stage_dir/lib/$libname" || true
189190
fi
190191
done
191192

192193
# 3. 修复可执行程序和扩展的 RPATH(如果有 patchelf)
193194
if command -v patchelf &> /dev/null; then
194195
patchelf --set-rpath '$ORIGIN:$ORIGIN/lib' "$stage_dir/webman-server.bin" 2>/dev/null || true
195-
for solib in "$stage_dir"/lib/*.so*; do
196+
for solib in "$stage_dir"/*.so "$stage_dir"/lib/*.so*; do
196197
[[ -f "$solib" ]] && patchelf --set-rpath '$ORIGIN:$ORIGIN/lib' "$solib" 2>/dev/null || true
197198
done
198199
for extsolib in "$stage_dir"/ext/*.so; do
@@ -237,21 +238,43 @@ while IFS= read -r line || [[ -n "$line" ]]; do
237238
fi
238239
done < "$stage_dir/php.ini"
239240

240-
# 5. 生成标准可移植启动脚本 start.sh
241+
# 5. 生成标准可移植启动包装脚本 webman-server 与 start.sh
242+
install -m 0755 /dev/stdin "$stage_dir/webman-server" <<'SCRIPT'
243+
#!/usr/bin/env sh
244+
set -eu
245+
246+
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
247+
cd "$SCRIPT_DIR"
248+
249+
export PHPRC="$SCRIPT_DIR"
250+
export LD_LIBRARY_PATH="$SCRIPT_DIR:$SCRIPT_DIR/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
251+
exec "$SCRIPT_DIR/webman-server.bin" "$@"
252+
SCRIPT
253+
241254
install -m 0755 /dev/stdin "$stage_dir/start.sh" <<'SCRIPT'
242255
#!/usr/bin/env bash
243-
set -euo pipefail
244-
readonly app_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
245-
cd "$app_dir"
246-
export PHPRC="$app_dir"
247-
export LD_LIBRARY_PATH="$app_dir:$app_dir/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
248-
exec "$app_dir/webman-server.bin" "$@"
256+
set -e
257+
258+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
259+
cd "$SCRIPT_DIR"
260+
261+
export PHPRC="$SCRIPT_DIR"
262+
export LD_LIBRARY_PATH="$SCRIPT_DIR:$SCRIPT_DIR/lib:$LD_LIBRARY_PATH"
263+
264+
if [ ! -f "$SCRIPT_DIR/webman-server" ]; then
265+
echo "[ERROR] webman-server executable not found in $SCRIPT_DIR!"
266+
exit 1
267+
fi
268+
269+
chmod +x "$SCRIPT_DIR/webman-server" 2>/dev/null || true
270+
exec "$SCRIPT_DIR/webman-server" "$@"
249271
SCRIPT
250272

251-
# 6. 复制运行时业务资源
273+
# 6. 复制运行时业务资源并确保 runtime 目录
252274
for resource in config public; do
253275
[[ -d "$resource" ]] && cp -a "$resource" "$stage_dir/"
254276
done
277+
mkdir -p "$stage_dir/runtime/logs" "$stage_dir/runtime/views"
255278
if [[ -d app/view ]]; then mkdir -p "$stage_dir/app"; cp -a app/view "$stage_dir/app/"; fi
256279
if [[ -f app/functions.php ]]; then copy_file app/functions.php "$stage_dir/app/functions.php"; fi
257280
[[ -f "$build_dir/build-manifest.json" ]] && copy_file "$build_dir/build-manifest.json" "$stage_dir/build-manifest.json"

0 commit comments

Comments
 (0)