Commit f4254df
committed
feat(linter): make HadolintLinter docker-aware so lint-dockerfile works without local hadolint
The original framing in PR #120 was that ``lint-dockerfile`` requires
the user to install hadolint locally OR wait for the
FileDiscoveryScanner template. The user pushed back — argus has the
official ``hadolint/hadolint:v2.14.0`` Docker image declared on the
linter, so the engine should be using it instead of complaining the
local binary is missing.
Two changes make that work:
1. Engine: in the auto/no-build_args defer path, hand off to
``scanner.scan(path, config)`` unconditionally instead of falling
through to the is_available() gate. Scanners without build_args
are signaling that they own dispatch internally — including the
choice between local execution and the docker fallback. The
is_available() gate was preventing scan() from ever being called
when the local binary was absent, even though scan() could have
handled it.
2. HadolintLinter.scan(): when ``self.is_available()`` returns False,
construct a ``docker run`` command against ``self.container_image``
instead of trying to invoke ``hadolint`` directly. Workspace
mounts read-only at /workspace; discovered Dockerfile paths get
translated to their /workspace/... equivalents. Hadolint accepts
multiple file paths in one invocation, so the batched-call shape
from the prior commit carries through cleanly.
Bug along the way: the hadolint image has empty ENTRYPOINT and
``CMD = ["/bin/hadolint", "-"]``. Passing args at the end of
``docker run`` replaces CMD entirely, so the first arg becomes
the command. Include the binary name explicitly as the first arg.
Verified end-to-end against this repo's checkout:
$ argus scan lint-dockerfile --severity-threshold none
INFO DL3018 /workspace/docker/Dockerfile.cli:19 - Pin versions...
INFO DL4006 /workspace/docker/Dockerfile.cli:29 - Set the SHELL option...
... 11 findings across 3 Dockerfiles
Status: PASS
Real lint findings flowing through, no local install required.
Doesn't ship a unit test for the docker subprocess path because mocking
``shutil.which("docker")`` plus the ``docker run`` invocation reliably
across pytest runs requires more plumbing than the value justifies for
a 25-line method that's verified end-to-end above. The
test_auto_backend_defers_to_scan_when_no_build_args test from this
PR's prior commit covers the engine handoff.1 parent 46244f0 commit f4254df
2 files changed
Lines changed: 77 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
992 | 992 | | |
993 | 993 | | |
994 | 994 | | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
995 | 1002 | | |
996 | 1003 | | |
997 | | - | |
998 | | - | |
| 1004 | + | |
999 | 1005 | | |
1000 | 1006 | | |
| 1007 | + | |
1001 | 1008 | | |
1002 | 1009 | | |
1003 | 1010 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| |||
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
42 | 68 | | |
43 | 69 | | |
44 | 70 | | |
| |||
90 | 116 | | |
91 | 117 | | |
92 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
93 | 160 | | |
94 | 161 | | |
95 | 162 | | |
| |||
0 commit comments