Repository navigation
feat: add hadolint linting step to container workflow - #2028
josecelano merged 11 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds hadolint-based linting for the repository Containerfile, integrating it into both the GitHub Actions container workflow and the local pre-commit hook, with a global .hadolint.yaml configuration and supporting documentation/metadata updates.
Changes:
- Added a new
.hadolint.yamlto centrally configure ignored hadolint rules (with rationale). - Added a hadolint lint step to
.github/workflows/container.yamland tocontrib/dev-tools/git/hooks/pre-commit.sh(only whenContainerfileis staged). - Updated documentation and metadata conventions (
semantic-links, issue draft spec, and spellchecker dictionary).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
project-words.txt |
Adds “Dockerfiles” to the project dictionary for spellcheck consistency. |
docs/skills/semantic-skill-link-convention.md |
Documents semantic-links placement patterns and adds the related-artifacts marker. |
docs/issues/drafts/1460-add-hadolint-to-container-workflow.md |
Draft spec describing the hadolint workflow/config approach and policy. |
contrib/dev-tools/git/hooks/pre-commit.sh |
Adds a hadolint step gated on staged Containerfile changes. |
Containerfile |
Adds a semantic-links comment referencing .hadolint.yaml for discoverability. |
.hadolint.yaml |
New global hadolint ignore configuration with rationale for ignored rules. |
.github/workflows/container.yaml |
Adds a hadolint lint step before Buildx setup/build steps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2028 +/- ##
===========================================
+ Coverage 81.50% 81.61% +0.11%
===========================================
Files 342 342
Lines 24337 24337
Branches 24337 24337
===========================================
+ Hits 19835 19862 +27
+ Misses 4202 4177 -25
+ Partials 300 298 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
.hadolint.yaml:43
- The DL4006 rationale currently states the
curl | bashURL is “pinned” and that acurl --failguard is not used, but the Containerfile uses a moving.../main/...URL and already passes-sSf(includes--fail). This makes the rationale misleading and also doesn’t clearly explain the real risk of ignoringpipefailforcurl | bashpipelines.
# - `curl ... | bash`: downloads a trusted install script from a pinned
# HTTPS URL (raw.githubusercontent.com/cargo-bins/cargo-binstall). The
# source is verified via TLS 1.2 and the URL is controlled by the project
# we depend on. While `curl | bash` is high-impact, the risk is mitigated
# by the signed HTTPS transport and the trusted upstream. A `curl --fail`
…ecks/ Move format-project-words.sh from contrib/dev-tools/git/ to contrib/dev-tools/checks/ and extract the inline hadolint command from pre-commit.sh into a standalone lint-containerfile.sh sensor. Update pre-commit.sh to reference the checks/ scripts instead of the old paths. Both sensor scripts now compute PROJECT_ROOT from their new location (../../.. instead of ../.., since they moved one directory deeper relative to the repo root). Part of the sensor/harness architecture design under EPIC torrust#2003, tracked in issue torrust#1460.
32f1883 to
da1b4f3
Compare
…ve test alongside sensor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
contrib/dev-tools/checks/tests/test-format-project-words.sh:6
- PROJECT_ROOT is computed three directories up from contrib/dev-tools/checks/tests/, which resolves to contrib/dev-tools instead of the repository root. This makes the subsequent cp paths ("${PROJECT_ROOT}/contrib/dev-tools/...") incorrect and will break these tests.
This issue also appears on line 14 of the same file.
contrib/dev-tools/checks/tests/test-format-project-words.sh:23
- The pre-commit hook now invokes ./contrib/dev-tools/checks/lint-containerfile.sh, but the test fixture only copies format-project-words.sh. This will cause the pre-commit invocation in these tests to fail with “No such file or directory”. Also, the hadolint sensor expects to run inside a git work tree, so the fixture should initialize an empty repo so
git diff --cachedcan run deterministically.
…files Add header comments linking: - format-project-words.sh to its test file with manual run reminder - lint-containerfile.sh with note that no automated tests exist yet - test-format-project-words.sh to its sensor with manual run reminder All reference EPIC torrust#2003 for the long-term automation harness redesign.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
contrib/dev-tools/checks/tests/test-format-project-words.sh:13
PROJECT_ROOTis computed with only three..segments, which resolves to thecontrib/directory (not the repository root). That makes subsequent paths like${PROJECT_ROOT}/contrib/dev-tools/...incorrect (they becomecontrib/contrib/...) and breaks the test fixture setup when run manually.
contrib/dev-tools/git/hooks/pre-commit.sh:31- This change moves the dictionary formatter invocation to
contrib/dev-tools/checks/format-project-words.sh, but the old pathcontrib/dev-tools/git/format-project-words.shno longer exists (and is still referenced from multiple docs/skills). Without either updating those references or providing a small wrapper at the old path, contributors following the docs will hit a broken command.
declare -a STEPS=(
"Formatting project dictionary|./contrib/dev-tools/checks/format-project-words.sh"
"Checking for unused dependencies (cargo machete --with-metadata)|cargo machete --with-metadata"
…DL3008 rationale, redundant skill-link
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
contrib/dev-tools/checks/tests/test-format-project-words.sh:13
PROJECT_ROOTis computed as three directories up fromcontrib/dev-tools/checks/tests, which resolves to<repo>/contribrather than the repository root. That makes subsequent paths like${PROJECT_ROOT}/contrib/dev-tools/...expand to<repo>/contrib/contrib/...and breaks these integration tests when run manually.
This issue also appears on line 26 of the same file.
contrib/dev-tools/checks/tests/test-format-project-words.sh:30
- The fixture copies
pre-commit.sh, but the hook now includes the hadolint step (./contrib/dev-tools/checks/lint-containerfile.sh). In this test fixture there is nolint-containerfile.sh, so the manual integration testit_should_continue_pre_commit_checks_when_dictionary_is_already_formattedwill fail when it reaches that step.
|
ACK 3d98c36 |
70a6b4e style(issues): format archived hadolint verification tables (Jose Celano) 170c732 docs(git): clarify GPG timeout handling (Jose Celano) cadb577 docs(issues): reconcile draft issue lifecycle (Jose Celano) Pull request description: ## Summary Reconciles stale issue-documentation lifecycle state and clarifies the supporting workflows. - Archives completed issue #1460 under parent EPIC #1457, with evidence from merged PR #2028. - Removes the superseded #1840 cache-layer draft after replacement issue #1869 closed. - Prefixes the API v2 draft with known parent EPIC #144. - Documents parent-EPIC draft naming, explicit `epic` metadata, and reconciliation of drafts already linked to GitHub issues. ## Validation - `TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-commit.sh` Related to #1460, #1869, and #1840. ACKs for top commit: josecelano: ACK 70a6b4e Tree-SHA512: 2db58f768c293bac3ee430e224b0c26fc3ac3d8e0e1451f35cc1e2eedccb65318d7a499c0a5c97ee4a4be7531958ce1e5b5b29887a313e6174ce831b1a942b6d
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of #2028 as it stands at e170b96 on the default branch.
What still runs: .hadolint.yaml and contrib/dev-tools/checks/lint-containerfile.sh are unchanged since the merge, 7da1e10. The hadolint invocation at .github/workflows/container.yaml:83-91 is also unchanged and still runs before the image build in the test job, which every publish job depends on through context. The pre-commit hook still calls the script, at contrib/dev-tools/git/hooks/pre-commit.sh:63.
[Major] contrib/dev-tools/checks/lint-containerfile.sh:55 exits with ${PIPESTATUS[0]}. That is the status of git show, the first command of the pipeline at lines 47-52, not hadolint's status, which is ${PIPESTATUS[1]}; the comment at line 54 says the opposite. So when a staged Containerfile fails hadolint, the script exits 0 and the hook marks the check PASS. In its default concise output the hook then leaves hadolint's findings in a log file that it prints only on failure. The same happens when docker run itself fails (daemon not running, image pull refused) after git show has already written the file into the pipe. CI still rejects such a file, but the local check cannot fail on what it exists to catch, and it tells the contributor that every check passed. Smallest fix: replace line 55 with exit $?, as the no-config branch at line 44 already does. Under the script's set -o pipefail (line 14), that is hadolint's status whenever hadolint or docker run fails, and git show's status otherwise.
[Minor] The staged-file check at contrib/dev-tools/checks/lint-containerfile.sh:25-35 cannot tell its cases apart. Under pipefail a pipeline reports the status of its rightmost failing command. So when git diff fails (outside a work tree it exits 129), grep -q reads nothing and exits 1, and the script prints "Containerfile unchanged, skipping hadolint" and exits 0. The comment at lines 23-24 says the construction prevents exactly that outcome. The reverse also happens: when git diff is still writing after grep -q has matched Containerfile, which sorts near the top of a long staged list, SIGPIPE kills git diff. The pipeline then reports 141, and the script exits 2 with "not a git repository?" even though it runs inside one. Smallest fix: run git diff alone first, as staged=$(git diff --cached --name-only --diff-filter=ACM) || { echo "Error: cannot list staged changes." >&2; exit 2; }, then test grep -qx Containerfile <<<"${staged}".
[Minor] contrib/dev-tools/checks/lint-containerfile.sh:43 and :47 read the blob as git show :./Containerfile, which git resolves against the current directory, while line 25 matches the root-relative name, and 2>/dev/null discards git's error. When the script runs from a subdirectory (the header at lines 6-7 offers manual invocation), the staged check matches but git show exits 128. hadolint then lints an empty input, and the script exits 128 with no message. A fix that reads only ${PIPESTATUS[1]} would turn this into a silent pass. Line 48 also mounts the working-tree .hadolint.yaml, so for an unstaged edit to the config, the script does not check exactly what will be committed, as lines 37-39 claim. Smallest fix: use git -C "${PROJECT_ROOT}" show :Containerfile without 2>/dev/null. Then either mount the staged config (git -C "${PROJECT_ROOT}" show :.hadolint.yaml into a temporary file) or narrow the comment.
[Minor] The DL4006 rationale at .hadolint.yaml:32-52 rests on two statements that the Containerfile contradicts. First, lines 34-37 say SHELL ["/bin/bash", "-o", "pipefail", "-c"] would require installing bash in every build stage. Yet every pipeline in the file already runs where bash exists: Containerfile:27 and Containerfile:46 pipe into bash itself, and the ldd | grep | awk pipelines at Containerfile:212 and Containerfile:234 run in stages built on tester, the same rust:slim-trixie image. Second, lines 43-45 say curl's -sSf flags make it return non-zero on download failures. But without pipefail the instruction's status is bash's and curl's status is discarded. A transfer cut off mid-script therefore hands bash a truncated installer, and the instruction succeeds if that fragment exits 0, which is the case DL4006 reports. What actually protects the build is that cargo binstall (Containerfile:28 and Containerfile:47) fails when no binary was installed. Smallest fix: add SHELL ["/bin/bash", "-o", "pipefail", "-c"] to the stages that run these pipelines and drop DL4006 from the global list, or at least correct the rationale.
[Nit] The DL3008 rationale at .hadolint.yaml:14-16 calls chef, tester and gcc build-time only, not production runtime images, but their output ships. gcc compiles the su-exec binary that the runtime image carries (Containerfile:244). The release image copies to /usr the /app tree assembled on top of tester (Containerfile:287), including the libz.so.1 taken from that base (Containerfile:234). The entry is also global, so it covers an apt-get install in any stage added later. Smallest fix: state the actual trade-off (reproducibility against the cost of maintaining pins) and name the shipped artifacts that these stages produce.
[Nit] The SC2046 rationale at .hadolint.yaml:62-68 argues that inline ignores behave inconsistently across hadolint versions. Both callers, however, pin one image digest (.github/workflows/container.yaml:89, contrib/dev-tools/checks/lint-containerfile.sh:20). The global entry also turns SC2046 off for every future RUN line, not only for the two cp -l $(realpath $(ldd ...)) lines at Containerfile:212 and Containerfile:234. Smallest fix: quote the two substitutions, as cp -l "$(realpath "$(ldd /app/bin/torrust-tracker | grep "libz\.so\.1" | awk '{print $3}')")" /app/lib/libz.so.1, then remove SC2046 from the list. The quoted form behaves the same for one path and still fails when there is none.
[Nit] .hadolint.yaml sets no failure-threshold, and hadolint's default threshold is info. A rule reported at style severity is therefore printed but does not fail the CI run at .github/workflows/container.yaml:86-91, while the description of #2028 says the workflow fails on any violation not explicitly allowed. Smallest fix: add failure-threshold: style to .hadolint.yaml.
[Nit] #2028 moved format-project-words.sh from contrib/dev-tools/git/ to contrib/dev-tools/checks/, and its description does not list the move. Three references still give the old path: .claude/skills/commit-changes/SKILL.md:176, .claude/skills/run-linters/SKILL.md:151 and .claude/skills/run-linters/references/linters.md:60, so following them fails with "No such file or directory". The references in .claude/skills/run-pre-commit-checks/SKILL.md were corrected later. Smallest fix: update the three paths.
Checked and found sound:
- The merge 7da1e10 applies exactly the change at 3d98c36.
- The CI invocation returns hadolint's own status and uses the same digest-pinned image as the script. It interpolates only
github.workspace, and the workflow'spaths-ignorenever skips a change toContainerfileor.hadolint.yaml. - The hook runs the script from the repository root and stops on its status.
- The no-config branch at
contrib/dev-tools/checks/lint-containerfile.sh:41-45propagates hadolint's status. - The DL3059 entry matches the file's one-instruction-per-cache-layer layout.
- The
lddrationale's conclusion holds: an empty match makescpfail the build.
Description
Closes #1460
Adds a hadolint Dockerfile linting step to the
container.yamlGitHub Actions workflow, ensuring theContainerfilemeets Docker best practices.Changes
.hadolint.yaml(new): Global hadolint configuration with documented rationale for 4 systematically ignored rules (DL3008, DL3059, DL4006, SC2046).github/workflows/container.yaml: Added hadolint step before setup-buildx, mounting the config fileContainerfile: Added semantic-links comment referencing.hadolint.yamlfor discoverabilitycontrib/dev-tools/git/hooks/pre-commit.sh: Added hadolint step that runs only if Containerfile changeddocs/issues/drafts/1460-add-hadolint-to-container-workflow.md: Updated spec to reflect the global config approachIgnore Policy
.hadolint.yamlwith documented rationale# hadolint ignore=comments with rationaleVerification
linter allpassescargo test --doc --workspacepasses