refactor(lab): drive docker from python so the cli works on windows and posix without bash

This commit is contained in:
ZSecurity
2026-10-24 14:07:06 +07:00
parent 8366583c43
commit 476b3d2078
8 changed files with 305 additions and 54 deletions
+6 -31
View File
@@ -1,34 +1,9 @@
#!/usr/bin/env bash
set -eu
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -W)
ROOT=$(cd "$HERE/.." && pwd -W)
IMAGE=${IMAGE:-php:8.4.26-apache}
NAME=${NAME:-p2s-lab}
PORT=${PORT:-18110}
NET=${NET:-}
docker rm -f "$NAME" >/dev/null 2>&1 || true
mkdir -p "$ROOT/out"
NETARG=""
if [ -n "$NET" ]; then
docker network create "$NET" >/dev/null 2>&1 || true
NETARG="--network $NET"
HERE=$(cd "$(dirname "$0")" && pwd)
cd "$HERE/.."
PY=${PYTHON:-}
if [ -z "$PY" ]; then
if command -v python >/dev/null 2>&1; then PY=python; else PY=python3; fi
fi
docker run -d --name "$NAME" $NETARG \
-p "127.0.0.1:$PORT:80" \
-v "$HERE/index.php:/var/www/html/index.php:ro" \
-v "$HERE/apache-single-worker.conf:/etc/apache2/conf-enabled/zz-p2s.conf:ro" \
-v "$ROOT/out:/out" \
"$IMAGE" /bin/sh -c 'cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
chown -R www-data:www-data /out 2>/dev/null || true
exec apache2-foreground' >/dev/null
for _ in $(seq 1 60); do
if curl -s -m 2 "http://127.0.0.1:$PORT/index.php" >/dev/null 2>&1; then
break
fi
sleep 0.5
done
echo "target: $(curl -s -m 3 "http://127.0.0.1:$PORT/index.php")"
exec "$PY" -m poc lab --up-only "$@"