Python
Linux: build openworker as one program, no Python needed
Rohit C Prasad258fe8c76ae9
diff --git a/packaging/build_linux.sh b/packaging/build_linux.shnew file mode 100755index 00000000..91dfb50b--- /dev/null+++ b/packaging/build_linux.sh@@ -0,0 +1,58 @@+#!/usr/bin/env bash+# Build the Linux `openworker` program: one folder with the program and its support files+# (no Python needed on the machine), packed as openworker-<version>-linux-<arch>.tar.gz.+#+# 1. Inside a Debian bullseye container (glibc 2.31, so the program runs on Ubuntu 20.04,+# Debian 11 and newer), install this package with the bedrock and openshell extras.+# 2. PyInstaller with packaging/openworker-server.spec, OPENWORKER_BUNDLE=cli: the whole+# command line as the entry point. `openworker-server` is a link to the same program.+# 3. Pack the folder and write its SHA-256 next to it, in packaging/dist/.+#+# Prerequisites: Docker, on a Linux machine of the target architecture (x86_64 or aarch64;+# the container is native, not emulated).+#+# Install on a machine:+# tar -xzf openworker-<version>-linux-<arch>.tar.gz -C ~/.local/share+# ln -sf ~/.local/share/openworker/openworker ~/.local/bin/openworker+set -euo pipefail++HERE="$(cd "$(dirname "$0")" && pwd)"+ROOT="$(dirname "$HERE")"+OUT="$HERE/dist"+IMAGE="${OPENWORKER_BUILD_IMAGE:-python:3.12-bullseye}"+VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' "$ROOT/pyproject.toml" | head -1)"+ARCH="$(uname -m)"+NAME="openworker-$VERSION-linux-$ARCH"++mkdir -p "$OUT"+rm -rf "$OUT/openworker" "$OUT/$NAME.tar.gz" "$OUT/$NAME.tar.gz.sha256"++echo "==> [1/3] building $NAME in $IMAGE"+# The source is mounted read-only and copied inside, so the build leaves nothing in the+# checkout; only packaging/dist/ is written, owned by the calling user.+docker run --rm \+ -v "$ROOT:/src:ro" -v "$OUT:/out" \+ -e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" \+ "$IMAGE" bash -euo pipefail -c '+ mkdir /work && cp -a /src/coworker /src/packaging /src/pyproject.toml /src/README.md /src/LICENSE /work/+ rm -rf /work/packaging/dist /work/packaging/build+ cd /work+ python -m venv /venv+ /venv/bin/pip install -q --upgrade pip+ # typer: only for PyInstaller, which imports mcp.cli while collecting mcp.+ /venv/bin/pip install -q ".[bedrock,openshell]" pyinstaller tzdata typer+ /venv/bin/python -c "import grpc" # OpenShell cannot be used without it+ echo "==> [2/3] PyInstaller"+ OPENWORKER_BUNDLE=cli /venv/bin/pyinstaller --noconfirm --clean --log-level WARN \+ --distpath /work/dist --workpath /work/build packaging/openworker-server.spec+ ln -s openworker /work/dist/openworker/openworker-server+ cp -a /work/dist/openworker /out/+ chown -R "$HOST_UID:$HOST_GID" /out/openworker+ '++echo "==> [3/3] packing"+"$OUT/openworker/openworker" version+tar -C "$OUT" -czf "$OUT/$NAME.tar.gz" openworker+(cd "$OUT" && sha256sum "$NAME.tar.gz" > "$NAME.tar.gz.sha256")+ls -la "$OUT/$NAME.tar.gz"+cat "$OUT/$NAME.tar.gz.sha256"diff --git a/packaging/cli_entry.py b/packaging/cli_entry.pynew file mode 100644index 00000000..146ea157--- /dev/null+++ b/packaging/cli_entry.py@@ -0,0 +1,22 @@+"""PyInstaller entry point for the Linux `openworker` program (build_linux.sh).++One program for the whole command line. Called as `openworker-server` (the bundle ships+that name as a link to the same file) it runs the server instead, as the pip install does.+"""++import os+import sys++if __name__ == "__main__":+ # Runner mode first, before anything else is imported (coworker/sandbox/launch.py).+ from coworker.sandbox.launch import maybe_run_runner++ maybe_run_runner(sys.argv[1:])+ if os.path.basename(sys.argv[0]) == "openworker-server":+ from coworker.server.run import main as server_main++ server_main()+ else:+ from coworker.cli import main++ main()diff --git a/packaging/openworker-server.spec b/packaging/openworker-server.specindex f56fb7bf..5d7d2d0b 100644--- a/packaging/openworker-server.spec+++ b/packaging/openworker-server.spec@@ -1,5 +1,7 @@# -*- mode: python ; coding: utf-8 -*--"""PyInstaller spec for the bundled `openworker-server` (desktop sidecar).+"""PyInstaller spec for the bundled `openworker-server` (desktop sidecar), and for the Linux+`openworker` program (OPENWORKER_BUNDLE=cli, see build_linux.sh): the same code, with the+whole command line (`join`, `up`, `machine`, ...) as its entry point instead of the server.One-DIR bundle (exe + `_internal/` support folder) shipped via Tauri's `resources` slot.It used to be a onefile binary in the externalBin slot, but onefile self-extracts its whole@@ -24,7 +26,7 @@ import globimport osimport sys-from PyInstaller.utils.hooks import collect_all, collect_data_files, collect_submodules+from PyInstaller.utils.hooks import collect_all, collect_data_files, collect_submodules, copy_metadata# SPECPATH is injected by PyInstaller and points at this file's directory# (<repo>/packaging). Derive everything else from it — no hardcoded paths.@@ -33,6 +35,13 @@ ROOT = os.path.dirname(PACKAGING)IS_WINDOWS = sys.platform == "win32"+# "server" (default): the desktop sidecar. "cli": the Linux `openworker` program.+BUNDLE = os.environ.get("OPENWORKER_BUNDLE", "server")+ENTRY, NAME = {+ "server": ("server_entry.py", "openworker-server"),+ "cli": ("cli_entry.py", "openworker"),+}[BUNDLE]+# Experimental (use-at-your-own-risk) connectors are excluded from official builds: the code# is stripped, not just disabled. Self-builders opt in with COWORKER_EXPERIMENTAL=1; the# loader in coworker/connectors/descriptors.py treats the missing package as a no-op.@@ -52,6 +61,9 @@ for pkg in ("coworker", "aisuite", "mcp", "ddgs", "croniter", "docstring_parser"# PyInstaller needs its own instruction.) Keep this even if the persona set changes — it# collects whatever non-.py files the package carries.datas += collect_data_files("coworker")+# The distribution's metadata, so `openworker version` and the machine handshake report the+# real version instead of 0.0.0 (importlib.metadata finds nothing in a bundle without it).+datas += copy_metadata("openworker")# The tool runner is packed into a zipapp FROM SOURCE at run time (coworker/sandbox/bundle.py)# and mounted into sandboxes, so its .py files, and aisuite's two toolkit modules it carries,@@ -110,7 +122,7 @@ for pkg in ("slack_bolt", "telegram"): # [messaging] extra — optionalpassa = Analysis(- [os.path.join(PACKAGING, "server_entry.py")],+ [os.path.join(PACKAGING, ENTRY)],pathex=[ROOT],binaries=binaries,datas=datas,@@ -127,7 +139,7 @@ exe = EXE(a.scripts,[],exclude_binaries=True,- name="openworker-server",+ name=NAME,debug=False,bootloader_ignore_signals=False,strip=False,@@ -145,5 +157,5 @@ coll = COLLECT(a.datas,strip=False,upx=False,- name="openworker-server",+ name=NAME,)