Files
computer-playbook/utils/install/lint/hadolint.py
T
kevinveenbirkenbachandClaude Opus 5 eda9474e37 test(lint): refuse a default in os.environ.get, and resolve the 25 sites
The deploy decides what ADAPTER_PORT or OPENWEBUI_ADMIN_NAME is and
writes it into the environment. A default in the reader is a second place
that value lives, and it is the one nobody greps for. os.environ["X"]
fails loudly on a missing key, which is the behaviour a misconfiguration
deserves.

Empty values stay free, because they add no second source and only say
absent: "", None, False, 0, the empty containers, and the "[]"/"{}" a
json.loads reader hands an absent variable. A default that is itself an
environ.get is free too, since it reads the one source again under
another key; a literal ending such a chain is still reported. Detection
runs on the parsed tree, so a call split across lines reads the same.

Five sites were real duplication and lost their default: the adapter
port, openwebui's admin name (a role that runs as a bot user), odoo's
OIDC uid field, seaweedfs' public-primary flag, and the swarm hosts
entry IP. Nineteen carry a nocheck naming why the value is not the
deploy's: contributor tooling whose default is the only source, test
scaffolding that writes the file it names, and two readers of
CA_TRUST_CERT_EXTRA_HOST, which nothing in the repo sets.

utils/diagnostics/container.py resolves without a marker: RESCUE_DEPTH is
a recursion base case, and the integer 0 says what the string "0" said.
The file sits exactly at the 500-line cap, so a comment line was not
available.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-14 00:26:55 +02:00

71 lines
2.2 KiB
Python

"""Install hadolint via GitHub-release prebuilt binary."""
from __future__ import annotations
import os
import platform
import tempfile
from pathlib import Path
from utils.install.github_release import download_release_asset
from utils.install.lint.pinned import resolve_release
from utils.install.primitives import (
ensure_dir_on_path,
install_with_optional_sudo,
log,
which,
)
# nocheck: environ-get-default contributor tooling, never deployed: no inventory or image declares HADOLINT_INSTALL_DIR, it only lets a workstation without write access to /usr/local/bin redirect the binary
_DEFAULT_INSTALL_DIR = os.environ.get("HADOLINT_INSTALL_DIR", "/usr/local/bin")
def _detect_os() -> str:
system = platform.system()
if system == "Linux":
return "Linux"
if system == "Darwin":
return "Darwin"
raise RuntimeError(f"Unsupported OS for hadolint prebuilt binary: {system}")
def _detect_arch() -> str:
machine = platform.machine().lower()
if machine in ("x86_64", "amd64"):
return "x86_64"
if machine in ("aarch64", "arm64"):
return "arm64"
raise RuntimeError(
f"Unsupported architecture for hadolint prebuilt binary: {machine}"
)
def _install_binary() -> None:
slug, version = resolve_release("hadolint")
asset_name = f"hadolint-{_detect_os()}-{_detect_arch()}"
url = f"https://github.com/{slug}/releases/download/v{version}/{asset_name}"
log(f"Installing hadolint v{version} from GitHub releases")
with tempfile.TemporaryDirectory() as tmpdir:
binary_src = Path(tmpdir) / "hadolint"
download_release_asset(url, str(binary_src))
install_with_optional_sudo(["install", "-d", _DEFAULT_INSTALL_DIR])
dst = str(Path(_DEFAULT_INSTALL_DIR) / "hadolint")
install_with_optional_sudo(["install", "-m", "0755", str(binary_src), dst])
def ensure() -> None:
if which("hadolint"):
return
log("Missing command 'hadolint'. Installing official prebuilt binary.")
_install_binary()
ensure_dir_on_path(_DEFAULT_INSTALL_DIR)
if not which("hadolint"):
raise RuntimeError(
"Command 'hadolint' is still unavailable after installation."
)