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
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ All notable changes to this project are documented here, following

## [Unreleased]

## [0.2.2] - 2026-11-04

### Fixed

- **Every command hung inside a container.** The CPU budget walks the cgroup
tree up to `/sys/fs/cgroup` with `dirname`, and stopped only on an exact
match. Inside a container with its own cgroup namespace -- podman's default,
and the self-hosted GitHub runner -- `/proc/self/cgroup` says `0::/`, so the
walk started at `/sys/fs/cgroup/`, passed it, reached `/` and dirname'd `/`
forever, before printing a line. trentina's first `sdlc ci` on that runner sat
for 30 minutes. The walk now ends at the root or anywhere outside it.
- **A container's CPU quota was never read.** The walk skipped the namespace
root, which is exactly where a container's own `cpu.max` lives; it now reads
it, so a run in a 4-CPU container budgets 2 rather than half the host.
- `tests/contract.sh` runs the launcher inside a container and fails if it does
not finish in 20 seconds.

## [0.2.1] - 2026-11-04

### Fixed
Expand Down Expand Up @@ -165,7 +182,8 @@ cached tag was never refreshed — that gate had been running a two-week-old
reviewer while CI pulled fresh. Local and CI were different reviewers on the
same diff.

[Unreleased]: https://github.com/crunchtools/python-sdlc/compare/v0.2.1...HEAD
[Unreleased]: https://github.com/crunchtools/python-sdlc/compare/v0.2.2...HEAD
[0.2.2]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.2.2
[0.2.1]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.2.1
[0.2.0]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.2.0
[0.1.0]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.1.0
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ LABEL description="Every CrunchTools Python SDLC check in one image: ruff, mypy,
LABEL org.opencontainers.image.source="https://github.com/crunchtools/python-sdlc"
LABEL org.opencontainers.image.description="Every CrunchTools Python SDLC check in one image."
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
LABEL version="0.2.1"
LABEL version="0.2.2"

# What the image carries, readable without starting anything. `sdlc versions`
# prints these and a consuming repo's CI pins them.
Expand Down
2 changes: 1 addition & 1 deletion IMAGE_TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.1
0.2.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ default_install_hook_types: [pre-commit, pre-push]

repos:
- repo: https://github.com/crunchtools/python-sdlc
rev: v0.2.1
rev: v0.2.2
hooks:
- id: sdlc-commit
- id: sdlc-push
Expand Down
21 changes: 17 additions & 4 deletions bin/sdlc
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,20 @@ _cpus_in_list() { # "0-3,7,10-11" -> 7

_cgroup_cpu_ceiling() { # cpu.max from leaf to root, smallest quota wins
_dir=$(awk -F: '$2=="" {print $3; exit}' /proc/self/cgroup 2>/dev/null) || _dir=
[ -n "${_dir:-}" ] || { printf '0'; return; }
# Inside a container with its own cgroup namespace -- podman's default, and
# the GitHub runner on gloval -- the path is "/" or climbs with "..". Both
# mean "the namespace root", which is /sys/fs/cgroup itself, and the root is
# exactly where a container's quota lives, so it is read, not skipped.
# A ".." COMPONENT, not any two dots: `job..scope` is a legal cgroup name.
case "$_dir" in /|/..|/../*|*/../*|*/..) _dir= ;; esac
_path="/sys/fs/cgroup${_dir%/}"
_best=0
_path="/sys/fs/cgroup$_dir"
while [ -n "$_path" ] && [ "$_path" != "/sys/fs/cgroup" ]; do
# The walk ends AT /sys/fs/cgroup or anywhere outside it, never by hoping
# dirname lands there exactly. It used to stop only on an exact match, so
# "/sys/fs/cgroup/" walked to "/" and then dirname'd "/" forever: every
# command, `--help` included, hung inside a container before printing a
# line. That was 30 minutes of a CI job doing nothing.
while :; do
if [ -r "$_path/cpu.max" ]; then
_q=$(awk '{print $1}' "$_path/cpu.max" 2>/dev/null) || _q=max
_p=$(awk '{print $2}' "$_path/cpu.max" 2>/dev/null) || _p=100000
Expand All @@ -89,7 +99,10 @@ _cgroup_cpu_ceiling() { # cpu.max from leaf to root, smallest quota wins
if [ "$_best" -eq 0 ] || [ "$_n" -lt "$_best" ]; then _best=$_n; fi
fi
fi
_path=$(dirname "$_path")
case "$_path" in
/sys/fs/cgroup/*) _path=$(dirname "$_path") ;;
*) break ;;
esac
done
printf '%s' "$_best"
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[project]
name = "python-sdlc"
version = "0.2.1"
version = "0.2.2"
description = "One container image and one script for every CrunchTools Python SDLC check"
requires-python = ">=3.14"
license = "AGPL-3.0-or-later"
Expand Down
23 changes: 23 additions & 0 deletions tests/contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ else
ok "semgrep fails on code its rule forbids"
fi

# ---------------------------------- the launcher runs inside a container
#
# bin/sdlc's CPU budget walks the cgroup tree, and inside a container with its
# own cgroup namespace -- podman's default, and the self-hosted GitHub runner --
# /proc/self/cgroup says "0::/". The walk once never terminated there, so every
# command hung before printing a line; a CI job sat for 30 minutes. Run it in a
# container, with shims for the two programs it checks for, and give it 20
# seconds.
LSHIM=$(mktemp -d)
printf '#!/bin/sh\ncase "$*" in *show-toplevel*) pwd ;; esac\nexit 0\n' > "$LSHIM/git"
printf '#!/bin/sh\nexit 0\n' > "$LSHIM/podman"
chmod +x "$LSHIM/git" "$LSHIM/podman"
rc=0
podman run --rm -v "$PWD:/s:ro,z" -v "$LSHIM:/shim:ro,z" -w /s \
-e PATH=/shim:/usr/bin:/bin registry.fedoraproject.org/fedora:43 \
timeout 20 sh bin/sdlc --help >/dev/null 2>&1 || rc=$?
rm -rf "$LSHIM"
if [ "$rc" -eq 0 ]; then
ok "bin/sdlc runs inside a container (cgroup namespace root)"
else
bad "bin/sdlc inside a container exited $rc (124 means it hung)"
fi

# --------------------------------------- `sdlc versions` matches the build pins
#
# The version table is the image's central promise: a consuming repo pins this
Expand Down
Loading