{-# LANGUAGE DuplicateRecordFields #-}
module Language.Docker.Parser.Run
( parseRun,
runFlags,
)
where
import Data.Functor (($>))
import qualified Data.Set as Set
import Language.Docker.Parser.Arguments (arguments)
import Language.Docker.Parser.Prelude
import Language.Docker.Syntax
data RunFlag
= RunFlagMount RunMount
| RunFlagSecurity RunSecurity
| RunFlagNetwork RunNetwork
deriving (Int -> RunFlag -> ShowS
[RunFlag] -> ShowS
RunFlag -> [Char]
(Int -> RunFlag -> ShowS)
-> (RunFlag -> [Char]) -> ([RunFlag] -> ShowS) -> Show RunFlag
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RunFlag -> ShowS
showsPrec :: Int -> RunFlag -> ShowS
$cshow :: RunFlag -> [Char]
show :: RunFlag -> [Char]
$cshowList :: [RunFlag] -> ShowS
showList :: [RunFlag] -> ShowS
Show)
data RunMountArg
= MountArgFromImage Text
| MountArgId Text
| MountArgMode Text
| MountArgReadOnly Bool
| MountArgRequired Bool
| MountArgSharing CacheSharing
| MountArgSource SourcePath
| MountArgTarget TargetPath
| MountArgType Text
| MountArgUid Text
| MountArgGid Text
deriving (Int -> RunMountArg -> ShowS
[RunMountArg] -> ShowS
RunMountArg -> [Char]
(Int -> RunMountArg -> ShowS)
-> (RunMountArg -> [Char])
-> ([RunMountArg] -> ShowS)
-> Show RunMountArg
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RunMountArg -> ShowS
showsPrec :: Int -> RunMountArg -> ShowS
$cshow :: RunMountArg -> [Char]
show :: RunMountArg -> [Char]
$cshowList :: [RunMountArg] -> ShowS
showList :: [RunMountArg] -> ShowS
Show)
data MountType
= Bind
| Cache
| Tmpfs
| Secret
| Ssh
parseRun :: (?esc :: Char) => Parser (Instruction Text)
parseRun :: (?esc::Char) => Parser (Instruction Text)
parseRun = do
(?esc::Char) => Text -> Parser ()
Text -> Parser ()
reserved Text
"RUN"
RunArgs Text -> Instruction Text
forall args. RunArgs args -> Instruction args
Run (RunArgs Text -> Instruction Text)
-> ParsecT DockerfileError Text Identity (RunArgs Text)
-> Parser (Instruction Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity (RunArgs Text)
(?esc::Char) =>
ParsecT DockerfileError Text Identity (RunArgs Text)
runArguments
runArguments :: (?esc :: Char) => Parser (RunArgs Text)
runArguments :: (?esc::Char) =>
ParsecT DockerfileError Text Identity (RunArgs Text)
runArguments = do
RunFlags
presentFlags <- [ParsecT DockerfileError Text Identity RunFlags]
-> ParsecT DockerfileError Text Identity RunFlags
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [ParsecT DockerfileError Text Identity RunFlags
(?esc::Char) => ParsecT DockerfileError Text Identity RunFlags
runFlags ParsecT DockerfileError Text Identity RunFlags
-> Parser () -> ParsecT DockerfileError Text Identity RunFlags
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
(?esc::Char) => Parser ()
requiredWhitespace, RunFlags -> ParsecT DockerfileError Text Identity RunFlags
forall a. a -> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Set RunMount -> Maybe RunSecurity -> Maybe RunNetwork -> RunFlags
RunFlags Set RunMount
forall a. Monoid a => a
mempty Maybe RunSecurity
forall a. Maybe a
Nothing Maybe RunNetwork
forall a. Maybe a
Nothing)]
Arguments Text
args <- Parser (Arguments Text)
(?esc::Char) => Parser (Arguments Text)
arguments
RunArgs Text
-> ParsecT DockerfileError Text Identity (RunArgs Text)
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (RunArgs Text
-> ParsecT DockerfileError Text Identity (RunArgs Text))
-> RunArgs Text
-> ParsecT DockerfileError Text Identity (RunArgs Text)
forall a b. (a -> b) -> a -> b
$ Arguments Text -> RunFlags -> RunArgs Text
forall args. Arguments args -> RunFlags -> RunArgs args
RunArgs Arguments Text
args RunFlags
presentFlags
runFlags :: (?esc :: Char) => Parser RunFlags
runFlags :: (?esc::Char) => ParsecT DockerfileError Text Identity RunFlags
runFlags = do
[RunFlag]
flags <- Parser RunFlag
(?esc::Char) => Parser RunFlag
runFlag Parser RunFlag
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity [RunFlag]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepBy` ParsecT DockerfileError Text Identity Text
flagSeparator
RunFlags -> ParsecT DockerfileError Text Identity RunFlags
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (RunFlags -> ParsecT DockerfileError Text Identity RunFlags)
-> RunFlags -> ParsecT DockerfileError Text Identity RunFlags
forall a b. (a -> b) -> a -> b
$ (RunFlag -> RunFlags -> RunFlags)
-> RunFlags -> [RunFlag] -> RunFlags
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RunFlag -> RunFlags -> RunFlags
toRunFlags RunFlags
emptyFlags [RunFlag]
flags
where
flagSeparator :: ParsecT DockerfileError Text Identity (Tokens Text)
flagSeparator = ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser ()
(?esc::Char) => Parser ()
requiredWhitespace Parser ()
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--")) ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> ParsecT DockerfileError Text Identity (Tokens Text)
forall a. [Char] -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"expected flag"
emptyFlags :: RunFlags
emptyFlags = Set RunMount -> Maybe RunSecurity -> Maybe RunNetwork -> RunFlags
RunFlags Set RunMount
forall a. Monoid a => a
mempty Maybe RunSecurity
forall a. Maybe a
Nothing Maybe RunNetwork
forall a. Maybe a
Nothing
toRunFlags :: RunFlag -> RunFlags -> RunFlags
toRunFlags (RunFlagMount RunMount
m) rf :: RunFlags
rf@RunFlags { $sel:mount:RunFlags :: RunFlags -> Set RunMount
mount = Set RunMount
mnt } = RunFlags
rf {mount = Set.insert m mnt}
toRunFlags (RunFlagNetwork RunNetwork
n) RunFlags
rf = RunFlags
rf {network = Just n}
toRunFlags (RunFlagSecurity RunSecurity
s) RunFlags
rf = RunFlags
rf {security = Just s}
runFlag :: (?esc :: Char) => Parser RunFlag
runFlag :: (?esc::Char) => Parser RunFlag
runFlag =
[Parser RunFlag] -> Parser RunFlag
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ RunMount -> RunFlag
RunFlagMount (RunMount -> RunFlag)
-> ParsecT DockerfileError Text Identity RunMount -> Parser RunFlag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity RunMount
(?esc::Char) => ParsecT DockerfileError Text Identity RunMount
runFlagMount,
RunSecurity -> RunFlag
RunFlagSecurity (RunSecurity -> RunFlag)
-> ParsecT DockerfileError Text Identity RunSecurity
-> Parser RunFlag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity RunSecurity
runFlagSecurity,
RunNetwork -> RunFlag
RunFlagNetwork (RunNetwork -> RunFlag)
-> ParsecT DockerfileError Text Identity RunNetwork
-> Parser RunFlag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity RunNetwork
runFlagNetwork
]
runFlagSecurity :: Parser RunSecurity
runFlagSecurity :: ParsecT DockerfileError Text Identity RunSecurity
runFlagSecurity = do
ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--security="
[ParsecT DockerfileError Text Identity RunSecurity]
-> ParsecT DockerfileError Text Identity RunSecurity
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [RunSecurity
Insecure RunSecurity
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity RunSecurity
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"insecure", RunSecurity
Sandbox RunSecurity
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity RunSecurity
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"sandbox"]
runFlagNetwork :: Parser RunNetwork
runFlagNetwork :: ParsecT DockerfileError Text Identity RunNetwork
runFlagNetwork = do
ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--network="
[ParsecT DockerfileError Text Identity RunNetwork]
-> ParsecT DockerfileError Text Identity RunNetwork
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [RunNetwork
NetworkNone RunNetwork
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity RunNetwork
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"none", RunNetwork
NetworkHost RunNetwork
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity RunNetwork
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"host", RunNetwork
NetworkDefault RunNetwork
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity RunNetwork
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"default"]
runFlagMount :: (?esc :: Char) => Parser RunMount
runFlagMount :: (?esc::Char) => ParsecT DockerfileError Text Identity RunMount
runFlagMount = do
ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--mount="
Maybe MountType
maybeType <-
[ParsecT DockerfileError Text Identity (Maybe MountType)]
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"type="
ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [ParsecT DockerfileError Text Identity (Maybe MountType)]
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ MountType -> Maybe MountType
forall a. a -> Maybe a
Just MountType
Bind Maybe MountType
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"bind",
MountType -> Maybe MountType
forall a. a -> Maybe a
Just MountType
Cache Maybe MountType
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"cache",
MountType -> Maybe MountType
forall a. a -> Maybe a
Just MountType
Tmpfs Maybe MountType
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"tmpfs",
MountType -> Maybe MountType
forall a. a -> Maybe a
Just MountType
Secret Maybe MountType
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"secret",
MountType -> Maybe MountType
forall a. a -> Maybe a
Just MountType
Ssh Maybe MountType
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"ssh"
],
Maybe MountType
-> ParsecT DockerfileError Text Identity (Maybe MountType)
forall a. a -> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe MountType
forall a. Maybe a
Nothing
]
(MountType
mountType, Parser [RunMountArg]
args) <- (MountType, Parser [RunMountArg])
-> ParsecT
DockerfileError Text Identity (MountType, Parser [RunMountArg])
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ((MountType, Parser [RunMountArg])
-> ParsecT
DockerfileError Text Identity (MountType, Parser [RunMountArg]))
-> (MountType, Parser [RunMountArg])
-> ParsecT
DockerfileError Text Identity (MountType, Parser [RunMountArg])
forall a b. (a -> b) -> a -> b
$
case Maybe MountType
maybeType of
Maybe MountType
Nothing -> (MountType
Bind, (?esc::Char) => MountType -> Parser [RunMountArg]
MountType -> Parser [RunMountArg]
argsParser MountType
Bind)
Just MountType
Ssh -> (MountType
Ssh, [Parser [RunMountArg]] -> Parser [RunMountArg]
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"," ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser [RunMountArg] -> Parser [RunMountArg]
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (?esc::Char) => MountType -> Parser [RunMountArg]
MountType -> Parser [RunMountArg]
argsParser MountType
Ssh, [RunMountArg] -> Parser [RunMountArg]
forall a. a -> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []])
Just MountType
t -> (MountType
t, Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"," ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser [RunMountArg] -> Parser [RunMountArg]
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (?esc::Char) => MountType -> Parser [RunMountArg]
MountType -> Parser [RunMountArg]
argsParser MountType
t)
case MountType
mountType of
MountType
Bind -> BindOpts -> RunMount
BindMount (BindOpts -> RunMount)
-> ParsecT DockerfileError Text Identity BindOpts
-> ParsecT DockerfileError Text Identity RunMount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([RunMountArg] -> ParsecT DockerfileError Text Identity BindOpts
bindMount ([RunMountArg] -> ParsecT DockerfileError Text Identity BindOpts)
-> Parser [RunMountArg]
-> ParsecT DockerfileError Text Identity BindOpts
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Parser [RunMountArg]
args)
MountType
Cache -> CacheOpts -> RunMount
CacheMount (CacheOpts -> RunMount)
-> ParsecT DockerfileError Text Identity CacheOpts
-> ParsecT DockerfileError Text Identity RunMount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([RunMountArg] -> ParsecT DockerfileError Text Identity CacheOpts
cacheMount ([RunMountArg] -> ParsecT DockerfileError Text Identity CacheOpts)
-> Parser [RunMountArg]
-> ParsecT DockerfileError Text Identity CacheOpts
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Parser [RunMountArg]
args)
MountType
Tmpfs -> TmpOpts -> RunMount
TmpfsMount (TmpOpts -> RunMount)
-> ParsecT DockerfileError Text Identity TmpOpts
-> ParsecT DockerfileError Text Identity RunMount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([RunMountArg] -> ParsecT DockerfileError Text Identity TmpOpts
tmpfsMount ([RunMountArg] -> ParsecT DockerfileError Text Identity TmpOpts)
-> Parser [RunMountArg]
-> ParsecT DockerfileError Text Identity TmpOpts
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Parser [RunMountArg]
args)
MountType
Secret -> SecretOpts -> RunMount
SecretMount (SecretOpts -> RunMount)
-> ParsecT DockerfileError Text Identity SecretOpts
-> ParsecT DockerfileError Text Identity RunMount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([RunMountArg] -> ParsecT DockerfileError Text Identity SecretOpts
secretMount ([RunMountArg] -> ParsecT DockerfileError Text Identity SecretOpts)
-> Parser [RunMountArg]
-> ParsecT DockerfileError Text Identity SecretOpts
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Parser [RunMountArg]
args)
MountType
Ssh -> SecretOpts -> RunMount
SshMount (SecretOpts -> RunMount)
-> ParsecT DockerfileError Text Identity SecretOpts
-> ParsecT DockerfileError Text Identity RunMount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([RunMountArg] -> ParsecT DockerfileError Text Identity SecretOpts
secretMount ([RunMountArg] -> ParsecT DockerfileError Text Identity SecretOpts)
-> Parser [RunMountArg]
-> ParsecT DockerfileError Text Identity SecretOpts
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Parser [RunMountArg]
args)
argsParser :: (?esc :: Char) => MountType -> Parser [RunMountArg]
argsParser :: (?esc::Char) => MountType -> Parser [RunMountArg]
argsParser MountType
mountType = (?esc::Char) => MountType -> Parser RunMountArg
MountType -> Parser RunMountArg
mountChoices MountType
mountType Parser RunMountArg
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser [RunMountArg]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepBy1` Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
","
bindMount :: [RunMountArg] -> Parser BindOpts
bindMount :: [RunMountArg] -> ParsecT DockerfileError Text Identity BindOpts
bindMount [RunMountArg]
args =
case Text
-> Set Text
-> Set Text
-> [RunMountArg]
-> Either DockerfileError [RunMountArg]
forall (t :: * -> *).
Foldable t =>
Text
-> Set Text
-> Set Text
-> t RunMountArg
-> Either DockerfileError [RunMountArg]
validArgs Text
"bind" Set Text
allowed Set Text
required [RunMountArg]
args of
Left DockerfileError
e -> DockerfileError -> ParsecT DockerfileError Text Identity BindOpts
forall a. DockerfileError -> Parser a
customError DockerfileError
e
Right [RunMountArg]
as -> BindOpts -> ParsecT DockerfileError Text Identity BindOpts
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (BindOpts -> ParsecT DockerfileError Text Identity BindOpts)
-> BindOpts -> ParsecT DockerfileError Text Identity BindOpts
forall a b. (a -> b) -> a -> b
$ (RunMountArg -> BindOpts -> BindOpts)
-> BindOpts -> [RunMountArg] -> BindOpts
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RunMountArg -> BindOpts -> BindOpts
bindOpts BindOpts
forall a. Default a => a
def [RunMountArg]
as
where
allowed :: Set Text
allowed = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text
"target", Text
"source", Text
"from", Text
"ro"]
required :: Set Text
required = Text -> Set Text
forall a. a -> Set a
Set.singleton Text
"target"
bindOpts :: RunMountArg -> BindOpts -> BindOpts
bindOpts :: RunMountArg -> BindOpts -> BindOpts
bindOpts (MountArgTarget TargetPath
path) BindOpts
bo = BindOpts
bo {bTarget = path}
bindOpts (MountArgSource SourcePath
path) BindOpts
bo = BindOpts
bo {bSource = Just path}
bindOpts (MountArgFromImage Text
img) BindOpts
bo = BindOpts
bo {bFromImage = Just img}
bindOpts (MountArgReadOnly Bool
ro) BindOpts
bo = BindOpts
bo {bReadOnly = Just ro}
bindOpts RunMountArg
invalid BindOpts
_ = [Char] -> BindOpts
forall a. HasCallStack => [Char] -> a
error ([Char] -> BindOpts) -> [Char] -> BindOpts
forall a b. (a -> b) -> a -> b
$ [Char]
"unhandled " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> RunMountArg -> [Char]
forall a. Show a => a -> [Char]
show RunMountArg
invalid [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
" please report this bug"
cacheMount :: [RunMountArg] -> Parser CacheOpts
cacheMount :: [RunMountArg] -> ParsecT DockerfileError Text Identity CacheOpts
cacheMount [RunMountArg]
args =
case Text
-> Set Text
-> Set Text
-> [RunMountArg]
-> Either DockerfileError [RunMountArg]
forall (t :: * -> *).
Foldable t =>
Text
-> Set Text
-> Set Text
-> t RunMountArg
-> Either DockerfileError [RunMountArg]
validArgs Text
"cache" Set Text
allowed Set Text
required [RunMountArg]
args of
Left DockerfileError
e -> DockerfileError -> ParsecT DockerfileError Text Identity CacheOpts
forall a. DockerfileError -> Parser a
customError DockerfileError
e
Right [RunMountArg]
as -> CacheOpts -> ParsecT DockerfileError Text Identity CacheOpts
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (CacheOpts -> ParsecT DockerfileError Text Identity CacheOpts)
-> CacheOpts -> ParsecT DockerfileError Text Identity CacheOpts
forall a b. (a -> b) -> a -> b
$ (RunMountArg -> CacheOpts -> CacheOpts)
-> CacheOpts -> [RunMountArg] -> CacheOpts
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RunMountArg -> CacheOpts -> CacheOpts
cacheOpts CacheOpts
forall a. Default a => a
def [RunMountArg]
as
where
allowed :: Set Text
allowed = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text
"target", Text
"sharing", Text
"id", Text
"ro", Text
"from", Text
"source", Text
"mode", Text
"uid", Text
"gid"]
required :: Set Text
required = Text -> Set Text
forall a. a -> Set a
Set.singleton Text
"target"
cacheOpts :: RunMountArg -> CacheOpts -> CacheOpts
cacheOpts :: RunMountArg -> CacheOpts -> CacheOpts
cacheOpts (MountArgTarget TargetPath
path) CacheOpts
co = CacheOpts
co {cTarget = path}
cacheOpts (MountArgSharing CacheSharing
sh) CacheOpts
co = CacheOpts
co {cSharing = Just sh}
cacheOpts (MountArgId Text
i) CacheOpts
co = CacheOpts
co {cCacheId = Just i}
cacheOpts (MountArgReadOnly Bool
ro) CacheOpts
co = CacheOpts
co {cReadOnly = Just ro}
cacheOpts (MountArgFromImage Text
img) CacheOpts
co = CacheOpts
co {cFromImage = Just img}
cacheOpts (MountArgSource SourcePath
path) CacheOpts
co = CacheOpts
co {cSource = Just path}
cacheOpts (MountArgMode Text
m) CacheOpts
co = CacheOpts
co {cMode = Just m}
cacheOpts (MountArgUid Text
u) CacheOpts
co = CacheOpts
co {cUid = Just u}
cacheOpts (MountArgGid Text
g) CacheOpts
co = CacheOpts
co {cGid = Just g}
cacheOpts RunMountArg
invalid CacheOpts
_ = [Char] -> CacheOpts
forall a. HasCallStack => [Char] -> a
error ([Char] -> CacheOpts) -> [Char] -> CacheOpts
forall a b. (a -> b) -> a -> b
$ [Char]
"unhandled " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> RunMountArg -> [Char]
forall a. Show a => a -> [Char]
show RunMountArg
invalid [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
" please report this bug"
tmpfsMount :: [RunMountArg] -> Parser TmpOpts
tmpfsMount :: [RunMountArg] -> ParsecT DockerfileError Text Identity TmpOpts
tmpfsMount [RunMountArg]
args =
case Text
-> Set Text
-> Set Text
-> [RunMountArg]
-> Either DockerfileError [RunMountArg]
forall (t :: * -> *).
Foldable t =>
Text
-> Set Text
-> Set Text
-> t RunMountArg
-> Either DockerfileError [RunMountArg]
validArgs Text
"tmpfs" Set Text
required Set Text
required [RunMountArg]
args of
Left DockerfileError
e -> DockerfileError -> ParsecT DockerfileError Text Identity TmpOpts
forall a. DockerfileError -> Parser a
customError DockerfileError
e
Right [RunMountArg]
as -> TmpOpts -> ParsecT DockerfileError Text Identity TmpOpts
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (TmpOpts -> ParsecT DockerfileError Text Identity TmpOpts)
-> TmpOpts -> ParsecT DockerfileError Text Identity TmpOpts
forall a b. (a -> b) -> a -> b
$ (RunMountArg -> TmpOpts -> TmpOpts)
-> TmpOpts -> [RunMountArg] -> TmpOpts
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RunMountArg -> TmpOpts -> TmpOpts
tmpOpts TmpOpts
forall a. Default a => a
def [RunMountArg]
as
where
required :: Set Text
required = Text -> Set Text
forall a. a -> Set a
Set.singleton Text
"target"
tmpOpts :: RunMountArg -> TmpOpts -> TmpOpts
tmpOpts :: RunMountArg -> TmpOpts -> TmpOpts
tmpOpts (MountArgTarget TargetPath
path) TmpOpts
t = TmpOpts
t {tTarget = path}
tmpOpts RunMountArg
invalid TmpOpts
_ = [Char] -> TmpOpts
forall a. HasCallStack => [Char] -> a
error ([Char] -> TmpOpts) -> [Char] -> TmpOpts
forall a b. (a -> b) -> a -> b
$ [Char]
"unhandled " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> RunMountArg -> [Char]
forall a. Show a => a -> [Char]
show RunMountArg
invalid [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
" please report this bug"
secretMount :: [RunMountArg] -> Parser SecretOpts
secretMount :: [RunMountArg] -> ParsecT DockerfileError Text Identity SecretOpts
secretMount [RunMountArg]
args =
case Text
-> Set Text
-> Set Text
-> [RunMountArg]
-> Either DockerfileError [RunMountArg]
forall (t :: * -> *).
Foldable t =>
Text
-> Set Text
-> Set Text
-> t RunMountArg
-> Either DockerfileError [RunMountArg]
validArgs Text
"secret" Set Text
allowed Set Text
forall {a}. Set a
required [RunMountArg]
args of
Left DockerfileError
e -> DockerfileError -> ParsecT DockerfileError Text Identity SecretOpts
forall a. DockerfileError -> Parser a
customError DockerfileError
e
Right [RunMountArg]
as -> SecretOpts -> ParsecT DockerfileError Text Identity SecretOpts
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (SecretOpts -> ParsecT DockerfileError Text Identity SecretOpts)
-> SecretOpts -> ParsecT DockerfileError Text Identity SecretOpts
forall a b. (a -> b) -> a -> b
$ (RunMountArg -> SecretOpts -> SecretOpts)
-> SecretOpts -> [RunMountArg] -> SecretOpts
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RunMountArg -> SecretOpts -> SecretOpts
secretOpts SecretOpts
forall a. Default a => a
def [RunMountArg]
as
where
allowed :: Set Text
allowed = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text
"target", Text
"id", Text
"required", Text
"source", Text
"mode", Text
"uid", Text
"gid"]
required :: Set a
required = Set a
forall {a}. Set a
Set.empty
secretOpts :: RunMountArg -> SecretOpts -> SecretOpts
secretOpts :: RunMountArg -> SecretOpts -> SecretOpts
secretOpts (MountArgTarget TargetPath
path) SecretOpts
co = SecretOpts
co {sTarget = Just path}
secretOpts (MountArgId Text
i) SecretOpts
co = SecretOpts
co {sCacheId = Just i}
secretOpts (MountArgRequired Bool
r) SecretOpts
co = SecretOpts
co {sIsRequired = Just r}
secretOpts (MountArgSource SourcePath
path) SecretOpts
co = SecretOpts
co {sSource = Just path}
secretOpts (MountArgMode Text
m) SecretOpts
co = SecretOpts
co {sMode = Just m}
secretOpts (MountArgUid Text
u) SecretOpts
co = SecretOpts
co {sUid = Just u}
secretOpts (MountArgGid Text
g) SecretOpts
co = SecretOpts
co {sGid = Just g}
secretOpts RunMountArg
invalid SecretOpts
_ = [Char] -> SecretOpts
forall a. HasCallStack => [Char] -> a
error ([Char] -> SecretOpts) -> [Char] -> SecretOpts
forall a b. (a -> b) -> a -> b
$ [Char]
"unhandled " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> RunMountArg -> [Char]
forall a. Show a => a -> [Char]
show RunMountArg
invalid [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
" please report this bug"
validArgs ::
Foldable t =>
Text ->
Set.Set Text ->
Set.Set Text ->
t RunMountArg ->
Either DockerfileError [RunMountArg]
validArgs :: forall (t :: * -> *).
Foldable t =>
Text
-> Set Text
-> Set Text
-> t RunMountArg
-> Either DockerfileError [RunMountArg]
validArgs Text
typeName Set Text
allowed Set Text
required t RunMountArg
args =
let (Either DockerfileError [RunMountArg]
result, Set Text
seen) = (RunMountArg
-> (Either DockerfileError [RunMountArg], Set Text)
-> (Either DockerfileError [RunMountArg], Set Text))
-> (Either DockerfileError [RunMountArg], Set Text)
-> t RunMountArg
-> (Either DockerfileError [RunMountArg], Set Text)
forall a b. (a -> b -> b) -> b -> t a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RunMountArg
-> (Either DockerfileError [RunMountArg], Set Text)
-> (Either DockerfileError [RunMountArg], Set Text)
checkValidArg ([RunMountArg] -> Either DockerfileError [RunMountArg]
forall a b. b -> Either a b
Right [], Set Text
forall {a}. Set a
Set.empty) t RunMountArg
args
in case Set Text -> [Text]
forall a. Set a -> [a]
Set.toList (Set Text -> Set Text -> Set Text
forall a. Ord a => Set a -> Set a -> Set a
Set.difference Set Text
required Set Text
seen) of
[] -> Either DockerfileError [RunMountArg]
result
[Text]
missing -> DockerfileError -> Either DockerfileError [RunMountArg]
forall a b. a -> Either a b
Left (DockerfileError -> Either DockerfileError [RunMountArg])
-> DockerfileError -> Either DockerfileError [RunMountArg]
forall a b. (a -> b) -> a -> b
$ [Text] -> DockerfileError
MissingArgument [Text]
missing
where
checkValidArg :: RunMountArg
-> (Either DockerfileError [RunMountArg], Set Text)
-> (Either DockerfileError [RunMountArg], Set Text)
checkValidArg RunMountArg
_ x :: (Either DockerfileError [RunMountArg], Set Text)
x@(Left DockerfileError
_, Set Text
_) = (Either DockerfileError [RunMountArg], Set Text)
x
checkValidArg RunMountArg
a (Right [RunMountArg]
as, Set Text
seen) =
let name :: Text
name = RunMountArg -> Text
toArgName RunMountArg
a
in case (Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member Text
name Set Text
allowed, Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member Text
name Set Text
seen) of
(Bool
False, Bool
_) -> (DockerfileError -> Either DockerfileError [RunMountArg]
forall a b. a -> Either a b
Left (Text -> Text -> DockerfileError
UnexpectedArgument Text
name Text
typeName), Set Text
seen)
(Bool
_, Bool
True) -> (DockerfileError -> Either DockerfileError [RunMountArg]
forall a b. a -> Either a b
Left (Text -> DockerfileError
DuplicateArgument Text
name), Set Text
seen)
(Bool
True, Bool
False) -> ([RunMountArg] -> Either DockerfileError [RunMountArg]
forall a b. b -> Either a b
Right (RunMountArg
a RunMountArg -> [RunMountArg] -> [RunMountArg]
forall a. a -> [a] -> [a]
: [RunMountArg]
as), Text -> Set Text -> Set Text
forall a. Ord a => a -> Set a -> Set a
Set.insert Text
name Set Text
seen)
mountChoices :: (?esc :: Char) => MountType -> Parser RunMountArg
mountChoices :: (?esc::Char) => MountType -> Parser RunMountArg
mountChoices MountType
mountType =
[Parser RunMountArg] -> Parser RunMountArg
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice ([Parser RunMountArg] -> Parser RunMountArg)
-> [Parser RunMountArg] -> Parser RunMountArg
forall a b. (a -> b) -> a -> b
$
case MountType
mountType of
MountType
Bind ->
[ Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgTarget,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgSource,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgFromImage,
Parser RunMountArg
mountArgReadOnly
]
MountType
Cache ->
[ Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgTarget,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgSource,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgFromImage,
Parser RunMountArg
mountArgReadOnly,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgId,
Parser RunMountArg
mountArgSharing,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgMode,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgUid,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgGid
]
MountType
Tmpfs -> [Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgTarget]
MountType
_ ->
[ Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgTarget,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgId,
Parser RunMountArg
mountArgRequired,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgSource,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgMode,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgUid,
Parser RunMountArg
(?esc::Char) => Parser RunMountArg
mountArgGid
]
stringArg :: (?esc :: Char) => Parser Text
stringArg :: (?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg = [ParsecT DockerfileError Text Identity Text]
-> ParsecT DockerfileError Text Identity Text
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [ParsecT DockerfileError Text Identity Text
doubleQuotedString, (?esc::Char) =>
[Char]
-> (Char -> Bool) -> ParsecT DockerfileError Text Identity Text
[Char]
-> (Char -> Bool) -> ParsecT DockerfileError Text Identity Text
someUnless [Char]
"a string" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
',')]
key :: Text -> Parser a -> Parser a
key :: forall a. Text -> Parser a -> Parser a
key Text
name Parser a
p = Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string (Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"=") ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser a -> Parser a
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a
p
tryKeyValue' :: Text -> Text -> Parser Text
tryKeyValue' :: Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
k Text
v = ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text)
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
(MonadParsec e s m, FoldCase (Tokens s)) =>
Tokens s -> m (Tokens s)
string' (Text
k Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"=") ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a b.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
(MonadParsec e s m, FoldCase (Tokens s)) =>
Tokens s -> m (Tokens s)
string' Text
Tokens Text
v
cacheSharing :: Parser CacheSharing
cacheSharing :: Parser CacheSharing
cacheSharing =
[Parser CacheSharing] -> Parser CacheSharing
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [CacheSharing
Private CacheSharing
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser CacheSharing
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"private", CacheSharing
Shared CacheSharing
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser CacheSharing
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"shared", CacheSharing
Locked CacheSharing
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> Parser CacheSharing
forall a b.
a
-> ParsecT DockerfileError Text Identity b
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"locked"]
mountArgFromImage :: (?esc :: Char) => Parser RunMountArg
mountArgFromImage :: (?esc::Char) => Parser RunMountArg
mountArgFromImage = Text -> RunMountArg
MountArgFromImage (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a. Text -> Parser a -> Parser a
key Text
"from" ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
mountArgGid :: (?esc :: Char) => Parser RunMountArg
mountArgGid :: (?esc::Char) => Parser RunMountArg
mountArgGid = Text -> RunMountArg
MountArgGid (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a. Text -> Parser a -> Parser a
key Text
"gid" ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
mountArgId :: (?esc :: Char) => Parser RunMountArg
mountArgId :: (?esc::Char) => Parser RunMountArg
mountArgId = Text -> RunMountArg
MountArgId (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a. Text -> Parser a -> Parser a
key Text
"id" ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
mountArgMode :: (?esc :: Char) => Parser RunMountArg
mountArgMode :: (?esc::Char) => Parser RunMountArg
mountArgMode = Text -> RunMountArg
MountArgMode (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a. Text -> Parser a -> Parser a
key Text
"mode" ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
mountArgReadOnly :: Parser RunMountArg
mountArgReadOnly :: Parser RunMountArg
mountArgReadOnly =
Bool -> RunMountArg
MountArgReadOnly
(Bool -> RunMountArg)
-> ParsecT DockerfileError Text Identity Bool -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT DockerfileError Text Identity Bool]
-> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ ParsecT DockerfileError Text Identity Bool
choiceRoExplicit,
ParsecT DockerfileError Text Identity Bool
choiceRwExplicit,
ParsecT DockerfileError Text Identity Bool
choiceRo,
ParsecT DockerfileError Text Identity Bool
choiceRw
]
where
choiceRoExplicit :: ParsecT DockerfileError Text Identity Bool
choiceRoExplicit =
[ParsecT DockerfileError Text Identity Text]
-> ParsecT DockerfileError Text Identity Text
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"ro" Text
"true",
Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"rw" Text
"false",
Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"readonly" Text
"true",
Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"readwrite" Text
"false"
] ParsecT DockerfileError Text Identity Text
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
choiceRwExplicit :: ParsecT DockerfileError Text Identity Bool
choiceRwExplicit =
[ParsecT DockerfileError Text Identity Text]
-> ParsecT DockerfileError Text Identity Text
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"rw" Text
"true",
Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"ro" Text
"false",
Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"readwrite" Text
"true",
Text -> Text -> ParsecT DockerfileError Text Identity Text
tryKeyValue' Text
"readonly" Text
"false"
] ParsecT DockerfileError Text Identity Text
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
choiceRo :: ParsecT DockerfileError Text Identity Bool
choiceRo =
[ParsecT DockerfileError Text Identity (Tokens Text)]
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
(MonadParsec e s m, FoldCase (Tokens s)) =>
Tokens s -> m (Tokens s)
string' Tokens Text
"ro",
Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
(MonadParsec e s m, FoldCase (Tokens s)) =>
Tokens s -> m (Tokens s)
string' Tokens Text
"readonly"
] ParsecT DockerfileError Text Identity (Tokens Text)
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
choiceRw :: ParsecT DockerfileError Text Identity Bool
choiceRw =
[ParsecT DockerfileError Text Identity (Tokens Text)]
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
(MonadParsec e s m, FoldCase (Tokens s)) =>
Tokens s -> m (Tokens s)
string' Tokens Text
"rw",
Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
(MonadParsec e s m, FoldCase (Tokens s)) =>
Tokens s -> m (Tokens s)
string' Tokens Text
"readwrite"
] ParsecT DockerfileError Text Identity (Tokens Text)
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
mountArgRequired :: Parser RunMountArg
mountArgRequired :: Parser RunMountArg
mountArgRequired = Bool -> RunMountArg
MountArgRequired (Bool -> RunMountArg)
-> ParsecT DockerfileError Text Identity Bool -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT DockerfileError Text Identity Bool]
-> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
[ [ParsecT DockerfileError Text Identity Text]
-> ParsecT DockerfileError Text Identity Text
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [ParsecT DockerfileError Text Identity Text
"required=true",
ParsecT DockerfileError Text Identity Text
"required=True"
] ParsecT DockerfileError Text Identity Text
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True,
[ParsecT DockerfileError Text Identity Text]
-> ParsecT DockerfileError Text Identity Text
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [ParsecT DockerfileError Text Identity Text
"required=false",
ParsecT DockerfileError Text Identity Text
"required=False"
] ParsecT DockerfileError Text Identity Text
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False,
Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"required" ParsecT DockerfileError Text Identity (Tokens Text)
-> Bool -> ParsecT DockerfileError Text Identity Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
]
mountArgSharing :: Parser RunMountArg
mountArgSharing :: Parser RunMountArg
mountArgSharing = CacheSharing -> RunMountArg
MountArgSharing (CacheSharing -> RunMountArg)
-> Parser CacheSharing -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Parser CacheSharing -> Parser CacheSharing
forall a. Text -> Parser a -> Parser a
key Text
"sharing" Parser CacheSharing
cacheSharing
mountArgSource :: (?esc :: Char) => Parser RunMountArg
mountArgSource :: (?esc::Char) => Parser RunMountArg
mountArgSource = do
[Char]
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
[Char]
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
[Char] -> m a -> m a
label [Char]
"source=" (ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text))
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a b. (a -> b) -> a -> b
$ [ParsecT DockerfileError Text Identity (Tokens Text)]
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"source=", Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"src="]
SourcePath -> RunMountArg
MountArgSource (SourcePath -> RunMountArg)
-> (Text -> SourcePath) -> Text -> RunMountArg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> SourcePath
SourcePath (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
mountArgTarget :: (?esc :: Char) => Parser RunMountArg
mountArgTarget :: (?esc::Char) => Parser RunMountArg
mountArgTarget = do
[Char]
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
[Char]
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
[Char] -> m a -> m a
label [Char]
"target=" (ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text))
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a b. (a -> b) -> a -> b
$ [ParsecT DockerfileError Text Identity (Tokens Text)]
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice [Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"target=", Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"dst=", Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"destination="]
TargetPath -> RunMountArg
MountArgTarget (TargetPath -> RunMountArg)
-> (Text -> TargetPath) -> Text -> RunMountArg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TargetPath
TargetPath (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
mountArgUid :: (?esc :: Char) => Parser RunMountArg
mountArgUid :: (?esc::Char) => Parser RunMountArg
mountArgUid = Text -> RunMountArg
MountArgUid (Text -> RunMountArg)
-> ParsecT DockerfileError Text Identity Text -> Parser RunMountArg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT DockerfileError Text Identity Text
-> ParsecT DockerfileError Text Identity Text
forall a. Text -> Parser a -> Parser a
key Text
"uid" ParsecT DockerfileError Text Identity Text
(?esc::Char) => ParsecT DockerfileError Text Identity Text
stringArg
toArgName :: RunMountArg -> Text
toArgName :: RunMountArg -> Text
toArgName (MountArgFromImage Text
_) = Text
"from"
toArgName (MountArgGid Text
_) = Text
"gid"
toArgName (MountArgId Text
_) = Text
"id"
toArgName (MountArgMode Text
_) = Text
"mode"
toArgName (MountArgReadOnly Bool
_) = Text
"ro"
toArgName (MountArgRequired Bool
_) = Text
"required"
toArgName (MountArgSharing CacheSharing
_) = Text
"sharing"
toArgName (MountArgSource SourcePath
_) = Text
"source"
toArgName (MountArgTarget TargetPath
_) = Text
"target"
toArgName (MountArgType Text
_) = Text
"type"
toArgName (MountArgUid Text
_) = Text
"uid"