hadolint 1.7.3 → 1.7.4
raw patch · 4 files changed
+82/−11 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +12/−0
- hadolint.cabal +2/−2
- src/Hadolint/Rules.hs +7/−6
- test/Spec.hs +61/−3
README.md view
@@ -46,6 +46,18 @@ brew install hadolint ``` +As shwon before, hadolint ia available as a docker container:++```bash+docker pull hadolint/hadolint+```++If you need a docker container with shell access, use the debian variant of the docker image:++```bash+docker pull hadolint/hadolint:latest-debian+```+ You can also build `hadolint` locally. You need [Haskell][] and the [stack][] build tool to build the binary.
hadolint.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: d37a0fd84b709a8dc3e6fc3f832dfab082288fd471f7b3c344549cf3ad680752+-- hash: 6d3df6bb7a68f68f6c3b7f0396c1a4f2ef36d21dd6eebe46dff3c194f1a932c4 name: hadolint-version: 1.7.3+version: 1.7.4 synopsis: Dockerfile Linter JavaScript API description: A smarter Dockerfile linter that helps you build best practice Docker images. category: Development
src/Hadolint/Rules.hs view
@@ -259,27 +259,28 @@ usingProgram prog args = not $ null [cmd | cmd <- Bash.findCommandNames args, cmd == prog] multipleCmds :: Rule-multipleCmds = instructionRuleState code severity message check Nothing+multipleCmds = instructionRuleState code severity message check False where code = "DL4003" severity = WarningC message = "Multiple `CMD` instructions found. If you list more than one `CMD` then only the last \ \`CMD` will take effect"- check Nothing line (Cmd _) = withState (Just line) True -- Remember the first CMD found- check (Just l) _ (Cmd _) = withState (Just l) False -- Fail the rule, CMD is duplicated+ check _ _ From {} = withState False True -- Reset the state each time we find a FROM+ check st _ Cmd {} = withState True (not st) -- Remember we found a CMD, fail if we found a CMD before check st _ _ = withState st True multipleEntrypoints :: Rule-multipleEntrypoints = instructionRuleState code severity message check Nothing+multipleEntrypoints = instructionRuleState code severity message check False where code = "DL4004" severity = ErrorC message = "Multiple `ENTRYPOINT` instructions found. If you list more than one `ENTRYPOINT` then \ \only the last `ENTRYPOINT` will take effect"- check Nothing line (Entrypoint _) = withState (Just line) True -- Remember the first ENTRYPOINT found- check (Just l) _ (Entrypoint _) = withState (Just l) False -- Fail the rule, ENTRYPOINT is duplicated+ check _ _ From {} = withState False True -- Reset the state each time we find a FROM+ check st _ Entrypoint {} = withState True (not st) -- Remember we found an ENTRYPOINT+ -- and fail if we found another one before check st _ _ = withState st True wgetOrCurl :: Rule
test/Spec.hs view
@@ -466,11 +466,69 @@ it "has maintainer first" $ ruleCatches hasNoMaintainer "MAINTAINER Lukas\nFROM DEBIAN" it "has no maintainer" $ ruleCatchesNot hasNoMaintainer "FROM debian" it "using add" $ ruleCatches copyInsteadAdd "ADD file /usr/src/app/"- it "many cmds" $ ruleCatches multipleCmds "CMD /bin/true\nCMD /bin/true"++ it "many cmds" $+ let dockerFile =+ [ "FROM debian"+ , "CMD bash"+ , "RUN foo"+ , "CMD another"+ ]+ in ruleCatches multipleCmds $ Text.unlines dockerFile++ it "single cmds, different stages" $+ let dockerFile =+ [ "FROM debian as distro1"+ , "CMD bash"+ , "RUN foo"+ , "FROM debian as distro2"+ , "CMD another"+ ]+ in ruleCatchesNot multipleCmds $ Text.unlines dockerFile++ it "many cmds, different stages" $+ let dockerFile =+ [ "FROM debian as distro1"+ , "CMD bash"+ , "RUN foo"+ , "CMD another"+ , "FROM debian as distro2"+ , "CMD another"+ ]+ in ruleCatches multipleCmds $ Text.unlines dockerFile+ it "single cmd" $ ruleCatchesNot multipleCmds "CMD /bin/true" it "no cmd" $ ruleCatchesNot multipleEntrypoints "FROM busybox"- it "many entries" $- ruleCatches multipleEntrypoints "ENTRYPOINT /bin/true\nENTRYPOINT /bin/true"++ it "many entrypoints" $+ let dockerFile =+ [ "FROM debian"+ , "ENTRYPOINT bash"+ , "RUN foo"+ , "ENTRYPOINT another"+ ]+ in ruleCatches multipleEntrypoints $ Text.unlines dockerFile++ it "single entrypoint, different stages" $+ let dockerFile =+ [ "FROM debian as distro1"+ , "ENTRYPOINT bash"+ , "RUN foo"+ , "FROM debian as distro2"+ , "ENTRYPOINT another"+ ]+ in ruleCatchesNot multipleEntrypoints $ Text.unlines dockerFile++ it "many entrypoints, different stages" $+ let dockerFile =+ [ "FROM debian as distro1"+ , "ENTRYPOINT bash"+ , "RUN foo"+ , "ENTRYPOINT another"+ , "FROM debian as distro2"+ , "ENTRYPOINT another"+ ]+ in ruleCatches multipleEntrypoints $ Text.unlines dockerFile it "single entry" $ ruleCatchesNot multipleEntrypoints "ENTRYPOINT /bin/true" it "no entry" $ ruleCatchesNot multipleEntrypoints "FROM busybox" it "workdir variable" $ ruleCatchesNot absoluteWorkdir "WORKDIR ${work}"