| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Language.Docker
Contents
- Parsing Dockerfiles (
Language.Docker.SyntaxandLanguage.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
Synopsis
- type Dockerfile = [InstructionPos Text]
- parseText :: Text -> Either Error Dockerfile
- parseFile :: FilePath -> IO (Either Error Dockerfile)
- parseStdin :: IO (Either Error Dockerfile)
- parseErrorPretty :: (Stream s, ShowErrorComponent e) => ParseError s e -> String
- errorBundlePretty :: (Stream s, ShowErrorComponent e) => ParseErrorBundle s e -> String
- prettyPrint :: Dockerfile -> Text
- prettyPrintDockerfile :: 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 => IO a -> m a
- from :: forall m. MonadFree EInstruction m => EBaseImage -> m ()
- tagged :: Image -> Tag -> EBaseImage
- untagged :: Text -> EBaseImage
- digested :: EBaseImage -> Digest -> EBaseImage
- aliased :: EBaseImage -> ImageAlias -> 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 = EBaseImage Image (Maybe Tag) (Maybe Digest) (Maybe ImageAlias) (Maybe Platform)
- 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 = BaseImage {}
- 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
- newtype Tag = Tag {}
- newtype Digest = Digest {}
- data Ports
- type Directory = Text
- data Arguments args
- type Pairs = [(Text, Text)]
- type Filename = Text
- type Platform = 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)
parseStdin :: IO (Either Error Dockerfile) Source #
Reads the standard input until the end and parses the contents as a Dockerfile
Re-exports from megaparsec
Arguments
| :: (Stream s, ShowErrorComponent e) | |
| => ParseError s e | Parse error to render |
| -> String | Result of rendering |
Pretty-print a ParseError. The rendered String always ends with a
newline.
Since: megaparsec-5.0.0
Arguments
| :: (Stream s, ShowErrorComponent e) | |
| => ParseErrorBundle s e | Parse error bundle to display |
| -> String | Textual rendition of the bundle |
Pretty-print a ParseErrorBundle. All ParseErrors in the bundle will
be pretty-printed in order together with the corresponding offending
lines by doing a single efficient pass over the input stream. The
rendered String always ends with a newline.
Since: megaparsec-7.0.0
Pretty-printing Dockerfiles (Language.Docker.PrettyPrint)
prettyPrint :: Dockerfile -> Text Source #
Pretty print a Dockerfile to a Text
prettyPrintDockerfile :: Pretty (Arguments args) => [InstructionPos args] -> Doc ann Source #
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"
digested :: EBaseImage -> Digest -> EBaseImage Source #
Adds a digest checksum so a FROM instruction This function is meant to be used as an infix operator.
from $ "fpco/stack-build" digested "sha256:abcdef123"
aliased :: EBaseImage -> ImageAlias -> 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 #
Constructors
| EBaseImage Image (Maybe Tag) (Maybe Digest) (Maybe ImageAlias) (Maybe Platform) |
Instances
| Eq EBaseImage Source # | |
Defined in Language.Docker.EDSL.Types | |
| Ord EBaseImage Source # | |
Defined in Language.Docker.EDSL.Types Methods compare :: EBaseImage -> EBaseImage -> Ordering # (<) :: EBaseImage -> EBaseImage -> Bool # (<=) :: EBaseImage -> EBaseImage -> Bool # (>) :: EBaseImage -> EBaseImage -> Bool # (>=) :: EBaseImage -> EBaseImage -> Bool # max :: EBaseImage -> EBaseImage -> EBaseImage # min :: EBaseImage -> EBaseImage -> EBaseImage # | |
| Show EBaseImage Source # | |
Defined in Language.Docker.EDSL.Types Methods showsPrec :: Int -> EBaseImage -> ShowS # show :: EBaseImage -> String # showList :: [EBaseImage] -> ShowS # | |
| IsString EBaseImage Source # | |
Defined in Language.Docker.EDSL.Types Methods fromString :: String -> EBaseImage # | |
QuasiQuoter (Language.Docker.EDSL.Quasi)
Types (Language.Docker.Syntax)
data Instruction args Source #
All commands available in Dockerfiles
Constructors
| 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) |
Instances
data InstructionPos args Source #
Instruction with additional location information required for creating
good check messages
Constructors
| InstructionPos | |
Fields
| |
Instances
Constructors
| BaseImage | |
Instances
| Eq BaseImage Source # | |
| Ord BaseImage Source # | |
| Show BaseImage Source # | |
| Lift BaseImage Source # | |
newtype SourcePath Source #
Constructors
| SourcePath | |
Fields
| |
Instances
| Eq SourcePath Source # | |
Defined in Language.Docker.Syntax | |
| Ord SourcePath Source # | |
Defined in Language.Docker.Syntax Methods compare :: SourcePath -> SourcePath -> Ordering # (<) :: SourcePath -> SourcePath -> Bool # (<=) :: SourcePath -> SourcePath -> Bool # (>) :: SourcePath -> SourcePath -> Bool # (>=) :: SourcePath -> SourcePath -> Bool # max :: SourcePath -> SourcePath -> SourcePath # min :: SourcePath -> SourcePath -> SourcePath # | |
| Show SourcePath Source # | |
Defined in Language.Docker.Syntax Methods showsPrec :: Int -> SourcePath -> ShowS # show :: SourcePath -> String # showList :: [SourcePath] -> ShowS # | |
| IsString SourcePath Source # | |
Defined in Language.Docker.Syntax Methods fromString :: String -> SourcePath # | |
| Lift SourcePath Source # | |
Defined in Language.Docker.Syntax.Lift Methods lift :: SourcePath -> Q Exp # | |
newtype TargetPath Source #
Constructors
| TargetPath | |
Fields
| |
Instances
| Eq TargetPath Source # | |
Defined in Language.Docker.Syntax | |
| Ord TargetPath Source # | |
Defined in Language.Docker.Syntax Methods compare :: TargetPath -> TargetPath -> Ordering # (<) :: TargetPath -> TargetPath -> Bool # (<=) :: TargetPath -> TargetPath -> Bool # (>) :: TargetPath -> TargetPath -> Bool # (>=) :: TargetPath -> TargetPath -> Bool # max :: TargetPath -> TargetPath -> TargetPath # min :: TargetPath -> TargetPath -> TargetPath # | |
| Show TargetPath Source # | |
Defined in Language.Docker.Syntax Methods showsPrec :: Int -> TargetPath -> ShowS # show :: TargetPath -> String # showList :: [TargetPath] -> ShowS # | |
| IsString TargetPath Source # | |
Defined in Language.Docker.Syntax Methods fromString :: String -> TargetPath # | |
| Lift TargetPath Source # | |
Defined in Language.Docker.Syntax.Lift Methods lift :: TargetPath -> Q Exp # | |
data CopySource Source #
Constructors
| CopySource !Text | |
| NoSource |
Instances
| Eq CopySource Source # | |
Defined in Language.Docker.Syntax | |
| Ord CopySource Source # | |
Defined in Language.Docker.Syntax Methods compare :: CopySource -> CopySource -> Ordering # (<) :: CopySource -> CopySource -> Bool # (<=) :: CopySource -> CopySource -> Bool # (>) :: CopySource -> CopySource -> Bool # (>=) :: CopySource -> CopySource -> Bool # max :: CopySource -> CopySource -> CopySource # min :: CopySource -> CopySource -> CopySource # | |
| Show CopySource Source # | |
Defined in Language.Docker.Syntax Methods showsPrec :: Int -> CopySource -> ShowS # show :: CopySource -> String # showList :: [CopySource] -> ShowS # | |
| IsString CopySource Source # | |
Defined in Language.Docker.Syntax Methods fromString :: String -> CopySource # | |
| Lift CopySource Source # | |
Defined in Language.Docker.Syntax.Lift Methods lift :: CopySource -> Q Exp # | |
Constructors
| CopyArgs | |
Fields
| |
Constructors
| AddArgs | |
Fields
| |
Instances
| Functor Check Source # | |
| Eq args => Eq (Check args) Source # | |
| Ord args => Ord (Check args) Source # | |
Defined in Language.Docker.Syntax | |
| Show args => Show (Check args) Source # | |
| Lift args => Lift (Check args) Source # | |
Constructors
| CheckArgs | |
Instances
| Functor CheckArgs Source # | |
| Eq args => Eq (CheckArgs args) Source # | |
| Ord args => Ord (CheckArgs args) Source # | |
Defined in Language.Docker.Syntax Methods compare :: CheckArgs args -> CheckArgs args -> Ordering # (<) :: CheckArgs args -> CheckArgs args -> Bool # (<=) :: CheckArgs args -> CheckArgs args -> Bool # (>) :: CheckArgs args -> CheckArgs args -> Bool # (>=) :: CheckArgs args -> CheckArgs args -> Bool # | |
| Show args => Show (CheckArgs args) Source # | |
| Lift args => Lift (CheckArgs args) Source # | |
Constructors
| Registry | |
Fields
| |
newtype ImageAlias Source #
Constructors
| ImageAlias | |
Fields
| |
Instances
| Eq ImageAlias Source # | |
Defined in Language.Docker.Syntax | |
| Ord ImageAlias Source # | |
Defined in Language.Docker.Syntax Methods compare :: ImageAlias -> ImageAlias -> Ordering # (<) :: ImageAlias -> ImageAlias -> Bool # (<=) :: ImageAlias -> ImageAlias -> Bool # (>) :: ImageAlias -> ImageAlias -> Bool # (>=) :: ImageAlias -> ImageAlias -> Bool # max :: ImageAlias -> ImageAlias -> ImageAlias # min :: ImageAlias -> ImageAlias -> ImageAlias # | |
| Show ImageAlias Source # | |
Defined in Language.Docker.Syntax Methods showsPrec :: Int -> ImageAlias -> ShowS # show :: ImageAlias -> String # showList :: [ImageAlias] -> ShowS # | |
| IsString ImageAlias Source # | |
Defined in Language.Docker.Syntax Methods fromString :: String -> ImageAlias # | |
| Lift ImageAlias Source # | |
Defined in Language.Docker.Syntax.Lift Methods lift :: ImageAlias -> Q Exp # | |
Instances
| Functor Arguments Source # | |
| IsList (Arguments Text) Source # | |
| Eq args => Eq (Arguments args) Source # | |
| Ord args => Ord (Arguments args) Source # | |
Defined in Language.Docker.Syntax Methods compare :: Arguments args -> Arguments args -> Ordering # (<) :: Arguments args -> Arguments args -> Bool # (<=) :: Arguments args -> Arguments args -> Bool # (>) :: Arguments args -> Arguments args -> Bool # (>=) :: Arguments args -> Arguments args -> Bool # | |
| Show args => Show (Arguments args) Source # | |
| IsString (Arguments Text) Source # | |
Defined in Language.Docker.Syntax Methods fromString :: String -> Arguments Text # | |
| Lift args => Lift (Arguments args) Source # | |
| Pretty (Arguments Text) Source # | |
| type Item (Arguments Text) Source # | |
Defined in Language.Docker.Syntax | |
type Linenumber = Int Source #
Instruction and InstructionPos helpers
instructionPos :: Instruction args -> InstructionPos args Source #