summaryrefslogtreecommitdiff
path: root/Propellor/Property
diff options
context:
space:
mode:
authorJoey Hess2014-04-08 01:10:54 -0400
committerJoey Hess2014-04-08 01:41:51 -0400
commit1d07360f74a06436f669a992e5ca589f07106c4e (patch)
tree8d775529a636d6dff97191dfdb6e70a054d715a8 /Propellor/Property
parent4f8e8077e00ea8c1d0bda199261a0239eed36959 (diff)
adding support for linked containers
Diffstat (limited to 'Propellor/Property')
-rw-r--r--Propellor/Property/Docker.hs29
1 files changed, 22 insertions, 7 deletions
diff --git a/Propellor/Property/Docker.hs b/Propellor/Property/Docker.hs
index 50a816d1..cc6f83c4 100644
--- a/Propellor/Property/Docker.hs
+++ b/Propellor/Property/Docker.hs
@@ -117,7 +117,7 @@ containerProperties findcontainer = \h -> case toContainerId h of
-- container.
data Container = Container Image [Containerized Property]
-data Containerized a = Containerized [RunParam] a
+data Containerized a = Containerized [HostName -> RunParam] a
-- | Parameters to pass to `docker run` when creating a container.
type RunParam = String
@@ -171,6 +171,15 @@ workdir = runProp "workdir"
memory :: String -> Containerized Property
memory = runProp "memory"
+-- | Link with another container on the same host.
+link :: ContainerName -> ContainerAlias -> Containerized Property
+link linkwith alias = genProp "link" $ \hn ->
+ fromContainerId (ContainerId hn linkwith) ++ ":" ++ alias
+
+-- | A short alias for a linked container.
+-- Each container has its own alias namespace.
+type ContainerAlias = String
+
-- | A container is identified by its name, and the host
-- on which it's deployed.
data ContainerId = ContainerId HostName ContainerName
@@ -182,10 +191,10 @@ data ContainerId = ContainerId HostName ContainerName
data ContainerIdent = ContainerIdent Image HostName ContainerName [RunParam]
deriving (Read, Show, Eq)
-getRunParams :: [Containerized a] -> [RunParam]
-getRunParams l = concatMap get l
+getRunParams :: HostName -> [Containerized a] -> [RunParam]
+getRunParams hn l = concatMap get l
where
- get (Containerized ps _) = ps
+ get (Containerized ps _) = map (\a -> a hn ) ps
fromContainerized :: forall a. [Containerized a] -> [a]
fromContainerized l = map get l
@@ -254,7 +263,7 @@ runningContainer cid@(ContainerId hn cn) image containerprops = containerDesc ci
extractident :: [Resp] -> Maybe ContainerIdent
extractident = headMaybe . catMaybes . map readish . catMaybes . map getStdout
- runps = getRunParams $ containerprops ++
+ runps = getRunParams hn $ containerprops ++
-- expose propellor directory inside the container
[ volume (localdir++":"++localdir)
-- name the container in a predictable way so we
@@ -404,11 +413,17 @@ listImages :: IO [Image]
listImages = lines <$> readProcess dockercmd ["images", "--all", "--quiet"]
runProp :: String -> RunParam -> Containerized Property
-runProp field val =
- Containerized ["--" ++ param] (Property (param) (return NoChange))
+runProp field val = Containerized
+ [\_ -> "--" ++ param]
+ (Property (param) (return NoChange))
where
param = field++"="++val
+genProp :: String -> (HostName -> RunParam) -> Containerized Property
+genProp field mkval = Containerized
+ [\h -> "--" ++ field ++ "=" ++ mkval h]
+ (Property field (return NoChange))
+
-- | The ContainerIdent of a container is written to
-- /.propellor-ident inside it. This can be checked to see if
-- the container has the same ident later.