split out DockerAttr

This commit is contained in:
Joey Hess 2014-05-31 22:00:11 -04:00
parent b0f2478bcb
commit cae7e15f56
2 changed files with 37 additions and 24 deletions

View File

@ -72,7 +72,7 @@ type ContainerName = String
container :: ContainerName -> Image -> Host container :: ContainerName -> Image -> Host
container cn image = Host hn [] attr container cn image = Host hn [] attr
where where
attr = mempty { _dockerImage = Val image } attr = dockerAttr $ mempty { _dockerImage = Val image }
hn = cn2hn cn hn = cn2hn cn
cn2hn :: ContainerName -> HostName cn2hn :: ContainerName -> HostName
@ -145,7 +145,7 @@ mkContainer cid@(ContainerId hn _cn) h = Container
<$> fromVal (_dockerImage attr) <$> fromVal (_dockerImage attr)
<*> pure (map (\a -> a hn) (_dockerRunParams attr)) <*> pure (map (\a -> a hn) (_dockerRunParams attr))
where where
attr = hostAttr h' attr = _dockerattr $ hostAttr h'
h' = h h' = h
-- expose propellor directory inside the container -- expose propellor directory inside the container
& volume (localdir++":"++localdir) & volume (localdir++":"++localdir)
@ -443,15 +443,18 @@ listImages :: IO [Image]
listImages = lines <$> readProcess dockercmd ["images", "--all", "--quiet"] listImages = lines <$> readProcess dockercmd ["images", "--all", "--quiet"]
runProp :: String -> RunParam -> Property runProp :: String -> RunParam -> Property
runProp field val = pureAttrProperty (param) $ runProp field val = pureAttrProperty (param) $ dockerAttr $
mempty { _dockerRunParams = [\_ -> "--"++param] } mempty { _dockerRunParams = [\_ -> "--"++param] }
where where
param = field++"="++val param = field++"="++val
genProp :: String -> (HostName -> RunParam) -> Property genProp :: String -> (HostName -> RunParam) -> Property
genProp field mkval = pureAttrProperty field $ genProp field mkval = pureAttrProperty field $ dockerAttr $
mempty { _dockerRunParams = [\hn -> "--"++field++"=" ++ mkval hn] } mempty { _dockerRunParams = [\hn -> "--"++field++"=" ++ mkval hn] }
dockerAttr :: DockerAttr -> Attr
dockerAttr a = mempty { _dockerattr = a }
-- | The ContainerIdent of a container is written to -- | The ContainerIdent of a container is written to
-- /.propellor-ident inside it. This can be checked to see if -- /.propellor-ident inside it. This can be checked to see if
-- the container has the same ident later. -- the container has the same ident later.

View File

@ -12,32 +12,18 @@ data Attr = Attr
, _sshPubKey :: Val String , _sshPubKey :: Val String
, _dns :: S.Set Dns.Record , _dns :: S.Set Dns.Record
, _namedconf :: Dns.NamedConfMap , _namedconf :: Dns.NamedConfMap
, _dockerattr :: DockerAttr
, _dockerImage :: Val String
, _dockerRunParams :: [HostName -> String]
} }
deriving (Eq)
instance Eq Attr where
x == y = and
[ _os x == _os y
, _dns x == _dns y
, _namedconf x == _namedconf y
, _sshPubKey x == _sshPubKey y
, _dockerImage x == _dockerImage y
, let simpl v = map (\a -> a "") (_dockerRunParams v)
in simpl x == simpl y
]
instance Monoid Attr where instance Monoid Attr where
mempty = Attr mempty mempty mempty mempty mempty mempty mempty = Attr mempty mempty mempty mempty mempty
mappend old new = Attr mappend old new = Attr
{ _os = _os old <> _os new { _os = _os old <> _os new
, _sshPubKey = _sshPubKey old <> _sshPubKey new , _sshPubKey = _sshPubKey old <> _sshPubKey new
, _dns = _dns old <> _dns new , _dns = _dns old <> _dns new
, _namedconf = _namedconf old <> _namedconf new , _namedconf = _namedconf old <> _namedconf new
, _dockerImage = _dockerImage old <> _dockerImage new , _dockerattr = _dockerattr old <> _dockerattr new
, _dockerRunParams = _dockerRunParams old <> _dockerRunParams new
} }
instance Show Attr where instance Show Attr where
@ -46,8 +32,7 @@ instance Show Attr where
, "sshPubKey " ++ show (_sshPubKey a) , "sshPubKey " ++ show (_sshPubKey a)
, "dns " ++ show (_dns a) , "dns " ++ show (_dns a)
, "namedconf " ++ show (_namedconf a) , "namedconf " ++ show (_namedconf a)
, "docker image " ++ show (_dockerImage a) , show (_dockerattr a)
, "docker run params " ++ show (map (\mk -> mk "") (_dockerRunParams a))
] ]
data Val a = Val a | NoVal data Val a = Val a | NoVal
@ -62,3 +47,28 @@ instance Monoid (Val a) where
fromVal :: Val a -> Maybe a fromVal :: Val a -> Maybe a
fromVal (Val a) = Just a fromVal (Val a) = Just a
fromVal NoVal = Nothing fromVal NoVal = Nothing
data DockerAttr = DockerAttr
{ _dockerImage :: Val String
, _dockerRunParams :: [HostName -> String]
}
instance Eq DockerAttr where
x == y = and
[ _dockerImage x == _dockerImage y
, let simpl v = map (\a -> a "") (_dockerRunParams v)
in simpl x == simpl y
]
instance Monoid DockerAttr where
mempty = DockerAttr mempty mempty
mappend old new = DockerAttr
{ _dockerImage = _dockerImage old <> _dockerImage new
, _dockerRunParams = _dockerRunParams old <> _dockerRunParams new
}
instance Show DockerAttr where
show a = unlines
[ "docker image " ++ show (_dockerImage a)
, "docker run params " ++ show (map (\mk -> mk "") (_dockerRunParams a))
]