language-docker 12.1.0 → 13.0.0
raw patch · 8 files changed
+77/−37 lines, 8 files
Files
- language-docker.cabal +5/−12
- src/Language/Docker.hs +2/−0
- src/Language/Docker/Parser/Copy.hs +22/−9
- src/Language/Docker/PrettyPrint.hs +8/−1
- src/Language/Docker/Syntax.hs +14/−2
- src/Language/Docker/Syntax/PortRange.hs +1/−1
- test/Language/Docker/ParseAddSpec.hs +16/−8
- test/Language/Docker/PrettyPrintSpec.hs +9/−4
language-docker.cabal view
@@ -1,13 +1,7 @@-cabal-version: 1.12---- This file has been generated from package.yaml by hpack version 0.35.0.------ see: https://github.com/sol/hpack------ hash: 37c989b46891ef750c66b64a1dcbdfc30c1ee22a0ed4821aeb27c7c63c02d2a9+cabal-version: 2.0 name: language-docker-version: 12.1.0+version: 13.0.0 synopsis: Dockerfile parser, pretty-printer and embedded DSL description: All functions for parsing and pretty-printing Dockerfiles are exported through @Language.Docker@. For more fine-grained operations look for specific modules that implement a certain functionality. See the <https://github.com/hadolint/language-docker GitHub project> for the source-code and examples.@@ -64,7 +58,6 @@ Language.Docker.Syntax.Port Language.Docker.Syntax.PortRange Language.Docker.Syntax.Protocol- Paths_language_docker hs-source-dirs: src default-extensions:@@ -83,7 +76,7 @@ , split >=0.2 , text , time- default-language: Haskell2010+ default-language: GHC2021 test-suite hspec type: exitcode-stdio-1.0@@ -100,7 +93,6 @@ Language.Docker.ParseRunSpec Language.Docker.PrettyPrintSpec TestHelper- Paths_language_docker hs-source-dirs: test default-extensions:@@ -125,4 +117,5 @@ , split >=0.2 , text , time- default-language: Haskell2010+ default-language: GHC2021+ build-tool-depends: hspec-discover:hspec-discover == 2.*
src/Language/Docker.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DuplicateRecordFields #-}+ module Language.Docker ( Language.Docker.Syntax.Dockerfile,
src/Language/Docker/Parser/Copy.hs view
@@ -10,7 +10,8 @@ import Language.Docker.Syntax data Flag- = FlagChown Chown+ = FlagChecksum Checksum+ | FlagChown Chown | FlagChmod Chmod | FlagLink Link | FlagSource CopySource@@ -56,18 +57,23 @@ parseAdd = do reserved "ADD" flags <- addFlag `sepEndBy` requiredWhitespace+ let checksumFlags = [c | FlagChecksum c <- flags] let chownFlags = [c | FlagChown c <- flags] let chmodFlags = [c | FlagChmod c <- flags] let linkFlags = [l | FlagLink l <- flags] let invalidFlags = [i | FlagInvalid i <- flags] notFollowedBy (string "--") <?>- "only the --chown flag, the --chmod flag or the src and dest paths"- case (invalidFlags, chownFlags, linkFlags, chmodFlags) of- ((k, v) : _, _, _, _) -> unexpectedFlag k v- (_, _ : _ : _, _, _) -> customError $ DuplicateFlagError "--chown"- (_, _, _ : _ : _, _) -> customError $ DuplicateFlagError "--chmod"- (_, _, _, _ : _ : _) -> customError $ DuplicateFlagError "--link"+ "only the --checksum, --chown, --chmod, --link flags or the src and dest paths"+ case (invalidFlags, checksumFlags, chownFlags, linkFlags, chmodFlags) of+ ((k, v) : _, _, _, _, _) -> unexpectedFlag k v+ (_, _ : _ : _, _, _, _) -> customError $ DuplicateFlagError "--checksum"+ (_, _, _ : _ : _, _, _) -> customError $ DuplicateFlagError "--chown"+ (_, _, _, _ : _ : _, _) -> customError $ DuplicateFlagError "--chmod"+ (_, _, _, _, _ : _ : _) -> customError $ DuplicateFlagError "--link" _ -> do+ let chk = case checksumFlags of+ [] -> NoChecksum+ c : _ -> c let cho = case chownFlags of [] -> NoChown c : _ -> c@@ -78,7 +84,7 @@ case linkFlags of [] -> NoLink l : _ -> l- fileList "ADD" (\src dest -> Add (AddArgs src dest) (AddFlags cho chm lnk))+ fileList "ADD" (\src dest -> Add (AddArgs src dest) (AddFlags chk cho chm lnk)) heredocList :: (?esc :: Char) => (NonEmpty SourcePath -> TargetPath -> Instruction Text) ->@@ -114,10 +120,17 @@ copyFlag = (FlagSource <$> try copySource <?> "only one --from") <|> addFlag addFlag :: (?esc :: Char) => Parser Flag-addFlag = (FlagChown <$> try chown <?> "--chown")+addFlag = (FlagChecksum <$> try checksum <?> "--checksum")+ <|> (FlagChown <$> try chown <?> "--chown") <|> (FlagChmod <$> try chmod <?> "--chmod") <|> (FlagLink <$> try link <?> "--link") <|> (FlagInvalid <$> try anyFlag <?> "other flag")++checksum :: (?esc :: Char) => Parser Checksum+checksum = do+ void $ string "--checksum="+ chk <- someUnless "the remote file checksum" (== ' ')+ return $ Checksum chk chown :: (?esc :: Char) => Parser Chown chown = do
src/Language/Docker/PrettyPrint.hs view
@@ -136,6 +136,12 @@ _ -> "" in hsep $ [pretty s | SourcePath s <- toList sources] ++ [pretty dest <> ending] +prettyPrintChecksum :: Checksum -> Doc ann+prettyPrintChecksum checksum =+ case checksum of+ Checksum c -> "--checksum=" <> pretty c+ NoChecksum -> mempty+ prettyPrintChown :: Chown -> Doc ann prettyPrintChown chown = case chown of@@ -315,8 +321,9 @@ prettyPrintBaseImage b Add AddArgs {sourcePaths, targetPath}- AddFlags {chownFlag, chmodFlag, linkFlag} -> do+ AddFlags {checksumFlag, chownFlag, chmodFlag, linkFlag} -> do "ADD"+ prettyPrintChecksum checksumFlag prettyPrintChown chownFlag prettyPrintChmod chmodFlag prettyPrintLink linkFlag
src/Language/Docker/Syntax.hs view
@@ -119,6 +119,17 @@ } deriving (Show, Eq, Ord, IsString) +data Checksum+ = Checksum !Text+ | NoChecksum+ deriving (Show, Eq, Ord)++instance IsString Checksum where+ fromString ch =+ case ch of+ "" -> NoChecksum+ _ -> Checksum (Text.pack ch)+ data Chown = Chown !Text | NoChown@@ -197,14 +208,15 @@ data AddFlags = AddFlags- { chownFlag :: !Chown,+ { checksumFlag :: !Checksum,+ chownFlag :: !Chown, chmodFlag :: !Chmod, linkFlag :: !Link } deriving (Show, Eq, Ord) instance Default AddFlags where- def = AddFlags NoChown NoChmod NoLink+ def = AddFlags NoChecksum NoChown NoChmod NoLink data Check args = Check !(CheckArgs args)
src/Language/Docker/Syntax/PortRange.hs view
@@ -15,6 +15,6 @@ instance Pretty PortRange where+ pretty (PortRange (Port start UDP) (Port end UDP)) = pretty start <> "-" <> pretty end <> "/udp" pretty (PortRange (Port start UDP) end) = pretty start <> "-" <> pretty end <> "/udp"- pretty (PortRange (PortStr start) (Port end UDP)) = pretty start <> "-" <> pretty end <> "/udp" pretty (PortRange start end) = pretty start <> "-" <> pretty end
test/Language/Docker/ParseAddSpec.hs view
@@ -41,13 +41,21 @@ ) def ]+ it "with checksum flag" $+ let file = Text.unlines ["ADD --checksum=sha256:24454f830cdd http://www.example.com/foo bar"]+ in assertAst+ file+ [ Add+ ( AddArgs (fmap SourcePath ["http://www.example.com/foo"]) (TargetPath "bar") )+ ( AddFlags (Checksum "sha256:24454f830cdd") NoChown NoChmod NoLink )+ ] it "with chown flag" $ let file = Text.unlines ["ADD --chown=root:root foo bar"] in assertAst file [ Add ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )- ( AddFlags (Chown "root:root") NoChmod NoLink )+ ( AddFlags NoChecksum (Chown "root:root") NoChmod NoLink ) ] it "with chmod flag" $ let file = Text.unlines ["ADD --chmod=640 foo bar"]@@ -55,7 +63,7 @@ file [ Add ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )- ( AddFlags NoChown (Chmod "640") NoLink )+ ( AddFlags NoChecksum NoChown (Chmod "640") NoLink ) ] it "with link flag" $ let file = Text.unlines ["ADD --link foo bar"]@@ -63,7 +71,7 @@ file [ Add ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )- ( AddFlags NoChown NoChmod Link )+ ( AddFlags NoChecksum NoChown NoChmod Link ) ] it "with chown and chmod flag" $ let file = Text.unlines ["ADD --chown=root:root --chmod=640 foo bar"]@@ -71,7 +79,7 @@ file [ Add ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )- ( AddFlags (Chown "root:root") (Chmod "640") NoLink )+ ( AddFlags NoChecksum (Chown "root:root") (Chmod "640") NoLink ) ] it "with chown and chmod flag other order" $ let file = Text.unlines ["ADD --chmod=640 --chown=root:root foo bar"]@@ -79,16 +87,16 @@ file [ Add ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )- ( AddFlags (Chown "root:root") (Chmod "640") NoLink )+ ( AddFlags NoChecksum (Chown "root:root") (Chmod "640") NoLink ) ] it "with all flags" $ let file =- Text.unlines ["ADD --chmod=640 --chown=root:root --link foo bar"]+ Text.unlines ["ADD --chmod=640 --chown=root:root --checksum=sha256:24454f830cdd --link foo bar"] in assertAst file [ Add ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )- ( AddFlags (Chown "root:root") (Chmod "640") Link )+ ( AddFlags (Checksum "sha256:24454f830cdd") (Chown "root:root") (Chmod "640") Link ) ] it "list of quoted files and chown" $ let file =@@ -101,5 +109,5 @@ (fmap SourcePath ["foo", "bar", "baz"]) (TargetPath "/app") )- ( AddFlags (Chown "user:group") NoChmod NoLink )+ ( AddFlags NoChecksum (Chown "user:group") NoChmod NoLink ) ]
test/Language/Docker/PrettyPrintSpec.hs view
@@ -21,25 +21,30 @@ ( AddArgs [SourcePath "foo"] (TargetPath "bar") ) ( def :: AddFlags ) in assertPretty "ADD foo bar" add+ it "with just checksum" $ do+ let add = Add+ ( AddArgs [SourcePath "http://www.example.com/foo"] (TargetPath "bar") )+ ( AddFlags ( Checksum "sha256:24454f830cdd" ) NoChown NoChmod NoLink )+ in assertPretty "ADD --checksum=sha256:24454f830cdd http://www.example.com/foo bar" add it "with just chown" $ do let add = Add ( AddArgs [SourcePath "foo"] (TargetPath "bar") )- ( AddFlags ( Chown "root:root" ) NoChmod NoLink )+ ( AddFlags NoChecksum ( Chown "root:root" ) NoChmod NoLink ) in assertPretty "ADD --chown=root:root foo bar" add it "with just chmod" $ do let add = Add ( AddArgs [SourcePath "foo"] (TargetPath "bar") )- ( AddFlags NoChown ( Chmod "751" ) NoLink )+ ( AddFlags NoChecksum NoChown ( Chmod "751" ) NoLink ) in assertPretty "ADD --chmod=751 foo bar" add it "with just link" $ do let add = Add ( AddArgs [SourcePath "foo"] (TargetPath "bar") )- ( AddFlags NoChown NoChmod Link )+ ( AddFlags NoChecksum NoChown NoChmod Link ) in assertPretty "ADD --link foo bar" add it "with chown, chmod and link" $ do let add = Add ( AddArgs [SourcePath "foo"] (TargetPath "bar") )- ( AddFlags ( Chown "root:root" ) ( Chmod "751" ) Link )+ ( AddFlags NoChecksum ( Chown "root:root" ) ( Chmod "751" ) Link ) in assertPretty "ADD --chown=root:root --chmod=751 --link foo bar" add describe "pretty print COPY" $ do