From f9258ad68a780b34189755f798f663926627f69a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 13:04:07 -0400 Subject: propellor spin --- config-joey.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/config-joey.hs b/config-joey.hs index 2e0a757e..a7475edf 100644 --- a/config-joey.hs +++ b/config-joey.hs @@ -53,6 +53,7 @@ darkstar = host "darkstar.kitenet.net" & Apt.buildDep ["git-annex"] `period` Daily & Docker.configured ! Docker.docked hosts "android-git-annex" + & Docker.docked hosts "webserver" clam :: Host clam = standardSystem "clam.kitenet.net" Unstable "amd64" -- cgit v1.2.3 From ff9647cf9de929b69727fde1e5370d2a483950f0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 13:21:42 -0400 Subject: propellor spin --- src/Propellor/Property/Docker.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs index f441197e..e5c26f6d 100644 --- a/src/Propellor/Property/Docker.hs +++ b/src/Propellor/Property/Docker.hs @@ -333,6 +333,7 @@ runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ prope restartcontainer = do oldimage <- liftIO $ fromMaybe image <$> commitContainer cid + liftIO $ print ("restarting", oldimage) void $ liftIO $ removeContainer cid go oldimage -- cgit v1.2.3 From 6ea324c613c5f1f4ddb1a5894be16eca4b39adb8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 13:24:31 -0400 Subject: propellor spin --- config-joey.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/config-joey.hs b/config-joey.hs index a7475edf..541d553c 100644 --- a/config-joey.hs +++ b/config-joey.hs @@ -363,7 +363,6 @@ standardContainer :: Docker.ContainerName -> DebianSuite -> Architecture -> Host standardContainer name suite arch = Docker.container name (dockerImage system) & os system & Apt.stdSourcesList `onChange` Apt.upgrade - & Apt.installed ["systemd"] & Apt.unattendedUpgrades & Apt.cacheCleaned & Docker.tweaked -- cgit v1.2.3 From c120355272a057c0e1f3dee420b479b56fb07fe9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 13:25:30 -0400 Subject: propellor spin --- src/Propellor/Property/Docker.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs index e5c26f6d..65b65f5e 100644 --- a/src/Propellor/Property/Docker.hs +++ b/src/Propellor/Property/Docker.hs @@ -322,6 +322,7 @@ runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ prope if runningident == Just ident then noChange else do + liftIO $ print ("runningident", runningident, "vs", ident) void $ liftIO $ stopContainer cid restartcontainer else ifM (liftIO $ elem cid <$> listContainers AllContainers) -- cgit v1.2.3 -- cgit v1.2.3 From df0c0e56cb60c7b00c1d1e715b990a9a1ca655ed Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 13:45:43 -0400 Subject: Docker: Avoid committing container every time it's started up. This was using a lot of disk space. Instead, start the container, and then use the running container to check if docker is running it with the right params. In the unlikely case that the params have changed, we still need to commit the container and restart it. The common case of eg a reboot no longer commits though. --- debian/changelog | 1 + src/Propellor/Property/Docker.hs | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2df7a57f..012826bd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ propellor (0.9.0) unstable; urgency=medium immediate upgrades to the next stable release. * debCdn switched from cdn.debian.net to http.debian.net, which seems to be better managed now. + * Docker: Avoid committing container every time it's started up. -- Joey Hess Fri, 10 Oct 2014 11:37:45 -0400 diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs index 65b65f5e..65a4a258 100644 --- a/src/Propellor/Property/Docker.hs +++ b/src/Propellor/Property/Docker.hs @@ -314,27 +314,33 @@ runningContainer :: ContainerId -> Image -> [RunParam] -> Property runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ property "running" $ do l <- liftIO $ listContainers RunningContainers if cid `elem` l - then do - -- Check if the ident has changed; if so the - -- parameters of the container differ and it must - -- be restarted. - runningident <- liftIO $ getrunningident - if runningident == Just ident - then noChange - else do - liftIO $ print ("runningident", runningident, "vs", ident) - void $ liftIO $ stopContainer cid - restartcontainer + then checkident else ifM (liftIO $ elem cid <$> listContainers AllContainers) - ( restartcontainer + ( do + -- The container exists, but is not + -- running. Its parameters may have + -- changed, but we cannot tell without + -- starting it up first. + void $ liftIO $ startContainer cid + checkident , go image ) where ident = ContainerIdent image hn cn runps + -- Check if the ident has changed; if so the + -- parameters of the container differ and it must + -- be restarted. + checkident = do + runningident <- liftIO $ getrunningident + if runningident == Just ident + then noChange + else do + void $ liftIO $ stopContainer cid + restartcontainer + restartcontainer = do oldimage <- liftIO $ fromMaybe image <$> commitContainer cid - liftIO $ print ("restarting", oldimage) void $ liftIO $ removeContainer cid go oldimage @@ -435,6 +441,9 @@ provisionContainer cid = containerDesc cid $ property "provisioned" $ liftIO $ d stopContainer :: ContainerId -> IO Bool stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ] +startContainer :: ContainerId -> IO Bool +startContainer cid = boolSystem dockercmd [Param "start", Param $ fromContainerId cid ] + stoppedContainer :: ContainerId -> Property stoppedContainer cid = containerDesc cid $ property desc $ ifM (liftIO $ elem cid <$> listContainers RunningContainers) -- cgit v1.2.3 -- cgit v1.2.3 -- cgit v1.2.3 From 2be1255b894b309c623532bad08338cff0064e64 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 13:51:52 -0400 Subject: propellor spin --- src/Propellor/Property/Docker.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs index 65a4a258..8c2f3701 100644 --- a/src/Propellor/Property/Docker.hs +++ b/src/Propellor/Property/Docker.hs @@ -314,7 +314,7 @@ runningContainer :: ContainerId -> Image -> [RunParam] -> Property runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ property "running" $ do l <- liftIO $ listContainers RunningContainers if cid `elem` l - then checkident + then checkident =<< liftIO (getrunningident simpleShClient) else ifM (liftIO $ elem cid <$> listContainers AllContainers) ( do -- The container exists, but is not @@ -322,7 +322,10 @@ runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ prope -- changed, but we cannot tell without -- starting it up first. void $ liftIO $ startContainer cid - checkident + -- It can take a while for the container to + -- start up enough to get its ident, so + -- retry for up to 60 seconds. + checkident =<< liftIO (getrunningident (simpleShClientRetry 60)) , go image ) where @@ -331,21 +334,18 @@ runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ prope -- Check if the ident has changed; if so the -- parameters of the container differ and it must -- be restarted. - checkident = do - runningident <- liftIO $ getrunningident - if runningident == Just ident - then noChange - else do - void $ liftIO $ stopContainer cid - restartcontainer + checkident runningident + | runningident == Just ident = noChange + | otherwise = do + void $ liftIO $ stopContainer cid + restartcontainer restartcontainer = do oldimage <- liftIO $ fromMaybe image <$> commitContainer cid void $ liftIO $ removeContainer cid go oldimage - getrunningident :: IO (Maybe ContainerIdent) - getrunningident = simpleShClient (namedPipe cid) "cat" [propellorIdent] $ \rs -> do + getrunningident shclient = shclient (namedPipe cid) "cat" [propellorIdent] $ \rs -> do let !v = extractident rs return v -- cgit v1.2.3 -- cgit v1.2.3 -- cgit v1.2.3 From 4182cae2351e1251bdb22eeb63a4402bc51cc2de Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Oct 2014 14:22:31 -0400 Subject: propellor spin --- config-joey.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-joey.hs b/config-joey.hs index 541d553c..3bf01114 100644 --- a/config-joey.hs +++ b/config-joey.hs @@ -53,7 +53,7 @@ darkstar = host "darkstar.kitenet.net" & Apt.buildDep ["git-annex"] `period` Daily & Docker.configured ! Docker.docked hosts "android-git-annex" - & Docker.docked hosts "webserver" + ! Docker.docked hosts "webserver" clam :: Host clam = standardSystem "clam.kitenet.net" Unstable "amd64" -- cgit v1.2.3