Skip to content

chore(image): clean up apt state, opt-out env and unused tools #13

Closed

Description

@dan-petty

Problem

An audit of ghcr.io/dan-petty/devtools (20261120) on 2026-11-20 found clean-up items in the image build. Image size is not a goal now (owner, 2026-11-20); these items fix wrong state, unused tools and settings that each consumer must repeat.

Change

  • apt state: the cache mount on all of /var/lib/apt keeps extended_states out of the layer, so apt marks 687 of 764 packages as manual and apt-get autoremove removes nothing. Remove the apt cache mounts and the docker-clean / keep-cache steps (CI exports no BuildKit cache and the daily build uses --no-cache), and use one apt-get update && apt-get install ... && rm -rf /var/lib/apt/lists/*.
  • One opt-out ENV block in the final stage for the tools that devtools ships: DO_NOT_TRACK=1, OPENSPEC_TELEMETRY=0, OPENSPEC_NO_UPDATE_CHECK=1, GH_NO_UPDATE_NOTIFIER=1, npm_config_update_notifier=false, COPILOT_AUTO_UPDATE=false, DISABLE_AUTOUPDATER=1, the semgrep metrics and version-check switches, GOTELEMETRY=off. Copilot self-update is on today and keeps one 166-282 MB copy per version in the home cache (16 versions, 3.5 GB in the devcontainer home volume).
  • Unused in the final image: the mise binary (156 MB; mise is a build-time tool here) and bandit from apt (devops-cli runs bandit from its own dev group). Keep pre-commit.
  • World-writable venv lock files under /usr/local/lib/devtools/*/.lock: remove them after uv pip sync.
  • Manifests are the source: each tool is listed in four places (apt list or mise.toml, the copy loop, test/tools.sh, README) and no check finds a missing copy. Make the README point to the manifests, and add a CI check that the copy loop covers mise.toml.

Not in this item: a unique build tag and the version label (devtools#6), the lint step (devtools#6), moving the Podman and common-utils package set from the devcontainer Features into devtools, and reproducible layer digests (later, with size work).

Proof

  • apt-mark showauto in the new image lists the dependencies; apt-get -s autoremove behaves normally.
  • docker run --rm <image> env shows the opt-out block; copilot --version as uid 1000 writes no ~/.cache/copilot/pkg.
  • test/tools.sh passes; mise and bandit are absent.

Alternatives check of 2026-11-20: not-applicable.
Class: chore, no search.
Tool: none found.

Proposed design

Problem statement

The devtools image keeps wrong apt state. It repeats opt-out settings in each consumer. It ships unused tools. It leaves world-writable lock files. It lets the copy loop drift from the manifests. This change cleans the image build and makes the manifests the source of the tool list.

Acceptance criteria

Requirement: apt state is not hidden by cache mounts

The image build SHALL remove the apt cache mounts and the docker-clean and keep-cache steps, and it MUST use one apt-get update && apt-get install ... && rm -rf /var/lib/apt/lists/* sequence.

Scenario: apt marks dependencies as automatic

  • WHEN docker run --rm devtools:test sh -c 'test "$(apt-mark showauto | wc -l)" -gt 100 && apt-get -s autoremove >/dev/null' runs
  • THEN The command exits 0.

Requirement: opt-out environment block

The final stage SHALL set one ENV block with DO_NOT_TRACK=1, OPENSPEC_TELEMETRY=0, OPENSPEC_NO_UPDATE_CHECK=1, GH_NO_UPDATE_NOTIFIER=1, npm_config_update_notifier=false, COPILOT_AUTO_UPDATE=false, DISABLE_AUTOUPDATER=1, SEMGREP_SEND_METRICS=off, SEMGREP_ENABLE_VERSION_CHECK=0, and GOTELEMETRY=off.

Scenario: opt-out variables are present

  • WHEN docker run --rm devtools:test sh -c 'for v in DO_NOT_TRACK=1 OPENSPEC_TELEMETRY=0 OPENSPEC_NO_UPDATE_CHECK=1 GH_NO_UPDATE_NOTIFIER=1 npm_config_update_notifier=false COPILOT_AUTO_UPDATE=false DISABLE_AUTOUPDATER=1 SEMGREP_SEND_METRICS=off SEMGREP_ENABLE_VERSION_CHECK=0 GOTELEMETRY=off; do env | grep -qx "$v" || exit 1; done' runs
  • THEN The command exits 0.

Requirement: Copilot writes no package cache

The final image MUST disable Copilot self-update so that copilot --version writes no package cache for uid 1000.

Scenario: copilot writes no package cache

  • WHEN docker run --rm --user 1000:1000 -e HOME=/tmp/copilot-home devtools:test sh -c 'mkdir -p "$HOME" && copilot --version >/dev/null && test ! -e "$HOME/.cache/copilot/pkg"' runs
  • THEN The command exits 0.

Requirement: unused tools are absent and pre-commit remains

The final image MUST NOT contain the mise binary or the apt bandit package, and it MUST keep pre-commit.

Scenario: removed tools are absent

  • WHEN docker run --rm devtools:test sh -c '! command -v mise && ! command -v bandit && pre-commit --version' runs
  • THEN The command exits 0.

Requirement: tool test drops removed tools

The tool test MUST NOT run mise --version or bandit --version.

Scenario: tool test has no removed tools

  • WHEN ! grep -Eq '^run (mise|bandit) ' test/tools.sh runs
  • THEN The command exits 0.

Requirement: venv lock files are not world-writable

The image build SHALL remove world-writable .lock files under /usr/local/lib/devtools after uv pip sync.

Scenario: no world-writable venv lock file remains

  • WHEN docker run --rm devtools:test sh -c 'test -z "$(find /usr/local/lib/devtools -name .lock -perm -002 -print -quit)"' runs
  • THEN The command exits 0.

Requirement: manifest check passes on the checked-in files

The repository MUST make the manifests the source of the tool list by pointing the README to mise.toml and the Dockerfile apt list and by a CI check that the Dockerfile copy loop covers every mise.toml tool.

Scenario: manifest check passes

  • WHEN bash test/manifests.sh runs in the image CI job against the checked-in Dockerfile, mise.toml and README.md
  • THEN The command exits 0.

Requirement: manifest check catches drift

The manifest check MUST fail when a mise.toml tool is missing from the Dockerfile copy loop.

Scenario: manifest check fails on drift

  • WHEN bash test/manifests.sh runs in a temporary copy of the repository with one mise.toml tool removed
  • THEN The command exits 1.

Existing Tool Considered

The alternatives check in the issue body records not-applicable for this chore and names no tool. No open, maintained tool covers the whole clean-up. The clean-up uses direct edits to Dockerfile, README.md and test/tools.sh. hadolint checks Dockerfile rules but does not compare the copy loop with mise.toml. mise holds the tool list but does not generate the Dockerfile copy loop. The only new code is test/manifests.sh. Building it costs about 1,000 tokens and 30 minutes. Keeping it costs about 100 tokens per manifest change.

Key questions

  • Does removing mise from the final image break a runtime caller?: No. The only repository caller is test/tools.sh:60, which runs mise --version; the issue records that mise is a build-time tool and the final image does not need it. Remove that line from test/tools.sh. [sources: test/tools.sh:60]
  • Does removing bandit from apt break a runtime caller?: No. The apt package is at Dockerfile:55 and the only caller in this repository is test/tools.sh:23; no other file invokes bandit. The issue states that devops-cli runs bandit from its own dev group. Remove the apt package and the test line. [sources: test/tools.sh:23]
  • Which tool test lines must change?: Remove run mise --version at test/tools.sh:60 and run bandit --version at test/tools.sh:23. Keep run pre-commit --version at test/tools.sh:92. [sources: test/tools.sh:23, test/tools.sh:60, test/tools.sh:92]
  • How should apt state be cleaned?: Remove the apt cache mounts and the docker-clean and keep-cache steps, and use one apt-get update && apt-get install ... && rm -rf /var/lib/apt/lists/* sequence. The scheduled build pulls the base image and uses no BuildKit cache, so the mounts hide extended_states without saving a useful cache. (best practice) [sources: .github/workflows/image.yml:54-64]
    • Chosen: Remove cache mounts and use one apt sequence. CI exports no BuildKit cache and the daily build uses --no-cache; the mounts only hide extended_states.
    • Rejected: Keep cache mounts and mark packages automatic. This adds a step and does not fix the hidden apt state.
    • Rejected: Keep cache mounts and remove lists only. This keeps extended_states out of the layer and leaves the wrong manual marks.
  • How should the opt-out settings reach the final image?: Set one ENV block in the final devtools stage, so every consumer inherits it. The block sets the ten variables named in the issue body. (best practice) [sources: README.md:13-18]
    • Chosen: One ENV block in the final stage. The final stage is the image that consumers use as a base, so this gives one place to audit and stops each consumer from repeating the settings.
    • Rejected: Per-tool wrapper scripts. This adds files and hides the settings from docker run --rm devtools:test env.
    • Rejected: Leave the settings to consumers. This repeats work and lets the Copilot cache grow in each home volume.
  • Which Semgrep environment variables disable metrics and the version check?: Set SEMGREP_SEND_METRICS=off and SEMGREP_ENABLE_VERSION_CHECK=0 in the final ENV block. The image test already runs semgrep --disable-version-check because a version check with no network waits 98 s (test/tools.sh:93-94); the ENV variable applies the same setting to every consumer run. (best practice) [sources: test/tools.sh:93-94]
    • Chosen: Set both Semgrep variables in the ENV block. This applies to every Semgrep run in the image.
    • Rejected: Pass CLI flags in test/tools.sh only. This covers the test but not consumer runs.
  • How should the Dockerfile copy loop stay aligned with mise.toml?: Add test/manifests.sh, a shell check that reads the mise.toml tool names and the Dockerfile copy loop, and call it from the image workflow. The check fails when a mise.toml tool is missing from the copy loop. (best practice) [sources: mise.toml:6-36, .github/workflows/image.yml:75-85]
    • Chosen: Add a shell check in test/manifests.sh. It adds no dependency and fails CI on a missing copy.
    • Rejected: Generate the copy loop from mise.toml at build time. This is a larger build change than the issue asks for.
    • Rejected: Rely on README and review. No check finds a missing copy.
  • How should the manifest check resolve a mise.toml tool key to its command name?: Use the tool key as the command name, except for GitHub backend keys, where the command is the part after the slash, and the aliases opentofu to tofu and argo-rollouts to kubectl-argo-rollouts. The check fails when a resolved command is missing from the Dockerfile copy loop. (best practice) [sources: mise.toml:6-36, test/tools.sh:61-87]
    • Chosen: Use a small alias map in the check. It keeps the check self-contained and handles the known command names.
    • Rejected: Run mise which for each tool in CI. This adds mise to the CI job and a new action or stage.
    • Rejected: Generate the copy loop from mise.toml. This is a larger build change than the issue asks for.
  • Where should the README get the tool list?: Point the README to mise.toml, the apt package list in the Dockerfile, python/, npm/ and test/tools.sh, and remove the duplicated table. (best practice) [sources: README.md:43-55, mise.toml:6, test/tools.sh:20-101]
    • Chosen: Point to the manifests and remove the table. This keeps one source for each tool list.
    • Rejected: Keep the table and add a check. This keeps a second list that can drift.
    • Rejected: Remove the tool section. Users still need a pointer to the manifests.
  • How should the world-writable venv lock files be removed?: Remove them in the python-tools stage after the uv pip sync loop, before the final stage copies /usr/local/lib/devtools/. The lock files are not needed after the sync. (best practice) [sources: README.md]
    • Chosen: Remove after uv pip sync. The files are not needed after the sync and this clears the world-writable bit.
    • Rejected: Change the mode with chmod. This keeps an unneeded lock file in the image.
    • Rejected: Leave the files. This keeps world-writable files in the final image.
  • Does the final image keep pre-commit?: Yes. The issue says keep pre-commit, and test/tools.sh:92 runs pre-commit --version; the change removes only the apt bandit package and the mise binary. [sources: test/tools.sh:92]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/chore
    status/new
    value/medium
    effort/medium
    source/agent
    scope/image
    on Nov 20, 2026
  2. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 20, 2026
  4. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. added
    status/ready
    and removed
    status/new
    on Nov 20, 2026
  6. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    The Copilot proof of this item cannot pass as written. #14 delivers the other items and sets COPILOT_AUTO_UPDATE=false, but it does not add the Copilot cache check.

    Evidence (@github/copilot 1.0.114, linux-x64, a new empty HOME, no XDG_CACHE_HOME):

    • copilot --version with no COPILOT_AUTO_UPDATE: writes ~/.cache/copilot/pkg/linux-x64/1.0.114, 282 MB.
    • COPILOT_AUTO_UPDATE=false copilot --version: writes the same folder, 282 MB.

    The native binary is a launcher. At the first start of each version, it writes its bundled package to the first folder of this list: $COPILOT_PKG_CACHE_HOME/pkg, $COPILOT_CACHE_HOME/pkg, ${XDG_CACHE_HOME:-~/.cache}/copilot/pkg, $COPILOT_HOME/pkg, ~/.copilot/pkg. COPILOT_AUTO_UPDATE=false (and --no-auto-update) stops only the download of newer versions. Thus the home cache still gets one copy for each Copilot version of a new image.

    Options for the owner: accept one copy per image version and close this item when #14 merges, or file a separate item for the package folder (for example COPILOT_PKG_CACHE_HOME). #14 adds neither.

  8. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Owner decision (2026-11-20), as recommended: accept one unpacked Copilot package per Copilot version in ~/.cache/copilot/pkg. COPILOT_AUTO_UPDATE=false stops the downloads of newer versions, which made the 16 copies. So the requirement "Copilot writes no package cache" becomes "Copilot downloads no newer version by itself". No extra code moves the package folder. PR #14 closes this issue.

  9. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Two corrections to the lists of this item. #14 applies them.

    bandit stays in the image. The published devops-cli devcontainer image is FROM devtools. Its lock stage exports the venv with uv export --locked --no-dev --extra review (devops-cli .devcontainer/Dockerfile:17). bandit is only in the dev dependency group of devops-cli (pyproject.toml), so the venv of that image has no bandit. The apt bandit of devtools is the only bandit on PATH there. Without it, devops scan in a child repository reports bandit as unavailable and does not fail. Thus the item "devops-cli runs bandit from its own dev group" is wrong for the published image. The apt list keeps bandit, and test/tools.sh runs bandit --version again.

    GOTELEMETRY=off is not in the ENV block. The Go toolchain does not read GOTELEMETRY from the environment: src/cmd/go/internal/help/helpdoc.go (golang/go, master) lists it under "Additional information available from 'go env' but not read from the environment". golang.org/x/telemetry reads its mode from a file that go telemetry off writes. The image also has no Go toolchain. The ENV block has the other nine variables.

  10. added
    status/in-review
    and removed
    status/ready
    on Nov 20, 2026
  11. removed
    status/in-review
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/imagesource/agenttype/chorevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions