Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(docker): minimize Canvas runtime packages (#18134)

Graham Neubig7af57f8a5411
diff --git a/__tests__/scripts/docker-runtime-packages.test.ts b/__tests__/scripts/docker-runtime-packages.test.ts
new file mode 100644
index 0000000000..0c96c2b8ce
--- /dev/null
+++ b/__tests__/scripts/docker-runtime-packages.test.ts
@@ -0,0 +1,73 @@
+// @vitest-environment node
+import { execFileSync } from "node:child_process";
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import { afterEach, describe, expect, it } from "vitest";
+
+const repoRoot = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../..",
+);
+const dockerfilePath = path.join(repoRoot, "docker/Dockerfile");
+const temporaryDirectories: string[] = [];
+
+function readDockerfile(): string {
+ return readFileSync(dockerfilePath, "utf-8");
+}
+
+afterEach(() => {
+ for (const directory of temporaryDirectories.splice(0)) {
+ rmSync(directory, { recursive: true, force: true });
+ }
+});
+
+describe("Docker runtime package metadata", () => {
+ it("keeps the Canvas snapshot at least as new as its agent-server base", () => {
+ const match = readDockerfile().match(
+ /^ARG DEBIAN_SNAPSHOT=(\d{8}T\d{6}Z)$/m,
+ );
+
+ expect(match?.[1]).toBeTruthy();
+ expect(match?.[1].localeCompare("20260920T000000Z")).toBeGreaterThanOrEqual(
+ 0,
+ );
+ });
+
+ it("selects a snapshot after the seven-day observation period", () => {
+ const directory = mkdtempSync(path.join(tmpdir(), "canvas-dockerfile-"));
+ temporaryDirectories.push(directory);
+ const candidate = path.join(directory, "Dockerfile");
+ writeFileSync(
+ candidate,
+ "FROM debian:trixie-slim\nARG DEBIAN_SNAPSHOT=20260913T000000Z\n",
+ );
+
+ execFileSync(
+ "python3",
+ [
+ path.join(repoRoot, ".github/scripts/update_debian_snapshot.py"),
+ "--dockerfile",
+ candidate,
+ "--now",
+ "2026-10-07T23:03:00Z",
+ "--skip-network-check",
+ ],
+ { stdio: "pipe" },
+ );
+
+ expect(readFileSync(candidate, "utf-8")).toContain(
+ "ARG DEBIAN_SNAPSHOT=20260930T000000Z",
+ );
+ });
+
+ it("does not retain PostgreSQL development packages at runtime", () => {
+ const dockerfile = readDockerfile();
+
+ expect(dockerfile).not.toMatch(/apt-get install[^;]*libpq(?:-dev|5)/s);
+ expect(dockerfile.indexOf("apt-get upgrade")).toBeLessThan(
+ dockerfile.indexOf('uv pip install --system "openhands-automation'),
+ );
+ });
+});
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 07c9a2eeea..f69b3639c8 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -95,11 +95,10 @@ ENV VITE_POSTHOG_API_KEY=${VITE_POSTHOG_API_KEY}
USER root
-# Install system deps required by automation's transitive dependencies
-# (asyncpg needs libpq, which the agent-server base image may not include).
-# Refresh inherited packages after adding dependencies so the final image
-# includes available security fixes.
-ARG DEBIAN_SNAPSHOT=20260913T000000Z
+# Refresh inherited packages so the final image includes available security
+# fixes. asyncpg publishes wheels for the supported Python and architectures
+# and implements the PostgreSQL protocol directly, so no libpq package is needed.
+ARG DEBIAN_SNAPSHOT=20260930T000000Z
RUN if command -v apt-get >/dev/null 2>&1; then \
printf '%s\n' \
'Types: deb' \
@@ -117,7 +116,6 @@ RUN if command -v apt-get >/dev/null 2>&1; then \
'Check-Valid-Until: no' \
> /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
- apt-get install -y --no-install-recommends libpq-dev && \
apt-get upgrade -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/*; \
fi