Skip to content

chore: merge final consecutive RUN in Dockerfile (close docker:S7031)#12

Merged
CybotTM merged 2 commits into
mainfrom
chore/dockerfile-merge-final-runs
May 22, 2026
Merged

chore: merge final consecutive RUN in Dockerfile (close docker:S7031)#12
CybotTM merged 2 commits into
mainfrom
chore/dockerfile-merge-final-runs

Conversation

@CybotTM
Copy link
Copy Markdown
Member

@CybotTM CybotTM commented May 21, 2026

Summary

Closes the last remaining SonarCloud OPEN issue on main: docker:S7031 ("Merge this RUN instruction with the consecutive ones") at Dockerfile:201.

After ea909c9's chown-hardening + first RUN consolidation, two consecutive RUNs remained in the runtime stage:

  • RUN set -eux; mkdir -p /var/lib/snipeit && cp ... && chown storage,bootstrap/cache,/var/lib/snipeit && chmod entrypoint
  • RUN mkdir -p /run/php-fpm && chown www-data /run/php-fpm

Both are filesystem-setup steps that can share an image layer. Folded into a single RUN; mkdir picks up /run/php-fpm and chown extends to it. Net -1 image layer, no functional change.

Test plan

  • docker buildx build --check . — no warnings
  • Local amd64 build succeeds
  • ls -lhd /run/php-fpm in built image: drwxr-xr-x 2 www-data www-data — identical to pre-merge state
  • CI green (multi-arch build + smoke test)

SonarCloud projected state after merge

  • OPEN issues: 1 → 0
  • Security hotspots: 2 (unchanged):
    • HIGH Dockerfile:193COPY --chown=root:www-data (defense-in-depth chown; SonarCloud rule wants any group ownership flagged for review)
    • MEDIUM Dockerfile:131php:fpm-alpine runs as root by default (intentional; entrypoint drops to www-data via su-exec after chown'ing fresh volumes)

Both hotspots are by-design and need to be marked REVIEWED + SAFE in the SonarCloud UI. The repo has no SONAR_TOKEN secret, so this can't be automated.

Copilot AI review requested due to automatic review settings May 21, 2026 21:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Consolidates the remaining consecutive RUN instructions in the runtime stage of the Dockerfile to satisfy SonarCloud rule docker:S7031 and reduce image layers, while keeping the same filesystem-setup behavior.

Changes:

  • Merged the /run/php-fpm directory setup into the existing runtime-stage filesystem-setup RUN to remove an extra layer.
  • Expanded/rewrote the surrounding Dockerfile commentary to document the runtime-stage setup steps and rationale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request consolidates multiple RUN instructions in the Dockerfile into a single layer to comply with SonarCloud rule docker:S7031 and reduce the number of image layers. Specifically, the creation and ownership assignment of the /run/php-fpm directory have been merged into the main setup block, and the internal documentation has been updated to reflect these changes. I have no feedback to provide as there were no review comments.

CybotTM added 2 commits May 22, 2026 07:15
SonarCloud reported docker:S7031 ("Merge this RUN instruction with the
consecutive ones") at Dockerfile:201 after the runtime-stage cleanup in
ea909c9. The remaining two RUNs were:

  RUN set -eux; mkdir -p /var/lib/snipeit && cp deps-manifest.txt && chmod && rm && chown storage bootstrap/cache /var/lib/snipeit && chmod entrypoint.sh
  RUN mkdir -p /run/php-fpm && chown www-data:www-data /run/php-fpm

Both are filesystem-setup steps that can run in the same layer. Folded
into a single RUN: mkdir picks up /run/php-fpm too, chown gets it via
the existing -R group, the comment block above is restructured to
document all four logical blocks (manifest / writable surfaces /
socket dir / executable bit). One fewer image layer.

Verified locally:
- buildx --check: no warnings
- runtime image builds clean
- `ls -lhd /run/php-fpm` shows `drwxr-xr-x 2 www-data www-data` —
  permissions identical to the pre-merge layer-pair.

SonarCloud quality state on main projected after this lands:
  OPEN issues: 1 → 0 (this was the last)
  Hotspots: 2 (unchanged — Dockerfile:131 root-by-design,
                          Dockerfile:193 chown=root:www-data is the
                          conventional pattern; both need to be marked
                          REVIEWED+SAFE in the SonarCloud UI by a
                          project admin, since the repo has no
                          SONAR_TOKEN secret for API-based marking).

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
Copilot caught two inaccuracies in the comment block introduced by
3cf6820. Both are fixed in this commit.

1. Dockerfile comment claimed `/run/php-fpm` is "re-chown'd by
   entrypoint.sh", but the entrypoint's chown list only covered
   storage, bootstrap/cache, /var/lib/snipeit. Added `/run/php-fpm`
   to the entrypoint's mkdir + chown blocks so the claim becomes
   true — and so that the tmpfs case (compose mounts a tmpfs at
   /run/php-fpm, which masks the image-layer chown) works without
   relying on tmpfs default 1777 mode. Standalone `docker run`
   keeps using the image-layer chown.

2. Dockerfile comment said "NO TCP port is exposed", but the base
   image php:8.5-fpm-alpine inherits `EXPOSE 9000` as OCI metadata.
   Dockerfile has no `UNEXPOSE`. The real security property is that
   nothing LISTENS on TCP 9000 — our `php-fpm.d/zz-snipe-it.conf`
   sets `listen = /run/php-fpm/snipeit.sock`, so the FastCGI bypass
   is closed by config, not by the absence of EXPOSE metadata.
   Comment rewritten to be accurate about this distinction.

Verified:
- shellcheck clean on entrypoint.sh
- bash -n clean
- docker buildx build --check: no warnings
- runtime image builds clean
- `ls -lhd /run/php-fpm` in the rebuilt image: drwxr-xr-x www-data
  (same ownership as before — the additional entrypoint chown is a
  no-op when the image-layer chown already matches, and the safety
  net for the tmpfs case).

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@CybotTM CybotTM force-pushed the chore/dockerfile-merge-final-runs branch from a2f85a8 to 0b3d762 Compare May 22, 2026 05:15
@sonarqubecloud
Copy link
Copy Markdown

@CybotTM CybotTM merged commit ad1aa70 into main May 22, 2026
18 of 19 checks passed
@CybotTM CybotTM deleted the chore/dockerfile-merge-final-runs branch May 22, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants