Skip to content

feat: add hadolint linting step to container workflow#2028

Merged
josecelano merged 11 commits into
torrust:developfrom
josecelano:1460-add-hadolint-to-container-workflow
Jul 24, 2026
Merged

feat: add hadolint linting step to container workflow#2028
josecelano merged 11 commits into
torrust:developfrom
josecelano:1460-add-hadolint-to-container-workflow

Conversation

@josecelano

Copy link
Copy Markdown
Member

Description

Closes #1460

Adds a hadolint Dockerfile linting step to the container.yaml GitHub Actions workflow, ensuring the Containerfile meets 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 file
  • Containerfile: Added semantic-links comment referencing .hadolint.yaml for discoverability
  • contrib/dev-tools/git/hooks/pre-commit.sh: Added hadolint step that runs only if Containerfile changed
  • docs/issues/drafts/1460-add-hadolint-to-container-workflow.md: Updated spec to reflect the global config approach

Ignore Policy

  • Systematic warnings (rules that apply across the entire Containerfile) are suppressed globally via .hadolint.yaml with documented rationale
  • One-off suppressions must use inline # hadolint ignore= comments with rationale
  • The workflow fails on any violation not explicitly allowed

Verification

  • linter all passes
  • cargo test --doc --workspace passes
  • hadolint produces clean output with the global config

Copilot AI review requested due to automatic review settings July 23, 2026 18:00
@josecelano josecelano self-assigned this Jul 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.yaml to centrally configure ignored hadolint rules (with rationale).
  • Added a hadolint lint step to .github/workflows/container.yaml and to contrib/dev-tools/git/hooks/pre-commit.sh (only when Containerfile is 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.

Comment thread docs/skills/semantic-skill-link-convention.md Outdated
Comment thread docs/issues/drafts/1460-add-hadolint-to-container-workflow.md Outdated
Comment thread .github/workflows/container.yaml
Comment thread contrib/dev-tools/git/hooks/pre-commit.sh Outdated
Comment thread .hadolint.yaml Outdated
Comment thread .hadolint.yaml
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.61%. Comparing base (03331a8) to head (3d98c36).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano
josecelano marked this pull request as ready for review July 23, 2026 18:29
@josecelano
josecelano requested a review from a team as a code owner July 23, 2026 18:29
Copilot AI review requested due to automatic review settings July 24, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 | bash URL is “pinned” and that a curl --fail guard 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 ignoring pipefail for curl | bash pipelines.
  # - `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`

Comment thread contrib/dev-tools/git/hooks/pre-commit.sh Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 15:47
…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Comment thread .hadolint.yaml Outdated
Comment thread .hadolint.yaml Outdated
Comment thread contrib/dev-tools/git/hooks/pre-commit.sh
@josecelano
josecelano force-pushed the 1460-add-hadolint-to-container-workflow branch from 32f1883 to da1b4f3 Compare July 24, 2026 15:55
Copilot AI review requested due to automatic review settings July 24, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 --cached can run deterministically.

Comment thread contrib/dev-tools/checks/lint-containerfile.sh Outdated
…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.
Copilot AI review requested due to automatic review settings July 24, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_ROOT is computed with only three .. segments, which resolves to the contrib/ directory (not the repository root). That makes subsequent paths like ${PROJECT_ROOT}/contrib/dev-tools/... incorrect (they become contrib/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 path contrib/dev-tools/git/format-project-words.sh no 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"

Comment thread contrib/dev-tools/checks/lint-containerfile.sh Outdated
Comment thread .hadolint.yaml Outdated
Comment thread docs/issues/drafts/1460-add-hadolint-to-container-workflow.md Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_ROOT is computed as three directories up from contrib/dev-tools/checks/tests, which resolves to <repo>/contrib rather 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 no lint-containerfile.sh, so the manual integration test it_should_continue_pre_commit_checks_when_dictionary_is_already_formatted will fail when it reaches that step.

Comment thread contrib/dev-tools/checks/lint-containerfile.sh
@josecelano

Copy link
Copy Markdown
Member Author

ACK 3d98c36

@josecelano
josecelano merged commit 7da1e10 into torrust:develop Jul 24, 2026
21 checks passed
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.

Docker Security Overhaul: Add a linter step to the container.yaml workflow

2 participants