Repository navigation
Conversation
`container_run` wraps a runnable target so that `buck2 run` (and `buck2 test`) of a Linux-configured target works on a Mac: a small POSIX launcher runs the program with Apple's `container` CLI there, mounting the project root at the same path so the absolute paths buck2 renders stay valid, and execs it directly on every other host. The wrap decision is made from the target's configuration (only `config//os:linux` targets are wrapped) and the dispatch decision at run time (`uname -s`), so action digests stay identical across hosts and wrapped targets keep working as tools on Linux executors. - prelude/container: rule, toolchain provider and launcher - prelude/toolchains/container.bzl: system_container_run_toolchain, added to system_demo_toolchains() - docs/users/how_tos/container_run.md: setup and usage guide - examples/with_prelude/container_run: CI-exercised example and launcher unit tests (fake container/uname cover the macOS path on any host) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdVaTFQQMHjXr7W3gpRL2d
Launcher: - Put `--` before the image so the container CLI cannot parse program arguments such as `---` or `--generate-completion-script` as its own. - Prefix every launcher variable with `_cr_` and apply `env` with env(1) in direct mode, so program env names like `mode` or `UID` are not clobbered. - Name the container and start a watchdog in its own process group that stops it when the CLI is killed (buck2 SIGKILLs cancelled tests; closing a terminal sends SIGHUP), instead of leaking a running VM. - Find uname, launchctl and pwd at their macOS paths too; keep verbose output linear under bash 3.2; fix the not-found hint. Rule and toolchain: - `buck2 run` of a wrapped test with `env` passes the env to the launcher instead of running the prelude's Python env injector in the image. - Leave `--platform` to the CLI when the target has no CPU constraint. - Deduplicate `ports`; reserve the `_cr_` prefix; validate `cpus`/`memory`. - Demo toolchain reads `[container_run] cli/cli_flavor` so developers can switch to a Docker-compatible CLI in .buckconfig.local. Tests, CI and docs: - Launcher tests cover args after the image, env collisions, exec, argv integrity, a pty, and the watchdog; they run in the PR workflow on Linux and macOS (bash 3.2). - The example adds a wrapped test and an end-to-end test of the container path with a fake CLI. - Docs: platform setup, per-developer CLI override, test environment, debugging, registry login, and corrected run-time details. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdVaTFQQMHjXr7W3gpRL2d
Launcher watchdog: - Only use `set -m` under bash (macOS's /bin/sh), where it leaves the process group without touching the terminal; dash takes over the controlling terminal with it. Other shells use setsid(1) if present. - Give the watchdog the system directories on PATH, and give up instead of spinning if `sleep` is unavailable (a test's `env` may replace PATH). - Leave containers started with `-d`/`--detach` alone. Rule and toolchain: - Only replace a wrapped test's RunInfo when it is the prelude's env injector and all env names are identifiers, so other test rules' RunInfo (e.g. erlang_test's shell) and unusual env names keep working. - Accept decimal memory sizes (and decimal CPUs for Docker), and require a unit on memory, which both CLIs otherwise read as bytes. Tests: read UID from the environment (bash always sets it, which broke the macOS CI step), and check the watchdog against a process-group kill with a PATH that lacks `sleep`, as buck2 does to a cancelled test. CI: a macOS workflow that runs the launcher tests, builds and tests the example with this prelude, installs Apple's container CLI, and runs a Linux target through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdVaTFQQMHjXr7W3gpRL2d
Records why `container run` cannot start a VM on hosted macOS runners. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdVaTFQQMHjXr7W3gpRL2d
Owner
Author
|
We might benefit from the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
container_runwraps a runnable target so thatbuck2 run(andbuck2 test) of a Linux-configured target works on a Mac: a small POSIXlauncher runs the program with Apple's
containerCLI there, mounting theproject root at the same path so the absolute paths buck2 renders stay
valid, and execs it directly on every other host. The wrap decision is made
from the target's configuration (only
config//os:linuxtargets arewrapped) and the dispatch decision at run time (
uname -s), so actiondigests stay identical across hosts and wrapped targets keep working as
tools on Linux executors.
to system_demo_toolchains()
unit tests (fake container/uname cover the macOS path on any host)
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01GdVaTFQQMHjXr7W3gpRL2d