feat: expand EasyCode software factory workflows
This commit is contained in:
61
RuoYi-Vue/deploy/preview-worker/entrypoint.sh
Normal file
61
RuoYi-Vue/deploy/preview-worker/entrypoint.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SOURCE_ZIP=/input/source.zip
|
||||
WORKSPACE=/tmp/workspace
|
||||
OUTPUT=/output
|
||||
|
||||
mkdir -p "$WORKSPACE" "$OUTPUT"
|
||||
unzip -q "$SOURCE_ZIP" -d "$WORKSPACE"
|
||||
|
||||
BACKEND_DIR=$(find "$WORKSPACE" -name pom.xml -not -path '*/node_modules/*' -printf '%h\n' | head -n 1)
|
||||
FRONTEND_DIR=$(find "$WORKSPACE" -name package.json -not -path '*/node_modules/*' -printf '%h\n' | head -n 1 || true)
|
||||
|
||||
if [[ -z "${BACKEND_DIR:-}" ]]; then
|
||||
echo "Generated source has no Maven backend" | tee "$OUTPUT/error.log"
|
||||
exit 21
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$BACKEND_DIR"
|
||||
SERVER_PORT=8081 mvn -B -DskipTests spring-boot:run
|
||||
) >"$OUTPUT/backend.log" 2>&1 &
|
||||
BACKEND_PID=$!
|
||||
|
||||
READY_URL=http://127.0.0.1:8081
|
||||
FRONTEND_PID=
|
||||
if [[ -n "${FRONTEND_DIR:-}" ]]; then
|
||||
(
|
||||
cd "$FRONTEND_DIR"
|
||||
if [[ -f package-lock.json ]]; then npm ci; else npm install; fi
|
||||
VITE_APP_API_BASE_URL=http://127.0.0.1:8081 \
|
||||
VUE_APP_API_BASE_URL=http://127.0.0.1:8081 \
|
||||
npm run dev -- --host 0.0.0.0 --port 8080
|
||||
) >"$OUTPUT/frontend.log" 2>&1 &
|
||||
FRONTEND_PID=$!
|
||||
READY_URL=http://127.0.0.1:8080
|
||||
fi
|
||||
|
||||
for _ in $(seq 1 180); do
|
||||
if curl -fsS "$READY_URL" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if ! kill -0 "$BACKEND_PID" 2>/dev/null; then
|
||||
echo "Backend exited before preview became ready" | tee "$OUTPUT/error.log"
|
||||
exit 22
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
curl -fsS "$READY_URL" >/dev/null
|
||||
chromium --headless --no-sandbox --disable-gpu --hide-scrollbars \
|
||||
--window-size=1440,900 --screenshot="$OUTPUT/screenshot.png" "$READY_URL" \
|
||||
>"$OUTPUT/screenshot.log" 2>&1
|
||||
printf '{"status":"RUNNING","url":"%s"}\n' "$READY_URL" >"$OUTPUT/ready"
|
||||
|
||||
if [[ -n "${FRONTEND_PID:-}" ]]; then
|
||||
wait -n "$BACKEND_PID" "$FRONTEND_PID"
|
||||
else
|
||||
wait "$BACKEND_PID"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user