Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Parsing Dockerfiles (
Language.Docker.Syntax
andLanguage.Docker.Parser
) - Re-exports from
megaparsec
- Pretty-printing Dockerfiles (
Language.Docker.PrettyPrint
) - Writting Dockerfiles (
Language.Docker.EDSL
) - QuasiQuoter (
Language.Docker.EDSL.Quasi
) - Types (
Language.Docker.Syntax
) - Instruction and InstructionPos helpers
- type Dockerfile = [InstructionPos Text]
- parseText :: Text -> Either Error Dockerfile
- parseFile :: FilePath -> IO (Either Error Dockerfile)
- parseErrorPretty :: (Ord t, ShowToken t, ShowErrorComponent e) => ParseError t e -> String
- prettyPrint :: Dockerfile -> Text
- prettyPrintInstructionPos :: Pretty (Arguments args) => InstructionPos args -> Doc ann
- toDockerfileText :: EDockerfileM a -> Text
- toDockerfile :: EDockerfileM a -> Dockerfile
- putDockerfileStr :: EDockerfileM a -> IO ()
- writeDockerFile :: Text -> Dockerfile -> IO ()
- toDockerfileTextIO :: MonadIO m => EDockerfileTM m t -> m Text
- toDockerfileIO :: MonadIO m => EDockerfileTM m t -> m Dockerfile
- runDockerfileIO :: MonadIO m => EDockerfileTM m t -> m (t, Dockerfile)
- runDockerfileTextIO :: MonadIO m => EDockerfileTM m t -> m (t, Text)
- liftIO :: MonadIO m => forall a. IO a -> m a
- from :: forall m. MonadFree EInstruction m => EBaseImage -> m ()
- tagged :: Image -> Tag -> EBaseImage
- untagged :: Text -> EBaseImage
- digested :: Image -> Text -> EBaseImage
- aliased :: EBaseImage -> Text -> EBaseImage
- add :: MonadFree EInstruction m => NonEmpty SourcePath -> TargetPath -> m ()
- user :: forall m. MonadFree EInstruction m => Text -> m ()
- label :: forall m. MonadFree EInstruction m => Pairs -> m ()
- stopSignal :: forall m. MonadFree EInstruction m => Text -> m ()
- copy :: MonadFree EInstruction m => CopyArgs -> m ()
- copyFromStage :: MonadFree EInstruction m => CopySource -> NonEmpty SourcePath -> TargetPath -> m ()
- to :: NonEmpty SourcePath -> TargetPath -> CopyArgs
- fromStage :: CopyArgs -> CopySource -> CopyArgs
- ownedBy :: CopyArgs -> Chown -> CopyArgs
- toSources :: NonEmpty Text -> NonEmpty SourcePath
- toTarget :: Text -> TargetPath
- run :: MonadFree EInstruction m => Arguments Text -> m ()
- runArgs :: forall m. MonadFree EInstruction m => Arguments Text -> m ()
- cmd :: MonadFree EInstruction m => Arguments Text -> m ()
- cmdArgs :: forall m. MonadFree EInstruction m => Arguments Text -> m ()
- healthcheck :: forall m. MonadFree EInstruction m => Check Text -> m ()
- check :: Arguments args -> Check args
- interval :: Check args -> Integer -> Check args
- timeout :: Check args -> Integer -> Check args
- startPeriod :: Check args -> Integer -> Check args
- retries :: Check args -> Integer -> Check args
- workdir :: forall m. MonadFree EInstruction m => Directory -> m ()
- expose :: forall m. MonadFree EInstruction m => Ports -> m ()
- ports :: [Port] -> Ports
- tcpPort :: Int -> Port
- udpPort :: Int -> Port
- variablePort :: Text -> Port
- portRange :: Int -> Int -> Port
- udpPortRange :: Int -> Int -> Port
- volume :: forall m. MonadFree EInstruction m => Text -> m ()
- entrypoint :: MonadFree EInstruction m => Arguments Text -> m ()
- entrypointArgs :: forall m. MonadFree EInstruction m => Arguments Text -> m ()
- maintainer :: forall m. MonadFree EInstruction m => Text -> m ()
- env :: forall m. MonadFree EInstruction m => Pairs -> m ()
- arg :: forall m. MonadFree EInstruction m => Text -> Maybe Text -> m ()
- comment :: forall m. MonadFree EInstruction m => Text -> m ()
- onBuild :: MonadFree EInstruction m => EDockerfileM a -> m ()
- onBuildRaw :: forall m. MonadFree EInstruction m => Instruction Text -> m ()
- embed :: forall m. MonadFree EInstruction m => [InstructionPos Text] -> m ()
- edockerfile :: QuasiQuoter
- type EDockerfileM = Free EInstruction
- type EDockerfileTM = FreeT EInstruction
- data EBaseImage
- dockerfile :: QuasiQuoter
- data Instruction args
- = From !BaseImage
- | Add !AddArgs
- | User !Text
- | Label !Pairs
- | Stopsignal !Text
- | Copy !CopyArgs
- | Run !(Arguments args)
- | Cmd !(Arguments args)
- | Shell !(Arguments args)
- | Workdir !Directory
- | Expose !Ports
- | Volume !Text
- | Entrypoint !(Arguments args)
- | Maintainer !Text
- | Env !Pairs
- | Arg !Text !(Maybe Text)
- | Healthcheck !(Check args)
- | Comment !Text
- | OnBuild !(Instruction args)
- data InstructionPos args = InstructionPos {
- instruction :: !(Instruction args)
- sourcename :: !Filename
- lineNumber :: !Linenumber
- data BaseImage
- = UntaggedImage !Image !(Maybe ImageAlias)
- | TaggedImage !Image !Tag !(Maybe ImageAlias)
- | DigestedImage !Image !Text !(Maybe ImageAlias)
- newtype SourcePath = SourcePath {
- unSourcePath :: Text
- newtype TargetPath = TargetPath {
- unTargetPath :: Text
- data Chown
- data CopySource
- = CopySource !Text
- | NoSource
- data CopyArgs = CopyArgs {}
- data AddArgs = AddArgs {}
- data Check args
- data CheckArgs args = CheckArgs {}
- data Image = Image {
- registryName :: !(Maybe Registry)
- imageName :: !Text
- newtype Registry = Registry {
- unRegistry :: Text
- newtype ImageAlias = ImageAlias {
- unImageAlias :: Text
- data Tag
- data Ports
- type Directory = Text
- data Arguments args
- type Pairs = [(Text, Text)]
- type Filename = Text
- type Linenumber = Int
- instructionPos :: Instruction args -> InstructionPos args
Documentation
type Dockerfile = [InstructionPos Text] Source #
Type of the Dockerfile AST
Parsing Dockerfiles (Language.Docker.Syntax
and Language.Docker.Parser
)
Re-exports from megaparsec
:: (Ord t, ShowToken t, ShowErrorComponent e) | |
=> ParseError t e | Parse error to render |
-> String | Result of rendering |
Pretty-print a ParseError
. The rendered String
always ends with a
newline.
Since: 5.0.0
Pretty-printing Dockerfiles (Language.Docker.PrettyPrint
)
prettyPrint :: Dockerfile -> Text Source #
Pretty print a Dockerfile
to a Text
prettyPrintInstructionPos :: Pretty (Arguments args) => InstructionPos args -> Doc ann Source #
Pretty print a InstructionPos
to a Doc
Writting Dockerfiles (Language.Docker.EDSL
)
toDockerfileText :: EDockerfileM a -> Text Source #
runs the Dockerfile EDSL and returns a Lazy
using
PrettyPrint
import Language.Docker main :: IO () main = print $ toDockerfileText $ do from (tagged "fpco/stack-build" "lts-6.9") add ["."] "applanguage-docker" workdir "applanguage-docker" run "stack build --test --only-dependencies" cmd "stack test"
toDockerfile :: EDockerfileM a -> Dockerfile Source #
Runs the Dockerfile EDSL and returns a Dockerfile
you can pretty print
or manipulate
putDockerfileStr :: EDockerfileM a -> IO () Source #
Prints the dockerfile to stdout. Mainly used for debugging purposes
import Language.Docker main :: IO () main = putDockerfileStr $ do from (tagged "fpco/stack-build" "lts-6.9") add ["."] "applanguage-docker" workdir "applanguage-docker" run "stack build --test --only-dependencies" cmd "stack test"
writeDockerFile :: Text -> Dockerfile -> IO () Source #
Writes the dockerfile to the given file path after pretty-printing it
import Language.Docker main :: IO () main = writeDockerFile "build.Dockerfile" $ toDockerfile $ do from (tagged "fpco/stack-build" "lts-6.9") add ["."] "applanguage-docker" workdir "applanguage-docker" run "stack build --test --only-dependencies" cmd "stack test"
toDockerfileTextIO :: MonadIO m => EDockerfileTM m t -> m Text Source #
A version of toDockerfileText
which allows IO actions
toDockerfileIO :: MonadIO m => EDockerfileTM m t -> m Dockerfile Source #
A version of toDockerfile
which allows IO actions
runDockerfileIO :: MonadIO m => EDockerfileTM m t -> m (t, Dockerfile) Source #
Just runs the EDSL's writer monad
runDockerfileTextIO :: MonadIO m => EDockerfileTM m t -> m (t, Text) Source #
Runs the EDSL's writer monad and pretty-prints the result
from :: forall m. MonadFree EInstruction m => EBaseImage -> m () Source #
Constructing base images
tagged :: Image -> Tag -> EBaseImage Source #
Use a specific tag for a docker image. This function is meant to be used as an infix operator.
from $ "fpco/stack-build" tagged
"lts-10.3"
untagged :: Text -> EBaseImage Source #
Use a docker image in a FROM instruction without a tag
The following two examples are equivalent
from $ untagged "fpco/stack-build"
Is equivalent to, when having OverloadedStrings:
from "fpco/stack-build"
aliased :: EBaseImage -> Text -> EBaseImage Source #
Alias a FROM instruction to be used as a build stage. This function is meant to be used as an infix operator.
from $ "fpco/stack-build" aliased
"builder"
Syntax
add :: MonadFree EInstruction m => NonEmpty SourcePath -> TargetPath -> m () Source #
Create an ADD instruction. This is often used as a shorthand version
of copy when no extra options are needed. Currently there is no way to
pass extra options to ADD, so you are encouraged to use copy
instead.
add ["foo.js", "bar.js"] "."
stopSignal :: forall m. MonadFree EInstruction m => Text -> m () Source #
copyFromStage :: MonadFree EInstruction m => CopySource -> NonEmpty SourcePath -> TargetPath -> m () Source #
Create a COPY instruction from a given build stage.
This is a shorthand version of using copy
with combinators.
copyFromStage "builder" ["foo.js", "bar.js"] "."
to :: NonEmpty SourcePath -> TargetPath -> CopyArgs Source #
toSources :: NonEmpty Text -> NonEmpty SourcePath Source #
Converts a NonEmpty list of strings to a NonEmpty list of SourcePath
This is a convenience function when you need to pass a non-static list of
strings that you build somewhere as an argument for copy
or add
someFiles <- glob "*.js"
copy $ (toSources someFiles) to
"."
toTarget :: Text -> TargetPath Source #
Converts a Text into a TargetPath
This is a convenience function when you need to pass a string variable
as an argument for copy
or add
let destination = buildSomePath pwd add ["foo.js"] (toTarget destination)
run :: MonadFree EInstruction m => Arguments Text -> m () Source #
Create a RUN instruction with the given arguments.
run "apt-get install wget"
cmd :: MonadFree EInstruction m => Arguments Text -> m () Source #
Create a CMD instruction with the given arguments.
cmd "my-program --some-flag"
healthcheck :: forall m. MonadFree EInstruction m => Check Text -> m () Source #
variablePort :: Text -> Port Source #
entrypoint :: MonadFree EInstruction m => Arguments Text -> m () Source #
Create an ENTRYPOINT instruction with the given arguments.
entrypoint "usrlocalbinprogram --some-flag"
entrypointArgs :: forall m. MonadFree EInstruction m => Arguments Text -> m () Source #
maintainer :: forall m. MonadFree EInstruction m => Text -> m () Source #
onBuild :: MonadFree EInstruction m => EDockerfileM a -> m () Source #
ONBUILD Dockerfile instruction
Each nested instruction gets emitted as a separate ONBUILD
block
toDockerfile
$ do
from "node"
run "apt-get update"
onBuild $ do
run "echo more-stuff"
run "echo here"
onBuildRaw :: forall m. MonadFree EInstruction m => Instruction Text -> m () Source #
embed :: forall m. MonadFree EInstruction m => [InstructionPos Text] -> m () Source #
edockerfile :: QuasiQuoter Source #
Quasiquoter for embedding dockerfiles on the EDSL
putStr $ toDockerfile
$ do
from "node"
run "apt-get update"
[edockerfile|
RUN apt-get update
CMD node something.js
|]
Support types for the EDSL
type EDockerfileM = Free EInstruction Source #
The type of Identity
based EDSL blocks
type EDockerfileTM = FreeT EInstruction Source #
The type of free monad EDSL blocks
data EBaseImage Source #
QuasiQuoter (Language.Docker.EDSL.Quasi
)
Types (Language.Docker.Syntax
)
data Instruction args Source #
All commands available in Dockerfiles
From !BaseImage | |
Add !AddArgs | |
User !Text | |
Label !Pairs | |
Stopsignal !Text | |
Copy !CopyArgs | |
Run !(Arguments args) | |
Cmd !(Arguments args) | |
Shell !(Arguments args) | |
Workdir !Directory | |
Expose !Ports | |
Volume !Text | |
Entrypoint !(Arguments args) | |
Maintainer !Text | |
Env !Pairs | |
Arg !Text !(Maybe Text) | |
Healthcheck !(Check args) | |
Comment !Text | |
OnBuild !(Instruction args) |
Functor Instruction Source # | |
Eq args => Eq (Instruction args) Source # | |
Ord args => Ord (Instruction args) Source # | |
Show args => Show (Instruction args) Source # | |
data InstructionPos args Source #
Instruction
with additional location information required for creating
good check messages
InstructionPos | |
|
Functor InstructionPos Source # | |
Eq args => Eq (InstructionPos args) Source # | |
Ord args => Ord (InstructionPos args) Source # | |
Show args => Show (InstructionPos args) Source # | |
UntaggedImage !Image !(Maybe ImageAlias) | |
TaggedImage !Image !Tag !(Maybe ImageAlias) | |
DigestedImage !Image !Text !(Maybe ImageAlias) |
newtype SourcePath Source #
newtype TargetPath Source #
data CopySource Source #
CopyArgs | |
|
AddArgs | |
|
newtype ImageAlias Source #
type Linenumber = Int Source #
Instruction and InstructionPos helpers
instructionPos :: Instruction args -> InstructionPos args Source #