feat: expand EasyCode software factory workflows

This commit is contained in:
王鹏
2026-07-15 12:48:50 +08:00
parent fcfa4374d7
commit 79dea897bc
1108 changed files with 163774 additions and 21593 deletions

View File

@@ -0,0 +1,16 @@
FROM maven:3.9.9-eclipse-temurin-17
RUN apt-get update \
&& apt-get install -y --no-install-recommends nodejs npm unzip curl chromium \
&& rm -rf /var/lib/apt/lists/*
COPY entrypoint.sh /usr/local/bin/easycode-preview-worker
RUN chmod 0555 /usr/local/bin/easycode-preview-worker
ENV HOME=/tmp \
MAVEN_OPTS="-Dmaven.repo.local=/tmp/.m2/repository" \
npm_config_cache=/tmp/.npm
EXPOSE 8080 8081
ENTRYPOINT ["/usr/local/bin/easycode-preview-worker"]

View File

@@ -0,0 +1,20 @@
# Preview Worker Deployment
The web application only enqueues persistent preview jobs. A separate deployment must run the same application with:
```text
EASYCODE_PREVIEW_EXECUTION_MODE=persistent
EASYCODE_PREVIEW_WORKER_ENABLED=true
EASYCODE_PREVIEW_WORKER_ROOT=/data/preview-worker
EASYCODE_PREVIEW_DOCKER_IMAGE=easycode/preview-worker:v1
```
Build the runtime image:
```bash
docker build -t easycode/preview-worker:v1 deploy/preview-worker
```
The web and Worker deployments must share the control database and the configured Worker root volume so the authenticated screenshot endpoint can read `output/screenshot.png`. Only the Worker deployment needs Docker access. The web deployment must use `EASYCODE_PREVIEW_EXECUTION_MODE=persistent` and keep `EASYCODE_PREVIEW_WORKER_ENABLED=false`. Local development defaults to `host` mode and does not require Docker.
The runtime publishes one constrained container port, waits for `/output/ready`, stores bounded logs and a Chromium screenshot, and is stopped by the durable Job TTL. Docker failures remain explicit; there is no host-process fallback.

View 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