{-# LANGUAGE OverloadedStrings #-}
module Language.Docker.Parser.Instruction
( parseInstruction,
parseShell,
parseStopSignal,
parseArg,
parseUser,
parseWorkdir,
parseVolume,
parseEntryPoint,
parseMaintainer,
parseOnbuild,
parseComment,
)
where
import Language.Docker.Parser.Arguments (arguments)
import Language.Docker.Parser.Cmd (parseCmd)
import Language.Docker.Parser.Copy (parseAdd, parseCopy)
import Language.Docker.Parser.Expose (parseExpose)
import Language.Docker.Parser.From (parseFrom)
import Language.Docker.Parser.Healthcheck (parseHealthcheck)
import Language.Docker.Parser.Pairs (parseEnv, parseLabel)
import Language.Docker.Parser.Prelude
import Language.Docker.Parser.Run (parseRun)
import Language.Docker.Syntax
parseShell :: Parser (Instruction Text)
parseShell :: Parser (Instruction Text)
parseShell = do
Text -> Parser ()
reserved "SHELL"
Arguments Text -> Instruction Text
forall args. Arguments args -> Instruction args
Shell (Arguments Text -> Instruction Text)
-> ParsecT DockerfileError Text Identity (Arguments Text)
-> Parser (Instruction Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity (Arguments Text)
arguments
parseStopSignal :: Parser (Instruction Text)
parseStopSignal :: Parser (Instruction Text)
parseStopSignal = do
Text -> Parser ()
reserved "STOPSIGNAL"
Text
args <- String -> Parser Text
untilEol "the stop signal"
Instruction Text -> Parser (Instruction Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ Text -> Instruction Text
forall args. Text -> Instruction args
Stopsignal Text
args
parseArg :: Parser (Instruction Text)
parseArg :: Parser (Instruction Text)
parseArg = do
Text -> Parser ()
reserved "ARG"
(Parser (Instruction Text) -> Parser (Instruction Text)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser (Instruction Text)
forall args.
ParsecT DockerfileError Text Identity (Instruction args)
nameWithDefault Parser (Instruction Text) -> String -> Parser (Instruction Text)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> "the arg name")
Parser (Instruction Text)
-> Parser (Instruction Text) -> Parser (Instruction Text)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Maybe Text -> Instruction Text
forall args. Text -> Maybe Text -> Instruction args
Arg (Text -> Maybe Text -> Instruction Text)
-> Parser Text
-> ParsecT
DockerfileError Text Identity (Maybe Text -> Instruction Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser Text
untilEol "the argument name" ParsecT
DockerfileError Text Identity (Maybe Text -> Instruction Text)
-> ParsecT DockerfileError Text Identity (Maybe Text)
-> Parser (Instruction Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Text -> ParsecT DockerfileError Text Identity (Maybe Text)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Text
forall a. Maybe a
Nothing
where
nameWithDefault :: ParsecT DockerfileError Text Identity (Instruction args)
nameWithDefault = do
Text
name <- String -> (Char -> Bool) -> Parser Text
someUnless "the argument name" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '=')
ParsecT DockerfileError Text Identity Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity Char -> Parser ())
-> ParsecT DockerfileError Text Identity Char -> Parser ()
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT DockerfileError Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Token Text
'='
Text
df <- String -> Parser Text
untilEol "the argument value"
Instruction args
-> ParsecT DockerfileError Text Identity (Instruction args)
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction args
-> ParsecT DockerfileError Text Identity (Instruction args))
-> Instruction args
-> ParsecT DockerfileError Text Identity (Instruction args)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Instruction args
forall args. Text -> Maybe Text -> Instruction args
Arg Text
name (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
df)
parseUser :: Parser (Instruction Text)
parseUser :: Parser (Instruction Text)
parseUser = do
Text -> Parser ()
reserved "USER"
Text
username <- String -> Parser Text
untilEol "the user"
Instruction Text -> Parser (Instruction Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ Text -> Instruction Text
forall args. Text -> Instruction args
User Text
username
parseWorkdir :: Parser (Instruction Text)
parseWorkdir :: Parser (Instruction Text)
parseWorkdir = do
Text -> Parser ()
reserved "WORKDIR"
Text
directory <- String -> Parser Text
untilEol "the workdir path"
Instruction Text -> Parser (Instruction Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ Text -> Instruction Text
forall args. Text -> Instruction args
Workdir Text
directory
parseVolume :: Parser (Instruction Text)
parseVolume :: Parser (Instruction Text)
parseVolume = do
Text -> Parser ()
reserved "VOLUME"
Text
directory <- String -> Parser Text
untilEol "the volume path"
Instruction Text -> Parser (Instruction Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ Text -> Instruction Text
forall args. Text -> Instruction args
Volume Text
directory
parseMaintainer :: Parser (Instruction Text)
parseMaintainer :: Parser (Instruction Text)
parseMaintainer = do
Text -> Parser ()
reserved "MAINTAINER"
Text
name <- String -> Parser Text
untilEol "the maintainer name"
Instruction Text -> Parser (Instruction Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ Text -> Instruction Text
forall args. Text -> Instruction args
Maintainer Text
name
parseEntryPoint :: Parser (Instruction Text)
parseEntryPoint :: Parser (Instruction Text)
parseEntryPoint = do
Text -> Parser ()
reserved "ENTRYPOINT"
Arguments Text -> Instruction Text
forall args. Arguments args -> Instruction args
Entrypoint (Arguments Text -> Instruction Text)
-> ParsecT DockerfileError Text Identity (Arguments Text)
-> Parser (Instruction Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity (Arguments Text)
arguments
parseOnbuild :: Parser (Instruction Text)
parseOnbuild :: Parser (Instruction Text)
parseOnbuild = do
Text -> Parser ()
reserved "ONBUILD"
Instruction Text -> Instruction Text
forall args. Instruction args -> Instruction args
OnBuild (Instruction Text -> Instruction Text)
-> Parser (Instruction Text) -> Parser (Instruction Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Instruction Text)
parseInstruction
parseComment :: Parser (Instruction Text)
= Text -> Instruction Text
forall args. Text -> Instruction args
Comment (Text -> Instruction Text)
-> Parser Text -> Parser (Instruction Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
comment
parseInstruction :: Parser (Instruction Text)
parseInstruction :: Parser (Instruction Text)
parseInstruction =
[Parser (Instruction Text)] -> Parser (Instruction Text)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ Parser (Instruction Text)
parseOnbuild,
Parser (Instruction Text)
parseFrom,
Parser (Instruction Text)
parseCopy,
Parser (Instruction Text)
parseRun,
Parser (Instruction Text)
parseWorkdir,
Parser (Instruction Text)
parseEntryPoint,
Parser (Instruction Text)
parseVolume,
Parser (Instruction Text)
parseExpose,
Parser (Instruction Text)
parseEnv,
Parser (Instruction Text)
parseArg,
Parser (Instruction Text)
parseUser,
Parser (Instruction Text)
parseLabel,
Parser (Instruction Text)
parseStopSignal,
Parser (Instruction Text)
parseCmd,
Parser (Instruction Text)
parseShell,
Parser (Instruction Text)
parseMaintainer,
Parser (Instruction Text)
parseAdd,
Parser (Instruction Text)
parseComment,
Parser (Instruction Text)
parseHealthcheck
]