chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,208 @@
|
||||
# Build extension and daemon from the same pinned source on the runtime architecture.
|
||||
FROM --platform=$TARGETPLATFORM node:24-bookworm-slim@sha256:ba849c60be29959425b8734d57b8b4b7d56f98edd9504c9af091d5281095a71e AS browserskill
|
||||
WORKDIR /build
|
||||
# Use the same optional Debian mirror as the Go builder and runtime stages.
|
||||
ARG APK_MIRROR_ARG
|
||||
# This base image has no CA certificates. Install them from the original HTTP
|
||||
# Debian source before swapping in a mirror: mirrors.tencent.com redirects
|
||||
# apt to HTTPS, and that handshake fails without a trust store.
|
||||
RUN if [ -n "$APK_MIRROR_ARG" ]; then \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends ca-certificates && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
sed -i "s@deb.debian.org@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi && \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends git python3 ca-certificates curl build-essential cmake pkg-config && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo
|
||||
ENV PATH=/usr/local/cargo/bin:$PATH
|
||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
|
||||
COPY scripts/build_browserskill.sh scripts/browserskill-release.json ./scripts/
|
||||
# 离线快速通道:优先使用仓库内预构建产物(air-gapped/网络受限环境无需 clone GitHub)
|
||||
COPY artifacts/browserskill ./artifacts/browserskill/
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
RUN bash scripts/build_browserskill.sh /opt/academy/browserskill "${TARGETOS}/${TARGETARCH}"
|
||||
|
||||
# Build stage
|
||||
FROM golang:1.26-bookworm AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 通过构建参数接收敏感信息
|
||||
ARG GOPRIVATE_ARG
|
||||
ARG GOPROXY_ARG
|
||||
ARG GOSUMDB_ARG=off
|
||||
ARG APK_MIRROR_ARG
|
||||
|
||||
# 设置Go环境变量
|
||||
ENV GOPRIVATE=${GOPRIVATE_ARG}
|
||||
ENV GOPROXY=${GOPROXY_ARG}
|
||||
ENV GOSUMDB=${GOSUMDB_ARG}
|
||||
|
||||
# Install dependencies
|
||||
RUN if [ -n "$APK_MIRROR_ARG" ]; then \
|
||||
sed -i "s@deb.debian.org@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi && \
|
||||
apt-get update && \
|
||||
apt-get install -y git build-essential libsqlite3-dev curl
|
||||
|
||||
# Install migrate tool
|
||||
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
|
||||
|
||||
# Copy go mod files. go.mod replace-points anydoc at ./third_party/anydoc-go,
|
||||
# so that module's go.mod must exist before `go mod download`.
|
||||
COPY go.mod go.sum ./
|
||||
COPY third_party/anydoc-go/go.mod third_party/anydoc-go/go.mod
|
||||
RUN go mod download
|
||||
COPY cmd/download cmd/download
|
||||
# DuckDB extensions (spatial/excel): prefer a local seed tarball exported from
|
||||
# a previously built image (artifacts/duckdb_extensions/seed.tar) —
|
||||
# extensions.duckdb.org is often unreachable from some networks. Fall back to
|
||||
# the online INSTALL path when the seed is absent.
|
||||
COPY artifacts/duckdb_extensions/seed.tar /tmp/duckdb-seed.tar
|
||||
RUN if [ -s /tmp/duckdb-seed.tar ]; then \
|
||||
mkdir -p /root/.duckdb && tar -xf /tmp/duckdb-seed.tar -C /root/.duckdb; \
|
||||
ls -la /root/.duckdb/extensions/*/linux_amd64; \
|
||||
else \
|
||||
go run cmd/download/duckdb/duckdb.go; \
|
||||
fi
|
||||
COPY . .
|
||||
RUN bash ./scripts/copy-licenses.sh /license-bundle
|
||||
|
||||
# Get version and commit info for build injection
|
||||
ARG VERSION_ARG
|
||||
ARG COMMIT_ID_ARG
|
||||
ARG BUILD_TIME_ARG
|
||||
ARG GO_VERSION_ARG
|
||||
|
||||
# Set build-time variables
|
||||
ENV VERSION=${VERSION_ARG}
|
||||
ENV COMMIT_ID=${COMMIT_ID_ARG}
|
||||
ENV BUILD_TIME=${BUILD_TIME_ARG}
|
||||
ENV GO_VERSION=${GO_VERSION_ARG}
|
||||
|
||||
# Link the anydoc parser engine (office docs converted in-process, no
|
||||
# Python docreader). Default on so Hub / compose images ship a working
|
||||
# engine; pass WITH_ANYDOC=0 to skip the Rust toolchain (~few minutes and
|
||||
# ~1 GB of build-stage layers).
|
||||
ARG WITH_ANYDOC=1
|
||||
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo
|
||||
ENV PATH=/usr/local/cargo/bin:$PATH
|
||||
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
||||
--mount=type=cache,target=/usr/local/cargo/git \
|
||||
if [ "$WITH_ANYDOC" = "1" ]; then \
|
||||
curl --http1.1 --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh \
|
||||
-o /tmp/rustup-init.sh \
|
||||
|| curl --http1.1 --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
||||
-o /tmp/rustup-init.sh; \
|
||||
ok=0; \
|
||||
for srv in https://mirrors.ustc.edu.cn/rust-static https://rsproxy.cn https://static.rust-lang.org; do \
|
||||
case "$srv" in \
|
||||
https://mirrors.ustc.edu.cn/rust-static) upd=https://mirrors.ustc.edu.cn/rust-static/rustup ;; \
|
||||
https://rsproxy.cn) upd=https://rsproxy.cn/rustup ;; \
|
||||
*) upd=https://static.rust-lang.org/rustup ;; \
|
||||
esac; \
|
||||
echo "==> Trying rust toolchain mirror: $srv"; \
|
||||
if RUSTUP_DIST_SERVER="$srv" RUSTUP_UPDATE_ROOT="$upd" \
|
||||
sh /tmp/rustup-init.sh -y --profile minimal --default-toolchain stable; then \
|
||||
ok=1; break; \
|
||||
fi; \
|
||||
done; \
|
||||
[ "$ok" = "1" ] && ./scripts/build-anydoc-lib.sh; \
|
||||
fi
|
||||
|
||||
# Build the application with version info. Mount the Go build cache as well as
|
||||
# the module cache: `COPY . .` invalidates this layer on every source change,
|
||||
# and without the mount each rebuild regenerates the whole compile cache inside
|
||||
# the layer (~2.7 GB), which occupies disk locally and is uploaded to the CI
|
||||
# layer cache. Mounted, the cache lives outside the layer and repeated builds
|
||||
# reuse compiled objects instead of recompiling from scratch.
|
||||
RUN if [ "$WITH_ANYDOC" = "1" ]; then \
|
||||
make build-prod GO_BUILD_TAGS=anydoc; \
|
||||
else \
|
||||
make build-prod; \
|
||||
fi
|
||||
RUN cp -r /go/pkg/mod/github.com/yanyiwu/ /app/yanyiwu/
|
||||
|
||||
# Final stage
|
||||
FROM debian:12.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ARG APK_MIRROR_ARG
|
||||
# PyPI 镜像(国内网络直连 pypi.org 常超时;由 compose 传入国内源,留空回退官方源)
|
||||
ARG PIP_INDEX_ARG
|
||||
# apt bootstrap 镜像(须为不跳转 HTTPS 的纯 HTTP 源,如 mirrors.aliyun.com)
|
||||
ARG BOOTSTRAP_MIRROR_ARG
|
||||
|
||||
# Pairing derives the gateway URL from the user's page origin by default.
|
||||
ENV BROWSERSKILL_BINARY=/opt/academy/browserskill/bsk \
|
||||
BROWSERSKILL_EXTENSION_PATH=/opt/academy/browserskill/browser-skill-academy-0.3.1.zip
|
||||
COPY --from=browserskill /opt/academy/browserskill /opt/academy/browserskill
|
||||
|
||||
# Create a non-root user first
|
||||
RUN useradd -m -s /bin/bash appuser
|
||||
|
||||
# First, install ca-certificates via an HTTP-only bootstrap mirror (国内直连官方源
|
||||
# 速率极慢;主镜像会 302 跳 HTTPS 而此刻尚无信任库,故 bootstrap 需用不跳转的 HTTP 源),
|
||||
# 装好信任库后立即把源切到 APK_MIRROR_ARG 供后续步骤使用
|
||||
RUN if [ -n "$BOOTSTRAP_MIRROR_ARG" ]; then \
|
||||
sed -i "s@deb.debian.org@${BOOTSTRAP_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi && \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends ca-certificates && \
|
||||
if [ -n "$APK_MIRROR_ARG" ]; then \
|
||||
sed -i "s@${BOOTSTRAP_MIRROR_ARG:-deb.debian.org}@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Then switch to mirror if specified and install other packages
|
||||
RUN if [ -n "$APK_MIRROR_ARG" ]; then \
|
||||
sed -i "s@deb.debian.org@${APK_MIRROR_ARG}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi && \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential postgresql-client default-mysql-client tzdata sed curl bash vim wget \
|
||||
libsqlite3-0 \
|
||||
python3 python3-pip python3-dev libffi-dev libssl-dev \
|
||||
nodejs npm \
|
||||
gosu \
|
||||
ffmpeg && \
|
||||
python3 -m pip install --break-system-packages -i ${PIP_INDEX_ARG:-https://pypi.org/simple} --upgrade pip setuptools wheel && \
|
||||
# uv 通过 PyPI 镜像安装(uvx 由 pip 装入 /usr/local/bin;官方 astral.sh 安装脚本在受限网络不可达)
|
||||
python3 -m pip install --break-system-packages -i ${PIP_INDEX_ARG:-https://pypi.org/simple} uv && \
|
||||
chown -R appuser:appuser /home/appuser && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create data directories and set permissions
|
||||
RUN mkdir -p /data/files && \
|
||||
chown -R appuser:appuser /app /data/files
|
||||
|
||||
# Copy migrate tool from builder stage
|
||||
COPY --from=builder /go/bin/migrate /usr/local/bin/
|
||||
COPY --from=builder /app/yanyiwu/ /go/pkg/mod/github.com/yanyiwu/
|
||||
|
||||
# Copy the binary from the builder stage
|
||||
COPY --from=builder /app/config ./config
|
||||
COPY --from=builder /app/scripts ./scripts
|
||||
COPY --from=builder /app/migrations ./migrations
|
||||
COPY --from=builder /app/dataset/samples ./dataset/samples
|
||||
COPY --from=builder /root/.duckdb /home/appuser/.duckdb
|
||||
COPY --from=builder /app/Academy .
|
||||
COPY --from=builder /license-bundle/ ./
|
||||
|
||||
# Copy and make entrypoint script executable
|
||||
COPY --from=builder /app/scripts/docker-entrypoint.sh ./scripts/docker-entrypoint.sh
|
||||
|
||||
# Make scripts executable
|
||||
RUN chmod +x ./scripts/*.sh
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
ENTRYPOINT ["./scripts/docker-entrypoint.sh"]
|
||||
CMD ["./Academy"]
|
||||
@@ -0,0 +1,170 @@
|
||||
# =========================
|
||||
# 构建阶段(轻量化:仅文档解析 + 图片提取,无 OCR/VLM)
|
||||
# =========================
|
||||
FROM python:3.10.18-bookworm AS builder
|
||||
|
||||
ARG APT_MIRROR=""
|
||||
RUN if [ -n "$APT_MIRROR" ]; then \
|
||||
sed -i "s@http://deb.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list.d/debian.sources && \
|
||||
sed -i "s@http://security.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装构建依赖
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
python3-dev \
|
||||
libjpeg-dev \
|
||||
zlib1g-dev \
|
||||
libffi-dev \
|
||||
libgl1 \
|
||||
libglib2.0-0 \
|
||||
wget \
|
||||
antiword \
|
||||
curl \
|
||||
unzip \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 检查是否存在本地protoc安装包,如果存在则离线安装,否则在线安装
|
||||
ARG TARGETARCH
|
||||
COPY packages/ /app/packages/
|
||||
RUN ls -lah /app/packages/
|
||||
# 兼容 BuildKit 和传统构建:如果 TARGETARCH 为空,使用 uname 检测
|
||||
RUN if [ -z "$TARGETARCH" ]; then \
|
||||
case $(uname -m) in \
|
||||
"x86_64") TARGETARCH="amd64" ;; \
|
||||
"aarch64") TARGETARCH="arm64" ;; \
|
||||
"armv7l") TARGETARCH="arm" ;; \
|
||||
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;; \
|
||||
esac; \
|
||||
echo "[自动检测] 架构: $TARGETARCH"; \
|
||||
else \
|
||||
echo "[BuildKit] 架构: $TARGETARCH"; \
|
||||
fi && \
|
||||
case $TARGETARCH in \
|
||||
"amd64") PROTOC_ARCH="x86_64" ;; \
|
||||
"arm64") PROTOC_ARCH="aarch_64" ;; \
|
||||
"arm") PROTOC_ARCH="arm" ;; \
|
||||
*) echo "Unsupported architecture for protoc: $TARGETARCH" && exit 1 ;; \
|
||||
esac && \
|
||||
PROTOC_PACKAGE="protoc-3.19.4-linux-${PROTOC_ARCH}.zip" && \
|
||||
if [ -f "/app/packages/${PROTOC_PACKAGE}" ]; then \
|
||||
echo "发现本地protoc安装包,将进行离线安装"; \
|
||||
cp /app/packages/${PROTOC_PACKAGE} /app/ && \
|
||||
unzip -o /app/${PROTOC_PACKAGE} -d /usr/local && \
|
||||
chmod +x /usr/local/bin/protoc && \
|
||||
rm -f /app/${PROTOC_PACKAGE}; \
|
||||
else \
|
||||
echo "未发现本地protoc安装包,将进行在线安装"; \
|
||||
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/${PROTOC_PACKAGE} && \
|
||||
unzip -o ${PROTOC_PACKAGE} -d /usr/local && \
|
||||
chmod +x /usr/local/bin/protoc && \
|
||||
rm -f ${PROTOC_PACKAGE}; \
|
||||
fi
|
||||
|
||||
# 复制依赖文件
|
||||
COPY docreader/pyproject.toml docreader/uv.lock ./
|
||||
RUN pip install uv --break-system-packages && \
|
||||
python -m uv sync --locked --no-dev
|
||||
|
||||
# 复制源代码和生成脚本
|
||||
COPY docreader docreader
|
||||
|
||||
# 生成 protobuf 代码(使用 venv 中的 grpc_tools)
|
||||
ENV PATH="/app/.venv/bin:${PATH}"
|
||||
RUN chmod +x docreader/scripts/generate_proto.sh && \
|
||||
bash docreader/scripts/generate_proto.sh
|
||||
|
||||
# =========================
|
||||
# 运行阶段(轻量化)
|
||||
# =========================
|
||||
FROM python:3.10.18-bookworm AS runner
|
||||
|
||||
ARG APT_MIRROR=""
|
||||
RUN if [ -n "$APT_MIRROR" ]; then \
|
||||
sed -i "s@http://deb.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list.d/debian.sources && \
|
||||
sed -i "s@http://security.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list.d/debian.sources; \
|
||||
fi
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装运行时依赖(已移除 OCR/PaddleOCR 相关依赖)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libjpeg62-turbo \
|
||||
wget \
|
||||
gnupg \
|
||||
openjdk-17-jre-headless \
|
||||
libgl1 \
|
||||
libglib2.0-0 \
|
||||
antiword \
|
||||
tar \
|
||||
dpkg \
|
||||
libxinerama1 \
|
||||
libfontconfig1 \
|
||||
libdbus-glib-1-2 \
|
||||
libcairo2 \
|
||||
libcups2 \
|
||||
libglu1-mesa \
|
||||
libsm6 \
|
||||
libreoffice \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 安装 grpc_health_probe
|
||||
ARG TARGETARCH
|
||||
# 兼容 BuildKit 和传统构建:如果 TARGETARCH 为空,使用 uname 检测
|
||||
RUN if [ -z "$TARGETARCH" ]; then \
|
||||
case $(uname -m) in \
|
||||
"x86_64") TARGETARCH="amd64" ;; \
|
||||
"aarch64") TARGETARCH="arm64" ;; \
|
||||
"armv7l") TARGETARCH="arm" ;; \
|
||||
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;; \
|
||||
esac; \
|
||||
echo "[自动检测] 架构: $TARGETARCH"; \
|
||||
else \
|
||||
echo "[BuildKit] 架构: $TARGETARCH"; \
|
||||
fi && \
|
||||
GRPC_HEALTH_PROBE_VERSION=v0.4.24 && \
|
||||
case $TARGETARCH in \
|
||||
"amd64") ARCH="amd64" ;; \
|
||||
"arm64") ARCH="arm64" ;; \
|
||||
"arm") ARCH="arm" ;; \
|
||||
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
|
||||
esac && \
|
||||
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-${ARCH} && \
|
||||
chmod +x /bin/grpc_health_probe
|
||||
|
||||
# 从构建阶段复制已安装的依赖和生成的代码
|
||||
ENV VIRTUAL_ENV=/app/.venv
|
||||
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
||||
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
|
||||
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
|
||||
# 安装 Playwright 浏览器(网页解析)。可在构建时切换为内部制品库或镜像源。
|
||||
ARG PLAYWRIGHT_DOWNLOAD_HOST=""
|
||||
ARG PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST=""
|
||||
RUN if [ -n "$PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST" ]; then \
|
||||
PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST="$PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST" python -m playwright install webkit; \
|
||||
elif [ -n "$PLAYWRIGHT_DOWNLOAD_HOST" ]; then \
|
||||
PLAYWRIGHT_DOWNLOAD_HOST="$PLAYWRIGHT_DOWNLOAD_HOST" python -m playwright install webkit; \
|
||||
else \
|
||||
python -m playwright install webkit; \
|
||||
fi
|
||||
RUN python -m playwright install-deps webkit
|
||||
|
||||
COPY docreader/pyproject.toml docreader/uv.lock ./
|
||||
COPY --from=builder /app/docreader docreader
|
||||
|
||||
# 创建共享临时图片目录
|
||||
RUN mkdir -p /tmp/docreader
|
||||
|
||||
# 暴露 gRPC 端口
|
||||
EXPOSE 50051
|
||||
|
||||
# Probe ARM crypto instructions before importing native dependencies. The
|
||||
# entrypoint only enables portable OpenSSL implementations after a SIGILL.
|
||||
ENTRYPOINT ["/app/.venv/bin/python", "-m", "docreader.container_entrypoint"]
|
||||
# Dependencies are installed from uv.lock at build time; do not mutate them at boot.
|
||||
CMD ["/app/.venv/bin/python", "-m", "docreader.main"]
|
||||
@@ -0,0 +1,29 @@
|
||||
# OpenDataLoader PDF hybrid backend (Docling). Pre-install deps so the
|
||||
# container listens on :5002 immediately instead of pip install on every start.
|
||||
#
|
||||
# Default --no-ocr: digital PDFs already have a text layer; Docling layout/table
|
||||
# still runs without EasyOCR (avoids libGL + heavy OCR stack in slim images).
|
||||
# For scanned PDFs use builtin docreader OCR, MinerU, or override with
|
||||
# ODL_HYBRID_EXTRA_ARGS="--force-ocr" (requires extra system/Python deps).
|
||||
FROM python:3.10.18-bookworm
|
||||
|
||||
# Docling table/layout models import cv2 (OpenCV), which needs libGL at runtime
|
||||
# even when hybrid runs with --no-ocr.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
libgl1 \
|
||||
libglib2.0-0 \
|
||||
libgomp1 \
|
||||
libsm6 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install --no-cache-dir "opendataloader-pdf[hybrid]>=2.4.7"
|
||||
|
||||
EXPOSE 5002
|
||||
|
||||
ENV ODL_HYBRID_EXTRA_ARGS="--no-ocr"
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --retries=5 --start-period=120s \
|
||||
CMD curl -f http://localhost:5002/health || exit 1
|
||||
|
||||
CMD ["bash", "-c", "exec opendataloader-pdf-hybrid --host 0.0.0.0 --port 5002 ${ODL_HYBRID_EXTRA_ARGS}"]
|
||||
@@ -0,0 +1,234 @@
|
||||
# Academy Sandbox Image
|
||||
# Pre-built environment for executing agent skill scripts in Docker sandbox
|
||||
# Multi-stage build, minimal dependencies
|
||||
#
|
||||
# Targets that ship from this file:
|
||||
# runtime - the plain environment. Used by the Docker backend and
|
||||
# as the base image of E2B templates, whose builder
|
||||
# injects its own envd.
|
||||
# cube - the same environment plus Cube's envd daemon. Cube
|
||||
# builds templates straight from the image and probes
|
||||
# :49983/health, so an image without envd can only ever
|
||||
# fail. See website-docs/06-development/04-sandbox-deployment.md.
|
||||
# desktop-runtime - runtime plus XFCE / x11vnc / websockify. Not a published
|
||||
# tag; the desktop and desktop-cube targets sit on it.
|
||||
# desktop - desktop-runtime, tagged for E2B (and a future Docker
|
||||
# desktop path). The Docker backend does not use this yet.
|
||||
# desktop-cube - desktop-runtime plus Cube envd.
|
||||
#
|
||||
# Pin every FROM to TARGETPLATFORM. BuildKit already honours --platform; the
|
||||
# pin is for the legacy builder (DOCKER_BUILDKIT=0), which ignores --platform
|
||||
# whenever the host's arm64 python/node is already cached. The cube target
|
||||
# can then COPY envd of one architecture onto a runtime of the other — Cube
|
||||
# probes the mixed image as READY and Exec fails with "exec format error".
|
||||
#
|
||||
# Do not give this ARG a default. A declared default beats the value BuildKit
|
||||
# injects per platform, so a multi-platform build would run every platform on
|
||||
# the amd64 rootfs and only relabel the config. The legacy builder injects
|
||||
# nothing and rejects an empty --platform, hence the amd64 fallback in FROM:
|
||||
# under that builder an arm64 image needs --build-arg TARGETPLATFORM.
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
# Stage 1: Get Node.js binaries
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:20-slim AS node-base
|
||||
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/astral-sh/uv:0.12.4 AS uv-base
|
||||
|
||||
# Stage 2: Runtime image
|
||||
#
|
||||
# 3.12 is the floor because skill sources commonly use PEP 701 nested quotes
|
||||
# in f-strings (f"x={d["k"]}"). Install-time ast.parse runs this interpreter;
|
||||
# 3.11 rejects that syntax and the whole skill install fails.
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3.12-slim AS runtime
|
||||
|
||||
# Fail the build when the rootfs is not the platform being built. No default:
|
||||
# BuildKit sets TARGETARCH per platform; the legacy builder leaves it empty.
|
||||
ARG TARGETARCH
|
||||
RUN arch="$(dpkg --print-architecture)"; \
|
||||
if [ -n "$TARGETARCH" ] && [ "$arch" != "$TARGETARCH" ]; then \
|
||||
echo "runtime rootfs is $arch but TARGETARCH=$TARGETARCH" >&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# Copy Node.js from node image (avoids NodeSource install overhead)
|
||||
COPY --from=node-base /usr/local/bin/node /usr/local/bin/
|
||||
COPY --from=node-base /usr/local/lib/node_modules /usr/local/lib/node_modules
|
||||
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
|
||||
ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
|
||||
|
||||
# Python package manager: uv (fast pip replacement). Preinstalled because each
|
||||
# skill gets its own venv at install time, and building that from a cold pip is
|
||||
# what dominates an install's wall clock.
|
||||
COPY --from=uv-base /uv /usr/local/bin/uv
|
||||
RUN ln -s /usr/local/bin/uv /usr/local/bin/uvx
|
||||
|
||||
# Node package manager: pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Install minimal CLI tools (bash/grep/sed/coreutils/findutils already in slim
|
||||
# image). `file` is not in slim; models reach for it after a script-type error.
|
||||
# curl is not optional: the sandbox connectivity check probes egress with it,
|
||||
# and skills that fetch a URL expect it to be there. The compression tools are
|
||||
# here because skill bundles and their assets arrive archived. git backs
|
||||
# per-turn workspace checkpoints (object store at /var/lib/academy/workspace.git,
|
||||
# work tree /workspace) that session fork and rewind roll back to.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
jq \
|
||||
curl \
|
||||
ca-certificates \
|
||||
file \
|
||||
zip \
|
||||
unzip \
|
||||
bzip2 \
|
||||
xz-utils \
|
||||
zstd \
|
||||
git \
|
||||
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
|
||||
|
||||
# Add packages here when installed skills actually need them:
|
||||
|
||||
# Sandbox scripts run as root by default: each chat session owns its own
|
||||
# sandbox, so the in-container account is not a tenant boundary, and agents are
|
||||
# expected to install packages and write wherever they need. A non-root
|
||||
# "user" account (UID 1000) is still created and named for interop — E2B
|
||||
# templates expose it and some tooling still addresses it by name — and it
|
||||
# gives something for `sudo` and E2B/Cube requests that target a named account
|
||||
# to land on. The Docker backend can also address it numerically as 1000:1000.
|
||||
RUN groupadd -g 1000 user && \
|
||||
useradd -u 1000 -g user -m -s /bin/bash user
|
||||
|
||||
# Pre-create the two directories every backend writes to. Root can create them
|
||||
# at exec time too. Ownership stays with the compatibility account so tools
|
||||
# explicitly selecting user can also write here; default root execs do not
|
||||
# rely on that ownership.
|
||||
RUN mkdir -p /workspace/input /workspace/output && \
|
||||
chown -R user:user /workspace
|
||||
|
||||
# Classic user@host:path prompt (colored). E2B's provisioner later appends
|
||||
# `PS1='\w $ '`; the script reapplies this prompt via PROMPT_COMMAND so
|
||||
# Cube, Docker, and E2B all show the same Debian-style line.
|
||||
COPY docker/sandbox-pty-prompt.sh /etc/academy/pty-prompt.sh
|
||||
RUN echo '. /etc/academy/pty-prompt.sh' > /etc/profile.d/zz-academy-prompt.sh && \
|
||||
echo '. /etc/academy/pty-prompt.sh' >> /root/.bashrc && \
|
||||
echo '. /etc/academy/pty-prompt.sh' >> /home/user/.bashrc
|
||||
|
||||
WORKDIR /workspace
|
||||
USER root
|
||||
|
||||
# Stage 3: Cube template image
|
||||
#
|
||||
# envd is what Cube talks to for everything — the readiness probe that decides
|
||||
# whether a template build succeeds, plus every later exec and file call. It
|
||||
# runs as root and selects the account named in each request. Academy names
|
||||
# root by default, matching the runtime stage.
|
||||
#
|
||||
# Built for amd64 and arm64: cubesandbox-base ships both, and Cube runs on
|
||||
# x86_64 (PVM or bare-metal KVM) and on arm64 bare-metal KVM. PVM itself is
|
||||
# x86_64-only, so an arm64 Cube host needs native KVM.
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/tencentcloud/cubesandbox-base:2026.16 AS cube-base
|
||||
|
||||
FROM runtime AS cube
|
||||
|
||||
USER root
|
||||
COPY --from=cube-base /usr/bin/envd /usr/bin/envd
|
||||
COPY --from=cube-base /usr/local/bin/cube-entrypoint.sh /usr/local/bin/cube-entrypoint.sh
|
||||
# Compare envd with the rootfs rather than trusting TARGETARCH: the legacy
|
||||
# builder leaves TARGETARCH empty, and a mixed image is exactly what this
|
||||
# guard exists to stop.
|
||||
RUN arch="$(dpkg --print-architecture)"; \
|
||||
case "$arch" in amd64) elf=x86-64 ;; arm64) elf=aarch64 ;; *) elf="$arch" ;; esac; \
|
||||
if ! file -bL /usr/bin/envd | grep -q "$elf"; then \
|
||||
echo "envd is$(file -bL /usr/bin/envd | cut -d, -f2) but rootfs is $arch" >&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
EXPOSE 49983
|
||||
# The entrypoint backgrounds envd and then waits on it, since this image
|
||||
# defines no CMD of its own.
|
||||
ENTRYPOINT ["/usr/local/bin/cube-entrypoint.sh"]
|
||||
|
||||
# Stage 4: desktop environment on top of runtime.
|
||||
#
|
||||
# Debian package names (runtime is python:3.12-slim, not Ubuntu). Do not run
|
||||
# `yes | unminimize` — Debian has no such command. Do not clone noVNC; the
|
||||
# Academy frontend uses @novnc/novnc and the sandbox only needs websockify.
|
||||
# procps supplies pgrep for the start script; util-linux supplies flock.
|
||||
FROM runtime AS desktop-runtime
|
||||
|
||||
USER root
|
||||
# DISPLAY is exported by start-desktop.sh when the desktop actually starts.
|
||||
# Do not bake it into the image ENV: Cube copies image ENV onto the cubebox
|
||||
# and a preset DISPLAY=:0 is the only env the working main-cube templates
|
||||
# do not have.
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
# XFCE apps (mousepad, xfce4-terminal) decode files with the process locale.
|
||||
# python:slim defaults to POSIX/C, which is why the desktop shows mojibake
|
||||
# while the Academy terminal tab does not: that tab is xterm.js in the
|
||||
# browser, and Cube/E2B already stamp LANG/LC_ALL on the envd PTY.
|
||||
# C.UTF-8 is built into glibc; do not pull locales-all.
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=C.UTF-8
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
procps \
|
||||
util-linux \
|
||||
xvfb \
|
||||
x11-utils \
|
||||
x11-xserver-utils \
|
||||
xauth \
|
||||
dbus \
|
||||
dbus-x11 \
|
||||
xfce4 \
|
||||
xfce4-goodies \
|
||||
x11vnc \
|
||||
websockify \
|
||||
xdotool \
|
||||
scrot \
|
||||
fonts-dejavu-core \
|
||||
fonts-noto-cjk \
|
||||
desktop-base \
|
||||
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
|
||||
&& rm -f /etc/rcS.d/S??procps /etc/rcS.d/S??x11-common \
|
||||
/etc/rc2.d/S??dbus /etc/rc3.d/S??dbus \
|
||||
/etc/rc4.d/S??dbus /etc/rc5.d/S??dbus
|
||||
|
||||
COPY docker/scripts/start-desktop.sh /usr/local/bin/start-desktop.sh
|
||||
COPY docker/desktop/xfce4-desktop.xml /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml
|
||||
RUN chmod 0755 /usr/local/bin/start-desktop.sh \
|
||||
&& mkdir -p /root/.config/xfce4/xfconf/xfce-perchannel-xml \
|
||||
&& cp /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml \
|
||||
/root/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml
|
||||
|
||||
# Stage 5: published desktop image (E2B / future Docker desktop).
|
||||
FROM desktop-runtime AS desktop
|
||||
EXPOSE 6080
|
||||
|
||||
# Stage 6: desktop + Cube envd. Same platforms and envd check as cube.
|
||||
FROM desktop-runtime AS desktop-cube
|
||||
|
||||
USER root
|
||||
COPY --from=cube-base /usr/bin/envd /usr/bin/envd
|
||||
COPY --from=cube-base /usr/local/bin/cube-entrypoint.sh /usr/local/bin/cube-entrypoint.sh
|
||||
RUN arch="$(dpkg --print-architecture)"; \
|
||||
case "$arch" in amd64) elf=x86-64 ;; arm64) elf=aarch64 ;; *) elf="$arch" ;; esac; \
|
||||
if ! file -bL /usr/bin/envd | grep -q "$elf"; then \
|
||||
echo "envd is$(file -bL /usr/bin/envd | cut -d, -f2) but rootfs is $arch" >&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# cube-entrypoint.sh redirects envd to /var/log/envd.log. Cube packs this
|
||||
# ~1.5GiB image into a 1.5GiB ext4 with no spare blocks; mkdir/write of that
|
||||
# log fails under `set -eu`, envd never binds 49983, and the template probe
|
||||
# is connection refused. envd as PID 1 (stdio) succeeds on the same rootfs.
|
||||
# "-" is the entrypoint's documented "inherit container stdio" value.
|
||||
ENV ENVD_LOG_FILE=-
|
||||
|
||||
EXPOSE 49983 6080
|
||||
ENTRYPOINT ["/usr/local/bin/cube-entrypoint.sh"]
|
||||
|
||||
# Stage 7: default target
|
||||
#
|
||||
# Docker builds the last stage when none is named, and that must stay the plain
|
||||
# runtime: a bare `docker build -f docker/Dockerfile.sandbox .` is expected to
|
||||
# produce the image the Docker backend runs, not a Cube or desktop variant.
|
||||
FROM runtime AS sandbox
|
||||
@@ -0,0 +1,31 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/var/log/supervisord.log
|
||||
logfile_maxbytes=50MB
|
||||
logfile_backups=10
|
||||
loglevel=info
|
||||
pidfile=/var/run/supervisord.pid
|
||||
user=root
|
||||
|
||||
[program:Academy]
|
||||
command=/app/Academy
|
||||
directory=/app
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/Academy.log
|
||||
stdout_logfile_maxbytes=50MB
|
||||
stdout_logfile_backups=10
|
||||
environment=CGO_ENABLED=1
|
||||
user=appuser
|
||||
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channel name="xfce4-desktop" version="1.0">
|
||||
<property name="backdrop" type="empty">
|
||||
<property name="screen0" type="empty">
|
||||
<property name="monitor0" type="empty">
|
||||
<property name="image-style" type="int" value="5"/>
|
||||
<property name="last-image" type="string" value="/usr/share/images/desktop-base/desktop-background"/>
|
||||
<property name="workspace0" type="empty">
|
||||
<property name="image-style" type="int" value="5"/>
|
||||
<property name="last-image" type="string" value="/usr/share/images/desktop-base/desktop-background"/>
|
||||
</property>
|
||||
</property>
|
||||
<property name="monitorVirtual1" type="empty">
|
||||
<property name="image-style" type="int" value="5"/>
|
||||
<property name="last-image" type="string" value="/usr/share/images/desktop-base/desktop-background"/>
|
||||
<property name="workspace0" type="empty">
|
||||
<property name="image-style" type="int" value="5"/>
|
||||
<property name="last-image" type="string" value="/usr/share/images/desktop-base/desktop-background"/>
|
||||
</property>
|
||||
</property>
|
||||
</property>
|
||||
</property>
|
||||
</channel>
|
||||
@@ -0,0 +1,54 @@
|
||||
# Academy interactive PTY prompt: classic \u@\h:\W\$
|
||||
# (user@host:last-path-segment, # for root / $ otherwise).
|
||||
#
|
||||
# \W is the last directory only (e.g. /opt/academy/skills → skills),
|
||||
# so deep cwd does not blow the prompt width.
|
||||
#
|
||||
# Bold green (01;32) is user@host; bold blue (01;34) is the path — the
|
||||
# usual Debian colors, so ls --color can keep directories blue and
|
||||
# executables green. Root uses the same green as a normal user.
|
||||
#
|
||||
# Also enables Debian-style interactive aliases (ll, la, l, colored ls/grep).
|
||||
#
|
||||
# Sourced from profile.d and bashrc. E2B's template provisioner later
|
||||
# appends PS1='\w $ '; PROMPT_COMMAND reapplies this prompt so that cannot
|
||||
# stick. No-op for non-bash (Debian /etc/profile is also read by dash).
|
||||
|
||||
[ -n "${BASH_VERSION-}" ] || return 0
|
||||
|
||||
academy_set_pty_prompt() {
|
||||
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
|
||||
}
|
||||
|
||||
academy_set_pty_prompt
|
||||
|
||||
# Debian/Ubuntu interactive shortcuts. Aliases only apply in interactive
|
||||
# shells, so skill scripts still see the real ls/grep.
|
||||
case "$-" in
|
||||
*i*)
|
||||
if command -v dircolors >/dev/null 2>&1; then
|
||||
eval "$(dircolors -b)"
|
||||
fi
|
||||
alias ls='ls --color=auto'
|
||||
alias grep='grep --color=auto'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
alias ll='ls -alF'
|
||||
alias la='ls -A'
|
||||
alias l='ls -CF'
|
||||
;;
|
||||
esac
|
||||
|
||||
case ";${PROMPT_COMMAND-};" in
|
||||
*academy_set_pty_prompt*) ;;
|
||||
*)
|
||||
if [ -n "${PROMPT_COMMAND-}" ]; then
|
||||
PROMPT_COMMAND="academy_set_pty_prompt; ${PROMPT_COMMAND}"
|
||||
else
|
||||
PROMPT_COMMAND="academy_set_pty_prompt"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
# PS1 and PROMPT_COMMAND stay shell-local. Exporting PS1 makes child
|
||||
# processes look interactive (`[ -z "$PS1" ]`); exporting PROMPT_COMMAND
|
||||
# without `export -f academy_set_pty_prompt` breaks nested bash.
|
||||
@@ -0,0 +1,150 @@
|
||||
#!/bin/sh
|
||||
# Idempotent desktop stack for Academy sandbox images.
|
||||
# Safe to re-run after pause/resume; serialised with flock so concurrent Exec
|
||||
# (dual tabs, retries, multiple replicas) cannot split the VNC secret.
|
||||
set -eu
|
||||
export DISPLAY=:0
|
||||
# UTF-8 for every daemon this script starts (XFCE session, xfce4-terminal,
|
||||
# mousepad). Without it they inherit POSIX/C from python:slim and UTF-8
|
||||
# files render as mojibake; the Academy terminal tab is unaffected because
|
||||
# it is drawn in the browser. Prefer an image-provided LANG, fall back here
|
||||
# so a wrapped older image still starts a UTF-8 session.
|
||||
export LANG="${LANG:-C.UTF-8}"
|
||||
export LC_ALL="${LC_ALL:-C.UTF-8}"
|
||||
mkdir -p /run/desktop
|
||||
|
||||
# Readiness is a LISTEN check read out of /proc, never a connection. Dialling
|
||||
# 5900 spends an RFB client slot and dialling 6080 parks websockify in
|
||||
# readline(); a probe must not perturb the stack it measures. (This also
|
||||
# sidesteps the old nc/dash problems: nc is not in the image and dash has no
|
||||
# /dev/tcp, and under `set -eu` a 127 exit from `if nc -z ...` does not trip
|
||||
# set -e, so the script would spin to its timeout with the desktop already up.)
|
||||
port_open() {
|
||||
hex=$(printf '%04X' "$1")
|
||||
cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk -v hex="$hex" '
|
||||
$4 == "0A" {
|
||||
n = split($2, addr, ":")
|
||||
if (toupper(addr[n]) == hex) { found = 1 }
|
||||
}
|
||||
END { exit !found }
|
||||
'
|
||||
}
|
||||
|
||||
# pgrep matches zombies. x11vnc -bg leaves one behind whenever PID 1 does not
|
||||
# reap it (envd does not), and a pgrep-guarded step 7 then skips the restart
|
||||
# for the life of the sandbox: websockify keeps answering on 6080, DialDesktop
|
||||
# gets its 101, and the RFB hello never comes. Steps guarded by a listening
|
||||
# port are immune; this is for the ones with no port of their own.
|
||||
proc_alive() {
|
||||
for pid in $(pgrep -x "$1" 2>/dev/null); do
|
||||
state=$(awk '/^State:/ { print $2; exit }' "/proc/$pid/status" 2>/dev/null || true)
|
||||
[ "$state" = "Z" ] || return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# 1. Already ready: both listeners, not just websockify. 6080-only lets
|
||||
# DialDesktop 101 while x11vnc is dead; the RFB hello never comes.
|
||||
if port_open 6080 && port_open 5900; then exit 0; fi
|
||||
|
||||
# 2. Serialise the whole start section. Concurrent triggers are normal
|
||||
# (dual tabs, timeout retries, multi-replica). Every step below is
|
||||
# check-then-act: without the lock two instances both see "secret missing"
|
||||
# and each write their own, so websockify uses A while the backend reads B
|
||||
# — intermittent 401. A Redis connection lock cannot serialise this Exec.
|
||||
#
|
||||
# Every daemon started below MUST close fd 9 (`9>&-`). A child that
|
||||
# inherits it keeps holding the lock after this script exits, and the next
|
||||
# run that misses the fast path blocks on flock forever — the Exec times
|
||||
# out at 60s (exit=-1) and 6080 never comes back.
|
||||
exec 9>/run/desktop/.lock
|
||||
flock 9
|
||||
|
||||
# Recheck after waiting for the lock: a previous holder may have finished.
|
||||
if port_open 6080 && port_open 5900; then exit 0; fi
|
||||
|
||||
# 3. Per-sandbox random secret (first start only). Used by websockify's
|
||||
# BasicHTTPAuth handshake; never sent to the browser. Write .tmp then
|
||||
# rename so a reader that sees the file also sees complete contents.
|
||||
if [ ! -f /run/desktop/secret ]; then
|
||||
umask 077
|
||||
tr -dc 'A-Za-z0-9' </dev/urandom | head -c 32 > /run/desktop/secret.tmp
|
||||
mv /run/desktop/secret.tmp /run/desktop/secret
|
||||
fi
|
||||
|
||||
# dbus-uuidgen --ensure: XFCE/dbus fail on a missing /etc/machine-id, which
|
||||
# slim images often omit. Harmless when the file already exists.
|
||||
if command -v dbus-uuidgen >/dev/null 2>&1; then
|
||||
dbus-uuidgen --ensure >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
# Every daemon below is started through this. Two things must happen or the
|
||||
# desktop "fails" while actually running:
|
||||
# - close fd 9, or the daemon keeps holding the flock after this script
|
||||
# exits and the next run that misses the fast path blocks forever;
|
||||
# - give it stdio of its own, or it holds the caller's stdout/stderr and
|
||||
# envd's Exec never returns (it waits for those to close), which surfaces
|
||||
# as exit=-1 at the 60s timeout.
|
||||
spawn() {
|
||||
name=$1
|
||||
shift
|
||||
"$@" </dev/null >>"/run/desktop/$name.log" 2>&1 9>&- &
|
||||
}
|
||||
|
||||
# 4. Xvfb
|
||||
proc_alive Xvfb || \
|
||||
spawn xvfb Xvfb :0 -ac -screen 0 1280x800x24 -nolisten tcp
|
||||
|
||||
# 4b. Wait until X actually accepts connections. Probe state, do not sleep a
|
||||
# fixed delay: startxfce4 before X is listening exits with "cannot open
|
||||
# display", later steps still run, and the failure looks like "6080 is up
|
||||
# but the screen is black / no window manager".
|
||||
i=0
|
||||
while [ $i -lt 40 ]; do
|
||||
xdpyinfo -display :0 >/dev/null 2>&1 && break
|
||||
i=$((i + 1))
|
||||
sleep 0.25
|
||||
done
|
||||
xdpyinfo -display :0 >/dev/null 2>&1 || exit 1
|
||||
|
||||
# 5. dbus + XFCE. Use xfce4-session, not startxfce4: the latter tries to
|
||||
# launch its own X server and fails with "X server already running" once
|
||||
# Xvfb is up. The session still starts, but the warning is noisy and the
|
||||
# extra compositor fight is real (xfwm4: another compositing manager).
|
||||
proc_alive xfce4-session || {
|
||||
mkdir -p /run/dbus
|
||||
dbus-daemon --system --fork </dev/null >>/run/desktop/dbus.log 2>&1 9>&- || true
|
||||
spawn xfce4-session xfce4-session
|
||||
}
|
||||
|
||||
# 6. Disable screensaver / DPMS — clock jumps after resume lock or blank the screen.
|
||||
xset s off -dpms 2>/dev/null || true
|
||||
xfconf-query -c xfce4-session -p /startup/screensaver/enabled -n -t bool -s false 2>/dev/null || true
|
||||
|
||||
# 7. x11vnc: localhost only; RFB security type None (auth is on websockify).
|
||||
# Do not pass -ping: it pushes a 1x1 framebuffer update every second and
|
||||
# would defeat any byte-counting idle detector.
|
||||
#
|
||||
# Guard on the port, not on pgrep: a zombie x11vnc is what silently turns
|
||||
# this step into a no-op. A duplicate only ever loses the bind and exits.
|
||||
port_open 5900 || \
|
||||
x11vnc -display :0 -localhost -rfbport 5900 -nopw \
|
||||
-forever -shared -wait 50 -noxdamage -repeat -bg \
|
||||
</dev/null >>/run/desktop/x11vnc.log 2>&1 9>&-
|
||||
|
||||
# 8. websockify: the only listener facing the world. Handshake requires
|
||||
# Authorization: Basic. This is the only gate on Cube's host-port NAT
|
||||
# path that bypasses CubeProxy. Port-guarded for the same reason as 7.
|
||||
port_open 6080 || \
|
||||
spawn websockify websockify --auth-plugin BasicHTTPAuth \
|
||||
--auth-source "academy:$(cat /run/desktop/secret)" \
|
||||
--heartbeat 30 6080 127.0.0.1:5900
|
||||
|
||||
# 9. Wait for ready (lock held so waiters queue instead of starting twice).
|
||||
i=0
|
||||
while [ $i -lt 60 ]; do
|
||||
port_open 6080 && port_open 5900 && exit 0
|
||||
i=$((i + 1))
|
||||
sleep 0.5
|
||||
done
|
||||
exit 1
|
||||
@@ -0,0 +1,49 @@
|
||||
use_default_settings: true
|
||||
|
||||
general:
|
||||
instance_name: "Academy SearXNG"
|
||||
privacypolicy_url: false
|
||||
donation_url: false
|
||||
contact_url: false
|
||||
enable_metrics: false
|
||||
|
||||
server:
|
||||
# Override via env SEARXNG_SECRET; the entrypoint script substitutes ultrasecretkey.
|
||||
secret_key: "ultrasecretkey"
|
||||
base_url: false
|
||||
image_proxy: true
|
||||
http_protocol_version: "1.0"
|
||||
method: "GET"
|
||||
# Disabled so Academy's backend can call /search without IP-based throttling.
|
||||
# Re-enable and add Academy's egress IP to a limiter allowlist if you expose
|
||||
# this instance to the public internet.
|
||||
limiter: false
|
||||
public_instance: false
|
||||
|
||||
ui:
|
||||
static_use_hash: true
|
||||
default_locale: ""
|
||||
query_in_title: false
|
||||
infinite_scroll: false
|
||||
center_alignment: false
|
||||
theme_args:
|
||||
simple_style: auto
|
||||
search_on_category_select: true
|
||||
hotkeys: default
|
||||
|
||||
search:
|
||||
safe_search: 0
|
||||
autocomplete: ""
|
||||
default_lang: "auto"
|
||||
ban_time_on_fail: 5
|
||||
max_ban_time_on_fail: 120
|
||||
formats:
|
||||
- html
|
||||
- json
|
||||
|
||||
outgoing:
|
||||
request_timeout: 6.0
|
||||
max_request_timeout: 10.0
|
||||
pool_connections: 100
|
||||
pool_maxsize: 20
|
||||
enable_http2: true
|
||||
Reference in new issue
Block a user