mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(ci): pin Node image and verify OpenCode release archives
This commit is contained in:
@@ -13,6 +13,7 @@ scripts/
|
||||
scripts/*
|
||||
!scripts/install.sh
|
||||
!scripts/install-rustup.sh
|
||||
!scripts/install-opencode.sh
|
||||
!scripts/install.ps1
|
||||
!scripts/version-sync.py
|
||||
!scripts/sync-plugin-versions.py
|
||||
|
||||
+16
-7
@@ -55,6 +55,9 @@ RUN /opt/python/cp311-cp311/bin/pip install 'maturin>=1.5,<2.0' && \
|
||||
# headers). Bookworm's libc.so.6 doesn't export these wrappers, so
|
||||
# `import headroom._core` fails at runtime. Trixie's glibc 2.41 does.
|
||||
#
|
||||
# Node 24.22.2 from the official multi-platform image; no NodeSource setup script.
|
||||
FROM node:24-bookworm-slim@sha256:01d566e8d94d8c619591d78652babfccd3c6992a3dffa9ed5ab39e11cf6c70e9 AS wrap-node
|
||||
|
||||
# We need Python 3.11 here (aider-chat==0.86.2 requires Python <3.12).
|
||||
# Trixie's default `python3` is 3.13 — too new for aider. python:3.11-slim
|
||||
# gives us Python 3.11 + trixie glibc + apt access for installing Node.
|
||||
@@ -77,11 +80,17 @@ RUN apt-get update && \
|
||||
ca-certificates \
|
||||
curl \
|
||||
git \
|
||||
gnupg && \
|
||||
curl -fsSL https://deb.nodesource.com/setup_24.x | bash - && \
|
||||
apt-get install -y --no-install-recommends nodejs && \
|
||||
gnupg \
|
||||
libstdc++6 \
|
||||
libatomic1 && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=wrap-node /usr/local/bin/node /usr/local/bin/node
|
||||
COPY --from=wrap-node /usr/local/lib/node_modules/ /usr/local/lib/node_modules/
|
||||
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
|
||||
ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx && \
|
||||
ln -s ../lib/node_modules/corepack/dist/corepack.js /usr/local/bin/corepack
|
||||
|
||||
# npm 10.9.8 crashes in Arborist's peer-set resolver when installing the local
|
||||
# OpenClaw plugin (Cannot read properties of null, reading 'edgesOut'). Pin the
|
||||
# tested npm version so both wrap-e2e callers use the same working installer.
|
||||
@@ -110,6 +119,7 @@ COPY --from=builder /dist/*.whl /tmp/wheels/
|
||||
# triggering the same `ModuleNotFoundError` the wheel install fixes.
|
||||
COPY sdk/typescript ./sdk/typescript
|
||||
COPY plugins/openclaw ./plugins/openclaw
|
||||
COPY scripts/install-opencode.sh /tmp/install-opencode.sh
|
||||
|
||||
# Install the prebuilt manylinux wheel with [proxy] extras. Pip resolves
|
||||
# extras from the wheel's metadata and pulls deps from public PyPI. The
|
||||
@@ -122,11 +132,10 @@ RUN python -m venv /opt/headroom-venv && \
|
||||
python -m venv /opt/aider-venv && \
|
||||
/opt/aider-venv/bin/python -m pip install --upgrade pip && \
|
||||
/opt/aider-venv/bin/python -m pip install "aider-chat==${AIDER_CHAT_VERSION}" && \
|
||||
curl -fsSL https://opencode.ai/install | VERSION="${OPENCODE_VERSION}" bash
|
||||
sh /tmp/install-opencode.sh "${OPENCODE_VERSION}"
|
||||
|
||||
# The opencode installer adds its bin dir to .bashrc. Non-login shells
|
||||
# (including CMD, docker run, and e2e shims spawned by subprocess) won't
|
||||
# source .bashrc, so add the dir to PATH explicitly. The e2e shim shadows
|
||||
# Expose the installed binary to non-login shells (including CMD, docker run,
|
||||
# and e2e shims spawned by subprocess). The e2e shim shadows
|
||||
# opencode anyway, but this guarantees `which opencode` works for
|
||||
# diagnostics.
|
||||
ENV PATH="/root/.opencode/bin:${PATH}"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# Install the pinned OpenCode release into the glibc Wrap E2E runtime.
|
||||
# Archive digests are from the GitHub v1.17.8 release asset metadata.
|
||||
set -eu
|
||||
|
||||
version=${1:?OpenCode version is required}
|
||||
if [ "$version" != 1.17.8 ]; then
|
||||
printf 'Unsupported unreviewed OpenCode version: %s\n' "$version" >&2
|
||||
exit 1
|
||||
fi
|
||||
case "$(uname -m)" in
|
||||
x86_64)
|
||||
target=linux-x64
|
||||
# Preserve the vendor installer's fallback on CPUs without AVX2.
|
||||
if ! grep -qwi avx2 /proc/cpuinfo 2>/dev/null; then
|
||||
target=linux-x64-baseline
|
||||
fi
|
||||
;;
|
||||
aarch64|arm64) target=linux-arm64 ;;
|
||||
*) printf 'Unsupported OpenCode Docker architecture\n' >&2; exit 1 ;;
|
||||
esac
|
||||
case "$target" in
|
||||
linux-x64) checksum=13fffc29227093462b7d14777ea6b804cfd94c2612819c101bbf933d862b1e5f ;;
|
||||
linux-x64-baseline) checksum=9b34bf34bdc66ea34ddd5858a131febf28b6247693acbfb5fb5c9ad94d90388b ;;
|
||||
linux-arm64) checksum=cfb34a6a9a40f9a2adb0d0f3ab387b97307823d075572bfb54a553228adcebbd ;;
|
||||
esac
|
||||
|
||||
temporary=$(mktemp -d)
|
||||
trap 'rm -rf -- "$temporary"' EXIT
|
||||
archive="$temporary/opencode.tar.gz"
|
||||
curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL \
|
||||
"https://github.com/anomalyco/opencode/releases/download/v$version/opencode-$target.tar.gz" \
|
||||
--output "$archive"
|
||||
printf '%s %s\n' "$checksum" "$archive" | sha256sum --check --strict -
|
||||
tar --extract --gzip --file "$archive" --directory "$temporary" --no-same-owner opencode
|
||||
if [ ! -f "$temporary/opencode" ] || [ -L "$temporary/opencode" ]; then
|
||||
printf 'Expected a regular OpenCode binary in the verified archive\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "$HOME/.opencode/bin"
|
||||
install -m 0755 -- "$temporary/opencode" "$HOME/.opencode/bin/opencode"
|
||||
@@ -0,0 +1,136 @@
|
||||
"""Offline archive verification and CPU selection checks for the Docker helper."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@unittest.skipUnless(os.name == "posix", "Docker bootstrap runs on Linux")
|
||||
class OpenCodeBootstrapTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.fixture = tempfile.TemporaryDirectory(prefix="headroom-opencode-test-")
|
||||
self.addCleanup(self.fixture.cleanup)
|
||||
self.root = Path(self.fixture.name)
|
||||
self.bin = self.root / "bin"
|
||||
self.bin.mkdir()
|
||||
self.trace = self.root / "trace"
|
||||
self.env = dict(
|
||||
os.environ,
|
||||
PATH=f"{self.bin}:{os.environ['PATH']}",
|
||||
HOME=str(self.root / "home"),
|
||||
TMPDIR=str(self.root),
|
||||
PROBE_TRACE=str(self.trace),
|
||||
PROBE_ARCH="x86_64",
|
||||
PROBE_AVX2="1",
|
||||
PROBE_SYMLINK="0",
|
||||
)
|
||||
self.stub("uname", 'printf "%s\\n" "$PROBE_ARCH"')
|
||||
self.stub("grep", '[ "$PROBE_AVX2" = 1 ]')
|
||||
self.stub(
|
||||
"curl",
|
||||
"""printf 'download\\n' >> "$PROBE_TRACE"
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--output) printf 'untrusted archive fixture' > "$2"; shift 2;;
|
||||
https://*) printf '%s\\n' "$1" > "$PROBE_TRACE.url"; shift;;
|
||||
*) shift;;
|
||||
esac
|
||||
done""",
|
||||
)
|
||||
self.stub(
|
||||
"tar",
|
||||
"""printf 'extract\\n' >> "$PROBE_TRACE"
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in --directory) destination="$2"; shift 2;; *) shift;; esac
|
||||
done
|
||||
if [ "$PROBE_SYMLINK" = 1 ]; then
|
||||
ln -s /bin/sh "$destination/opencode"
|
||||
else
|
||||
printf 'inert fixture' > "$destination/opencode"
|
||||
fi""",
|
||||
)
|
||||
self.stub(
|
||||
"install",
|
||||
'printf "install\\n" >> "$PROBE_TRACE"\nprintf "%s\\n" "$@" > "$PROBE_TRACE.args"',
|
||||
)
|
||||
self.script = Path(__file__).resolve().parents[2] / "scripts/install-opencode.sh"
|
||||
|
||||
def stub(self, name, body):
|
||||
path = self.bin / name
|
||||
path.write_text("#!/bin/sh\nset -eu\n" + body + "\n")
|
||||
path.chmod(0o755)
|
||||
|
||||
def run_bootstrap(self, version="1.17.8"):
|
||||
self.assertTrue(self.script.is_file(), "checksum bootstrap helper is required")
|
||||
return subprocess.run(
|
||||
["sh", str(self.script), version], env=self.env, capture_output=True, text=True
|
||||
)
|
||||
|
||||
def allow_fixture_checksum(self):
|
||||
self.stub("sha256sum", 'cat > "$PROBE_TRACE.checksum"')
|
||||
|
||||
def assert_target(self, target):
|
||||
self.allow_fixture_checksum()
|
||||
result = self.run_bootstrap()
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
Path(str(self.trace) + ".url").read_text().strip(),
|
||||
f"https://github.com/anomalyco/opencode/releases/download/v1.17.8/opencode-{target}.tar.gz",
|
||||
)
|
||||
self.assertEqual(self.trace.read_text().splitlines(), ["download", "extract", "install"])
|
||||
self.assertEqual(
|
||||
Path(str(self.trace) + ".args").read_text().splitlines()[-1],
|
||||
str(self.root / "home/.opencode/bin/opencode"),
|
||||
)
|
||||
|
||||
def test_corrupt_archive_stops_before_extraction(self):
|
||||
result = self.run_bootstrap()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("sha256sum", result.stderr)
|
||||
self.assertEqual(self.trace.read_text().splitlines(), ["download"])
|
||||
self.assertFalse((self.root / "home").exists())
|
||||
|
||||
def test_failed_download_stops_before_extraction(self):
|
||||
self.stub("curl", "exit 22")
|
||||
result = self.run_bootstrap()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertFalse(self.trace.exists())
|
||||
self.assertEqual(list(self.root.iterdir()), [self.bin])
|
||||
|
||||
def test_x64_without_avx2_keeps_baseline_binary(self):
|
||||
self.env["PROBE_AVX2"] = "0"
|
||||
self.assert_target("linux-x64-baseline")
|
||||
|
||||
def test_x64_with_avx2_keeps_standard_binary(self):
|
||||
self.assert_target("linux-x64")
|
||||
|
||||
def test_arm64_keeps_arm64_binary(self):
|
||||
self.env["PROBE_ARCH"] = "aarch64"
|
||||
self.assert_target("linux-arm64")
|
||||
|
||||
def test_unsupported_version_stops_before_download(self):
|
||||
result = self.run_bootstrap("unreviewed-version")
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("Unsupported", result.stderr)
|
||||
self.assertFalse(self.trace.exists())
|
||||
|
||||
def test_unsupported_architecture_stops_before_download(self):
|
||||
self.env["PROBE_ARCH"] = "unknown-fixture"
|
||||
result = self.run_bootstrap()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("Unsupported", result.stderr)
|
||||
self.assertFalse(self.trace.exists())
|
||||
|
||||
def test_symlink_archive_member_is_not_installed(self):
|
||||
self.allow_fixture_checksum()
|
||||
self.env["PROBE_SYMLINK"] = "1"
|
||||
result = self.run_bootstrap()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(self.trace.read_text().splitlines(), ["download", "extract"])
|
||||
self.assertFalse((self.root / "home").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user