summaryrefslogtreecommitdiff
path: root/Propellor
diff options
context:
space:
mode:
authorJoey Hess2014-04-01 20:47:25 -0400
committerJoey Hess2014-04-01 20:47:25 -0400
commite08accb35adef35abf3fa45d4baa9a799321506f (patch)
tree120b292682aca47e20590a6f8ba7d40c3d5ee617 /Propellor
parent1f314984b5f2f9d9a082bc20e825e2e8c8a273d7 (diff)
nicer parameters when run inside docker
Diffstat (limited to 'Propellor')
-rw-r--r--Propellor/CmdLine.hs3
-rw-r--r--Propellor/Property/Docker.hs31
-rw-r--r--Propellor/Types.hs2
3 files changed, 23 insertions, 13 deletions
diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs
index 626828aa..c267e7d4 100644
--- a/Propellor/CmdLine.hs
+++ b/Propellor/CmdLine.hs
@@ -39,6 +39,7 @@ processCmdLine = go =<< getArgs
Just cmdline -> return $ Continue cmdline
Nothing -> errorMessage "--continue serialization failure"
go ("--chain":h:[]) = return $ Chain h
+ go ("--docker":h:[]) = return $ Docker h
go (h:[])
| "--" `isPrefixOf` h = usage
| otherwise = return $ Run h
@@ -62,7 +63,7 @@ defaultMain getprops = do
go _ (Chain host) = withprops host $ \ps -> do
r <- ensureProperties' ps
putStrLn $ "\n" ++ show r
- go _ (ChainDocker host) = Docker.chain host
+ go _ (Docker host) = Docker.chain host
go True cmdline@(Spin _) = buildFirst cmdline $ go False cmdline
go True cmdline = updateFirst cmdline $ go False cmdline
go False (Spin host) = withprops host $ const $ spin host
diff --git a/Propellor/Property/Docker.hs b/Propellor/Property/Docker.hs
index a18155ed..c91771c4 100644
--- a/Propellor/Property/Docker.hs
+++ b/Propellor/Property/Docker.hs
@@ -64,7 +64,7 @@ type ContainerName = String
-- | A container is identified by its name, and the host
-- on which it's deployed.
data ContainerId = ContainerId HostName ContainerName
- deriving (Eq)
+ deriving (Eq, Read, Show)
toContainerId :: String -> Maybe ContainerId
toContainerId s = case separate (== '.') s of
@@ -123,7 +123,7 @@ runningContainer cid@(ContainerId hn cn) image containerprops = containerDesc ci
if cid `elem` l
then do
runningident <- getrunningident
- if ident2id <$> runningident == Just (ident2id ident)
+ if (ident2id <$> runningident) == Just (ident2id ident)
then return NoChange
else do
void $ stopContainer cid
@@ -149,12 +149,15 @@ runningContainer cid@(ContainerId hn cn) image containerprops = containerDesc ci
, name (fromContainerId cid)
]
- chaincmd = [localdir </> "propellor", "--continue", show $ ChainDocker $ show ident]
+ chaincmd = [localdir </> "propellor", "--docker", show cid]
- go img = ifM (runContainer img (runps ++ ["-i", "-d", "-t"]) chaincmd)
- ( return MadeChange
- , return FailedChange
- )
+ go img = do
+ createDirectoryIfMissing True (takeDirectory $ identFile cid)
+ writeFile (identFile cid) (show ident)
+ ifM (runContainer img (runps ++ ["-i", "-d", "-t"]) chaincmd)
+ ( return MadeChange
+ , return FailedChange
+ )
-- | Two containers with the same ContainerIdent were started from
-- the same base image (possibly a different version though), and
@@ -175,8 +178,15 @@ propellorIdent = "/.propellor-ident"
namedPipe :: ContainerId -> FilePath
namedPipe cid = "docker/" ++ fromContainerId cid
+identFile :: ContainerId -> FilePath
+identFile cid = "docker/" ++ fromContainerId cid ++ ".ident"
+
+readIdentFile :: ContainerId -> IO ContainerIdent
+readIdentFile cid = fromMaybe (error "bad ident in identFile")
+ . readish <$> readFile (identFile cid)
+
-- | Called when propellor is running inside a docker container.
--- The string should be the container's ContainerIdent.
+-- The string should be the container's ContainerId.
--
-- Fork a thread to run the SimpleSh server in the background.
-- In the foreground, run an interactive bash (or sh) shell,
@@ -184,10 +194,9 @@ namedPipe cid = "docker/" ++ fromContainerId cid
chain :: String -> IO ()
chain s = case readish s of
Nothing -> error $ "Invalid ContainerId: " ++ s
- Just ident@(ContainerIdent _image hn cn _rp) -> do
+ Just cid -> do
changeWorkingDirectory localdir
- let cid = ContainerId hn cn
- writeFile propellorIdent (show ident)
+ writeFile propellorIdent . show =<< readIdentFile cid
void $ async $ simpleSh $ namedPipe cid
forever $ do
void $ ifM (inPath "bash")
diff --git a/Propellor/Types.hs b/Propellor/Types.hs
index 4d8af2c9..c18cc7b7 100644
--- a/Propellor/Types.hs
+++ b/Propellor/Types.hs
@@ -64,7 +64,7 @@ data CmdLine
| AddKey String
| Continue CmdLine
| Chain HostName
- | ChainDocker HostName
+ | Docker HostName
deriving (Read, Show, Eq)
-- | Note that removing or changing field names will break the