fix(docker): pass RUNTIME_HOME=/root for root bake targets

The root image variants (runtime, runtime-code, runtime-slim,
runtime-code-slim) set RUNTIME_USER=root but left RUNTIME_HOME at the
Dockerfile default of /home/nonroot, so VOLUME and WORKDIR pointed at
/home/nonroot while the process ran with HOME=/root and ~/.headroom
landed in the container layer instead of the volume.

Fixes #4443
This commit is contained in:
drakeo338
2026-10-23 12:46:32 +00:00
parent e995eb9f1d
commit ae30825a10
2 changed files with 29 additions and 0 deletions
+4
View File
@@ -21,6 +21,7 @@ target "runtime" {
args = {
HEADROOM_EXTRAS = "proxy,bedrock"
RUNTIME_USER = "root"
RUNTIME_HOME = "/root"
}
}
@@ -39,6 +40,7 @@ target "runtime-code" {
args = {
HEADROOM_EXTRAS = "proxy,code,bedrock"
RUNTIME_USER = "root"
RUNTIME_HOME = "/root"
}
}
@@ -57,6 +59,7 @@ target "runtime-slim" {
args = {
HEADROOM_EXTRAS = "proxy,bedrock"
RUNTIME_USER = "root"
RUNTIME_HOME = "/root"
}
}
@@ -75,6 +78,7 @@ target "runtime-code-slim" {
args = {
HEADROOM_EXTRAS = "proxy,code,bedrock"
RUNTIME_USER = "root"
RUNTIME_HOME = "/root"
}
}
+25
View File
@@ -156,6 +156,31 @@ def test_every_published_docker_variant_includes_bedrock_auth_dependencies() ->
assert {"boto3", "botocore"} <= bedrock_names
def test_root_docker_bake_targets_pass_runtime_home_root() -> None:
"""Root image variants must declare the volume/workdir under ``/root`` (#4443).
``RUNTIME_HOME`` defaults to ``/home/nonroot`` in the Dockerfile, so a bake
target with ``RUNTIME_USER = "root"`` that omits it ships an image whose
VOLUME and WORKDIR are ``/home/nonroot`` while the process runs with
``HOME=/root``; ``~/.headroom`` then lands in the container layer.
"""
bake = (ROOT / "docker-bake.hcl").read_text(encoding="utf-8")
blocks = re.findall(r'^target "([^"]+)" \{\n(.*?)^\}', bake, flags=re.S | re.M)
root_targets = {
name: body for name, body in blocks if re.search(r'RUNTIME_USER\s*=\s*"root"', body)
}
assert set(root_targets) == {"runtime", "runtime-code", "runtime-slim", "runtime-code-slim"}
missing = [
name
for name, body in root_targets.items()
if not re.search(r'RUNTIME_HOME\s*=\s*"/root"', body)
]
assert not missing, f"root bake targets without RUNTIME_HOME=/root: {missing}"
for name, body in blocks:
if re.search(r'RUNTIME_USER\s*=\s*"nonroot"', body):
assert "RUNTIME_HOME" not in body or "/home/nonroot" in body, name
def test_public_docker_instructions_use_the_current_organization_package() -> None:
"""Do not send users back to the personal GHCR package frozen at 0.27.0."""
public_docs = (