build(image): the app layers name the runtime user, so the chown layer is gone

By the maintainer's decision of 2026-11-25, recorded in the handover. The option as
offered: "Drop the duplicate chown layer", as offered: "`COPY --chown` on the app file
layers instead of a final `chown -R`. Every file under `/app` stays owned by uid 1000,
compared file by file in the rebuilt image."

`RUN chown -R ousast /app` ran after the last COPY, so it copied every file of `/app`
into a second layer: 194 MB beside the 189 MB `benchmarks` layer in the local image,
and the build of 2026-11-25 spent 311 of its 470 seconds in it. The line is removed, and
the copies it covered take `--chown=1000` as `benchmarks` already did: `pyproject.toml`,
`README.md` and `LICENSE` in one, `src` in the other. Nothing after the last COPY writes
under `/app`: the pip install runs with the uv_build backend and left nothing there in
the image built on 2026-11-25.

Two things are expected to change besides the layer. `/app` itself, which `WORKDIR`
creates, is owned by root, where `chown -R` made it uid 1000. And the files that were
gid 0 take gid 1000. No tracked use writes into `/app` as the runtime user: compose runs
in `/work` and writes under `/reports`, the wrapper `ops/ousast-docker` works in the
mounted repository, and the workflows build and push.

Tests: the new `tests/test_task_images.py::test_app_layers_carry_their_owner` fails on
a `RUN chown` in the final stage and on a `COPY` into it that does not start with
`COPY --chown=1000 `. It failed before the change (1 failed, 15 passed) and passes
after; with `tests/test_search_image.py`, 17 passed. On scratch copies it fails when
the chown line is put back and when the flag is dropped from `COPY src ./src`.
`test_digest_required_and_code_last` found its code line by `COPY src `; it accepts the
new prefix, and its ordering check is unchanged. ruff, mypy, the three gates and
compileall pass, and the gates print what they printed before the change. An independent
reviewer approved the change in one round.

Not claimed here: the rebuilt image. It follows in this step's next part, with the
proof that every file under `/app` is owned by uid 1000 and that `/app` holds the
tracked files only.
This commit is contained in:
Marius Ciepluch
2026-11-26 10:36:59 +01:00
parent 005bffb677
commit a706a7d811
2 changed files with 15 additions and 4 deletions
+3 -3
View File
@@ -36,12 +36,12 @@ RUN if getent passwd 1000 > /dev/null; then \
usermod --login ousast --home /home/ousast --move-home "$(getent passwd 1000 | cut -d: -f1)"; \
else useradd --create-home --uid 1000 ousast; fi
WORKDIR /app
COPY pyproject.toml README.md LICENSE ./
COPY src ./src
# Each layer under /app names the runtime user itself; a later `chown -R /app` would store every file twice.
COPY --chown=1000 pyproject.toml README.md LICENSE ./
COPY --chown=1000 src ./src
RUN --mount=type=cache,target=/root/.cache/pip \
/venv/bin/pip install --no-deps --no-cache-dir .
COPY --chown=1000 benchmarks ./benchmarks
RUN chown -R ousast /app
USER ousast
ENTRYPOINT ["python", "-m", "openultrasast.cli"]
CMD ["--help"]