An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Retry pinned ONNX source downloads and show Docker release versions
Daniel8123e27e7674
diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.ymlindex 574cdacacb..84e253eefc 100644--- a/.github/workflows/dockerimage.yml+++ b/.github/workflows/dockerimage.yml@@ -1,4 +1,5 @@name: Release Docker Image+run-name: Release Docker Image ${{ github.event_name == 'workflow_dispatch' && format('v{0}', inputs.version) || github.ref_name }}on:push:diff --git a/Dockerfile b/Dockerfileindex d98685d589..b06606691e 100644--- a/Dockerfile+++ b/Dockerfile@@ -49,20 +49,41 @@ FROM go-source AS go-buildRUN --mount=type=cache,target=/root/.cache/go-build \go build -tags "fts5 sqlcipher" -ldflags "-s -w"+FROM --platform=$BUILDPLATFORM ${ALPINE_IMAGE} AS onnx-source+ARG ONNX_COMMIT=3a728b75062256951b6e19ce718907cf1a1d4cf0+RUN apk add --no-cache git+# 固定提交的源码在构建机上下载一次,网络中断时重试;子模块保持各自锁定的提交。+RUN <<EORUN+#!/bin/sh -e+retry() {+ attempt=1+ until "$@"; do+ if [ "$attempt" -ge 3 ]; then return 1; fi+ echo "Source download failed; retry $attempt/2" >&2+ sleep "$((attempt * 10))"+ attempt="$((attempt + 1))"+ done+}+git init /onnxruntime+cd /onnxruntime+git remote add origin https://github.com/microsoft/onnxruntime+git config http.version HTTP/1.1+retry git fetch --depth=1 --no-tags origin "${ONNX_COMMIT}"+git checkout --detach FETCH_HEAD+test "$(git rev-parse HEAD)" = "${ONNX_COMMIT}"+retry git -c http.version=HTTP/1.1 submodule update --init --recursive --depth=1+EORUN+FROM ${ALPINE_IMAGE} AS onnx-buildARG TARGETARCHARG TARGETPLATFORM-ARG ONNX_COMMIT=3a728b75062256951b6e19ce718907cf1a1d4cf0ARG ONNX_VERSION=1.24.3ARG ONNX_TOOLCHAIN_REV=1# ONNX 阶段只依赖 C++ 工具链和固定源码;更新工具链时递增修订号以刷新安装层。RUN echo "${TARGETPLATFORM} toolchain revision ${ONNX_TOOLCHAIN_REV}" \&& apk add --no-cache bash cmake make g++ git patch python3 py3-pip py3-packaging linux-headers \&& apk info -v | sort > /onnx-toolchain.txt-RUN git clone --no-checkout https://github.com/microsoft/onnxruntime /onnxruntime \- && cd /onnxruntime \- && git checkout "${ONNX_COMMIT}" \- && git submodule update --init --recursive+COPY --from=onnx-source /onnxruntime /onnxruntime# Release 构建不生成栈回溯,将 execinfo.h 限定为 Debug 构建所需的头文件。RUN <<EORUN#!/bin/sh -ediff --git a/scripts/test_docker_release.py b/scripts/test_docker_release.pyindex 507939bcb0..66e23d4557 100644--- a/scripts/test_docker_release.py+++ b/scripts/test_docker_release.py@@ -3,7 +3,9 @@import copyimport importlib.utilimport json+import osfrom pathlib import Path+import shutilimport subprocessimport tempfileimport unittest@@ -175,5 +177,74 @@ class CacheTests(unittest.TestCase):cache.onnx_steps(log)+class SourceDownloadTests(unittest.TestCase):+ def execute(self, fetch_failures=0, submodule_failures=0, actual_commit=None):+ shell = shutil.which("sh")+ if shell is None:+ git = shutil.which("git")+ candidate = Path(git).parents[1] / "bin/sh.exe" if git else None+ shell = str(candidate) if candidate and candidate.is_file() else None+ if shell is None:+ self.skipTest("A POSIX shell is required for Docker source download tests")+ dockerfile = Path(__file__).resolve().parents[1].joinpath("Dockerfile").read_text(encoding="utf-8")+ stage = dockerfile.split("AS onnx-source\n", 1)[1].split("\nFROM ", 1)[0]+ script = stage.split("RUN <<EORUN\n", 1)[1].split("\nEORUN", 1)[0]+ commit = stage.split("ARG ONNX_COMMIT=", 1)[1].splitlines()[0]+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ trace = root / "trace"+ harness = r'''fetch_calls=0+submodule_calls=0+git() {+ printf '%s\n' "$*" >> "$TRACE"+ case "$1" in+ init) mkdir -p "$2" ;;+ fetch)+ fetch_calls=$((fetch_calls + 1))+ if [ "$fetch_calls" -le "$FETCH_FAILURES" ]; then return 1; fi ;;+ rev-parse) printf '%s\n' "$ACTUAL_COMMIT" ;;+ -c)+ submodule_calls=$((submodule_calls + 1))+ if [ "$submodule_calls" -le "$SUBMODULE_FAILURES" ]; then return 1; fi ;;+ esac+ return 0+}+sleep() { printf 'sleep %s\n' "$*" >> "$TRACE"; }+'''+ path = root / "download.sh"+ source = root.joinpath("source").as_posix()+ script = script.replace("git init /onnxruntime", 'git init "' + source + '"')+ script = script.replace("cd /onnxruntime", 'cd "' + source + '"')+ path.write_text(harness + script,+ encoding="utf-8", newline="\n")+ env = dict(os.environ, TRACE=trace.as_posix(), FETCH_FAILURES=str(fetch_failures),+ SUBMODULE_FAILURES=str(submodule_failures), ONNX_COMMIT=commit,+ ACTUAL_COMMIT=actual_commit or commit)+ result = subprocess.run([shell, "-e", str(path)], env=env, capture_output=True, text=True, timeout=20)+ return result.returncode, trace.read_text(encoding="utf-8").splitlines(), commit++ def test_network_failure_retries_only_the_locked_shallow_fetch(self):+ code, trace, commit = self.execute(fetch_failures=2)+ self.assertEqual(code, 0)+ self.assertEqual(sum(line.startswith("init ") for line in trace), 1)+ self.assertEqual(trace.count("fetch --depth=1 --no-tags origin " + commit), 3)+ self.assertEqual([line for line in trace if line.startswith("sleep ")], ["sleep 10", "sleep 20"])+ self.assertIn("checkout --detach FETCH_HEAD", trace)+ self.assertIn("remote add origin https://github.com/microsoft/onnxruntime", trace)++ def test_exhausted_fetch_or_wrong_commit_stops_before_submodules(self):+ for options in ({"fetch_failures": 3}, {"actual_commit": "0" * 40}):+ with self.subTest(options=options):+ code, trace, _ = self.execute(**options)+ self.assertNotEqual(code, 0)+ self.assertFalse(any("submodule update" in line for line in trace))++ def test_submodule_retry_preserves_the_downloaded_superproject(self):+ code, trace, _ = self.execute(submodule_failures=2)+ self.assertEqual(code, 0)+ self.assertEqual(sum(line.startswith("fetch ") for line in trace), 1)+ self.assertEqual(trace.count("-c http.version=HTTP/1.1 submodule update --init --recursive --depth=1"), 3)++if __name__ == "__main__":unittest.main()