buffet 0.4.0 → 0.5.0
raw patch · 8 files changed
+47/−61 lines, 8 filesdep +prettyprinterPVP ok
version bump matches the API change (PVP)
Dependencies added: prettyprinter
API changes (from Hackage documentation)
+ Buffet.Toolbox.DockerTools: printArguments :: Arguments Text -> Text
Files
- LICENSE +1/−1
- README.md +8/−6
- buffet.cabal +5/−4
- src/Buffet.hs +1/−1
- src/Buffet/Assemble/ConditionInstructions.hs +13/−27
- src/Buffet/Assemble/JoinConsecutiveRunInstructions.hs +5/−5
- src/Buffet/Parse/ParseHealthCheck.hs +2/−12
- src/Buffet/Toolbox/DockerTools.hs +12/−5
LICENSE view
@@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Benjamin Fischer+Copyright (c) 2019–2020 Benjamin Fischer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
README.md view
@@ -12,15 +12,16 @@ A Dockerfile for Prettier ```dockerfile-FROM alpine:3.11.5-RUN apk add --no-cache yarn~=1.19 && yarn global add prettier@2.0.2+FROM alpine:3.12.0+RUN apk add --no-cache yarn~=1.22 \+ && yarn global add prettier@2.1.2 WORKDIR /workdir ``` plus a Dockerfile for HTML Tidy ```dockerfile-FROM alpine:3.11.5+FROM alpine:3.12.0 RUN apk add --no-cache tidyhtml~=5.6 WORKDIR /workdir ```@@ -28,9 +29,10 @@ are automatically assembled in a single Dockerfile ```dockerfile-FROM alpine:3.11.5-RUN apk add --no-cache yarn~=1.19 && yarn global add prettier@2.0.2 \- && apk add --no-cache tidyhtml~=5.6+FROM alpine:3.12.0+RUN apk add --no-cache yarn~=1.22 \+ && yarn global add prettier@2.1.2 \+ && apk add --no-cache tidyhtml~=5.6 WORKDIR /workdir ```
buffet.cabal view
@@ -1,13 +1,13 @@ cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: 5aa136a496cd4e9ffdb1c3708111acaa4831e2aa5f2eb24ab55e68193bbad52e+-- hash: 1a2db84508718f76303fe3c239a753d2c8b79cf4a769261f6b911eb93c3dfac8 name: buffet-version: 0.4.0+version: 0.5.0 synopsis: Assembles many Dockerfiles in one. description: See https://github.com/evolutics/buffet category: Development@@ -15,7 +15,7 @@ bug-reports: https://github.com/evolutics/buffet/issues author: Benjamin Fischer maintainer: benjamin.fischer@evolutics.info-copyright: 2019 Benjamin Fischer+copyright: 2019–2020 Benjamin Fischer license: MIT license-file: LICENSE build-type: Simple@@ -93,6 +93,7 @@ , mustache , optparse-applicative , parsec+ , prettyprinter , random , split , text
src/Buffet.hs view
@@ -42,7 +42,7 @@ versionOption :: Options.Parser (a -> a) versionOption =- Options.infoOption "Buffet 0.4.0" $+ Options.infoOption "Buffet 0.5.0" $ mconcat [Options.long "version", Options.helpDoc $ Just versionHelp, Options.hidden] where
src/Buffet/Assemble/ConditionInstructions.hs view
@@ -5,7 +5,6 @@ import qualified Buffet.Assemble.InsertOptionArgInstructionUnlessPresent as InsertOptionArgInstructionUnlessPresent import qualified Buffet.Ir.Ir as Ir-import qualified Buffet.Toolbox.TextTools as TextTools import qualified Data.Text as T import qualified Language.Docker as Docker hiding (sourcePaths) import qualified Language.Docker.Syntax as Syntax@@ -31,8 +30,8 @@ where condition (Docker.Copy arguments) = conditionCopyInstruction configuration arguments- condition (Docker.Run (Syntax.ArgumentsText command)) =- configuredConditionRunInstruction configuration command+ condition (Docker.Run (Syntax.RunArgs (Syntax.ArgumentsText command) flags)) =+ conditionRunInstruction configuration command flags condition instruction = instruction conditionCopyInstruction ::@@ -47,29 +46,16 @@ originalSources = Docker.sourcePaths arguments dummy = Docker.SourcePath {Docker.unSourcePath = copyDummySourcePath buffet} -configuredConditionRunInstruction ::- Configuration -> T.Text -> Docker.Instruction T.Text-configuredConditionRunInstruction configuration =- conditionRunInstruction condition- where- condition =- mconcat- [T.pack "[ -n \"${", Ir.option $ option configuration, T.pack "}\" ]"]--conditionRunInstruction :: T.Text -> T.Text -> Docker.Instruction T.Text-conditionRunInstruction condition thenPart =- Docker.Run $ Syntax.ArgumentsText command+conditionRunInstruction ::+ Configuration -> T.Text -> Syntax.RunFlags -> Docker.Instruction T.Text+conditionRunInstruction configuration thenPart =+ Docker.Run . Syntax.RunArgs (Syntax.ArgumentsText command) where command =- TextTools.intercalateNewline $- mconcat [[conditionLine], indentLines thenLines, [indentLine endLine]]- conditionLine = mconcat [T.pack "if ", condition, T.pack "; then \\"]- thenLines = T.lines embeddedThen- embeddedThen = mconcat [indentLine thenPart, T.pack " \\"]- endLine = T.pack "; fi"--indentLines :: [T.Text] -> [T.Text]-indentLines = fmap indentLine--indentLine :: T.Text -> T.Text-indentLine = T.append $ T.pack " "+ mconcat+ [ T.pack "if [ -n \"${"+ , Ir.option $ option configuration+ , T.pack "}\" ]; then "+ , thenPart+ , T.pack "; fi"+ ]
src/Buffet/Assemble/JoinConsecutiveRunInstructions.hs view
@@ -6,13 +6,14 @@ import qualified Data.Text as T import qualified Language.Docker as Docker import qualified Language.Docker.Syntax as Syntax-import Prelude (($), foldr, mconcat)+import Prelude (($), (==), foldr, mconcat) get :: Ir.DockerfilePart -> Ir.DockerfilePart get = foldr process [] where- process (Docker.Run first) (Docker.Run second:rest) =- Docker.Run (joinRuns first second) : rest+ process (Docker.Run (Syntax.RunArgs first flags)) (Docker.Run (Syntax.RunArgs second flags'):rest)+ | flags == flags' =+ Docker.Run (Syntax.RunArgs (joinRuns first second) flags) : rest process first rest = first : rest joinRuns ::@@ -20,8 +21,7 @@ -> Docker.Arguments T.Text -> Docker.Arguments T.Text joinRuns first second =- Syntax.ArgumentsText $- mconcat [command first, T.pack " \\\n && ", command second]+ Syntax.ArgumentsText $ mconcat [command first, T.pack " && ", command second] where command (Syntax.ArgumentsText shell) = shell command (Syntax.ArgumentsList exec) = exec
src/Buffet/Parse/ParseHealthCheck.hs view
@@ -2,32 +2,22 @@ ( get ) where +import qualified Buffet.Toolbox.DockerTools as DockerTools import qualified Data.Maybe as Maybe import qualified Data.Text as T import qualified Language.Docker as Docker-import qualified Language.Docker.Syntax as Syntax import Prelude (Maybe(Just, Nothing), ($), (.), reverse) get :: Docker.Dockerfile -> Maybe T.Text get stage = case lastHealthcheck stage of Just (Docker.Check checkArguments) ->- Just . reviveCommandStyle . argumentsText $- Docker.checkCommand checkArguments+ Just . DockerTools.printArguments $ Docker.checkCommand checkArguments _ -> Nothing -reviveCommandStyle :: T.Text -> T.Text-reviveCommandStyle = reviveLineBreaks- where- reviveLineBreaks = T.replace (T.pack " ") $ T.pack " \\\n "- lastHealthcheck :: Docker.Dockerfile -> Maybe (Docker.Check T.Text) lastHealthcheck = Maybe.listToMaybe . reverse . Maybe.mapMaybe maybeHealthcheck where maybeHealthcheck (Docker.InstructionPos (Docker.Healthcheck check) _ _) = Just check maybeHealthcheck _ = Nothing--argumentsText :: Docker.Arguments T.Text -> T.Text-argumentsText (Syntax.ArgumentsText text) = text-argumentsText (Syntax.ArgumentsList list) = list
src/Buffet/Toolbox/DockerTools.hs view
@@ -1,15 +1,22 @@ module Buffet.Toolbox.DockerTools- ( printInstruction+ ( printArguments+ , printInstruction ) where import qualified Data.Text as T import qualified Data.Text.Lazy as Lazy+import qualified Data.Text.Prettyprint.Doc as Doc+import qualified Data.Text.Prettyprint.Doc.Render.Text as Text import qualified Language.Docker as Docker+import qualified Language.Docker.PrettyPrint as PrettyPrint import qualified Language.Docker.Syntax as Syntax-import Prelude (($), mconcat)+import Prelude (($), (.), mempty) +printArguments :: Docker.Arguments T.Text -> T.Text+printArguments =+ Text.renderStrict . Doc.layoutCompact . PrettyPrint.prettyPrintArguments+ printInstruction :: Docker.Instruction T.Text -> T.Text-printInstruction (Docker.Run (Syntax.ArgumentsText command)) =- T.unlines [mconcat [T.pack "RUN ", command]] printInstruction instruction =- Lazy.toStrict $ Docker.prettyPrint [Docker.instructionPos instruction]+ Lazy.toStrict $+ Docker.prettyPrint [Syntax.InstructionPos instruction mempty 0]