Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/prek-consts/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl EnvVars {
pub const SSL_CERT_FILE: &'static str = "SSL_CERT_FILE";
pub const SSL_CERT_DIR: &'static str = "SSL_CERT_DIR";
pub const PREK_CONTAINER_RUNTIME: &'static str = "PREK_CONTAINER_RUNTIME";
pub const PREK_DOCKER_NO_INIT: &'static str = "PREK_DOCKER_NO_INIT";
pub const PREK_QUIET: &'static str = "PREK_QUIET";
pub const PREK_LOG_TRUNCATE_LIMIT: &'static str = "PREK_LOG_TRUNCATE_LIMIT";

Expand Down
4 changes: 3 additions & 1 deletion crates/prek/src/languages/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ impl Docker {
};
let volume = format!("{}:/src:rw{z}", work_dir.display());

if !CONTAINER_RUNTIME.is_apple_container() {
if !CONTAINER_RUNTIME.is_apple_container()
&& !EnvVars::var_as_bool(EnvVars::PREK_DOCKER_NO_INIT).unwrap_or(false)
{
// Run an init inside the container that forwards signals and reaps processes
command.arg("--init");
}
Expand Down
3 changes: 3 additions & 0 deletions docs/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ Runtime behavior:
- The container is run with `--entrypoint` set to the hook `entry`, so the image’s default command is not used when filenames are passed.
- Environment variables configured via `env` are passed using `-e`.
- On Linux, prek tries to run as a non-root user and handles rootless Podman with `--userns=keep-id`.
- For Docker and Podman, prek passes `--init` so signals are forwarded and child processes are reaped inside the container.

Use `docker` when you need a language runtime that isn’t otherwise supported; the container provides the execution environment.

!!! note "prek-only"

prek auto-detects the container runtime (Docker, Podman, or [Container](https://github.com/apple/container)) and can be overridden with `PREK_CONTAINER_RUNTIME`.
Set `PREK_DOCKER_NO_INIT=1` to skip Docker's `--init` flag in container environments that cannot run the init helper. This is a compatibility escape hatch; disabling `--init` can leave containers running after Ctrl-C if the container's PID 1 does not handle forwarded signals.
See [Environment Variable Reference](reference/environment-variables.md) for details.

### docker_image
Expand All @@ -209,6 +211,7 @@ Runtime behavior:

- Uses the same bind-mount and `/src` working directory as `docker` hooks.
- Environment variables configured via `env` are passed using `-e`.
- Uses the same `--init` behavior as `docker` hooks.

If the image already defines an `ENTRYPOINT`, you can omit `--entrypoint` in `entry`. Otherwise, specify it explicitly in `entry`.

Expand Down
6 changes: 6 additions & 0 deletions docs/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ Options:
- `podman`
- `container` (Apple's Container runtime on macOS, see [container](https://github.com/apple/container))

### `PREK_DOCKER_NO_INIT`

Disable passing `--init` to Docker and Podman when running `docker` and `docker_image` hooks.
This is a compatibility escape hatch for container environments that cannot run Docker's init helper.
Disabling `--init` can leave containers running after Ctrl-C if the container's PID 1 does not handle forwarded signals.

### `PREK_LOG_TRUNCATE_LIMIT`

Control the truncation limit for command lines shown in trace logs (`Executing ...`).
Expand Down
Loading