fix bug in containerid parsing
This commit is contained in:
parent
1d180d6ae5
commit
2d4a0f760b
|
@ -49,7 +49,7 @@ type ContainerName = String
|
||||||
-- | A container is identified by its name, and the host
|
-- | A container is identified by its name, and the host
|
||||||
-- on which it's deployed.
|
-- on which it's deployed.
|
||||||
data ContainerId = ContainerId HostName ContainerName
|
data ContainerId = ContainerId HostName ContainerName
|
||||||
deriving (Read, Show, Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
toContainerId :: String -> Maybe ContainerId
|
toContainerId :: String -> Maybe ContainerId
|
||||||
toContainerId s = case separate (== '.') s of
|
toContainerId s = case separate (== '.') s of
|
||||||
|
@ -99,8 +99,8 @@ hasContainer hn cn findcontainer =
|
||||||
desc = "docker container " ++ fromContainerId cid
|
desc = "docker container " ++ fromContainerId cid
|
||||||
|
|
||||||
ensureContainer :: ContainerId -> Image -> [Containerized Property] -> IO Result
|
ensureContainer :: ContainerId -> Image -> [Containerized Property] -> IO Result
|
||||||
ensureContainer cid image containerprops = do
|
ensureContainer cid@(ContainerId hn cn) image containerprops = do
|
||||||
l <- listContainers Running
|
l <- listContainers RunningContainers
|
||||||
if cid `elem` l
|
if cid `elem` l
|
||||||
then do
|
then do
|
||||||
runningident <- getrunningident
|
runningident <- getrunningident
|
||||||
|
@ -112,11 +112,11 @@ ensureContainer cid image containerprops = do
|
||||||
removeContainer cid
|
removeContainer cid
|
||||||
go oldimage
|
go oldimage
|
||||||
else do
|
else do
|
||||||
whenM (elem cid <$> listContainers Stopped) $
|
whenM (elem cid <$> listContainers AllContainers) $
|
||||||
removeContainer cid
|
removeContainer cid
|
||||||
go image
|
go image
|
||||||
where
|
where
|
||||||
ident = ContainerIdent image cid runps
|
ident = ContainerIdent image hn cn runps
|
||||||
|
|
||||||
-- Start the simplesh server that will be used by propellor
|
-- Start the simplesh server that will be used by propellor
|
||||||
-- to run commands in the container. An interactive shell
|
-- to run commands in the container. An interactive shell
|
||||||
|
@ -172,7 +172,7 @@ provisionContainer cid = do
|
||||||
-- | Two containers with the same ContainerIdent were started from
|
-- | Two containers with the same ContainerIdent were started from
|
||||||
-- the same base image (possibly a different version though), and
|
-- the same base image (possibly a different version though), and
|
||||||
-- with the same RunParams.
|
-- with the same RunParams.
|
||||||
data ContainerIdent = ContainerIdent Image ContainerId [RunParam]
|
data ContainerIdent = ContainerIdent Image HostName ContainerName [RunParam]
|
||||||
deriving (Read, Show, Eq)
|
deriving (Read, Show, Eq)
|
||||||
|
|
||||||
-- | The ContainerIdent of a container is written to
|
-- | The ContainerIdent of a container is written to
|
||||||
|
@ -201,17 +201,17 @@ commitContainer cid = catchMaybeIO $
|
||||||
takeWhile (/= '\n')
|
takeWhile (/= '\n')
|
||||||
<$> readProcess dockercmd ["commit", fromContainerId cid]
|
<$> readProcess dockercmd ["commit", fromContainerId cid]
|
||||||
|
|
||||||
data ContainerStatus = Running | Stopped
|
data ContainerFilter = RunningContainers | AllContainers
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
-- | Only lists propellor managed containers.
|
-- | Only lists propellor managed containers.
|
||||||
listContainers :: ContainerStatus -> IO [ContainerId]
|
listContainers :: ContainerFilter -> IO [ContainerId]
|
||||||
listContainers status =
|
listContainers status =
|
||||||
catMaybes . map readish . catMaybes . map (lastMaybe . words) . lines
|
catMaybes . map toContainerId . catMaybes . map (lastMaybe . words) . lines
|
||||||
<$> readProcess dockercmd ps
|
<$> readProcess dockercmd ps
|
||||||
where
|
where
|
||||||
ps
|
ps
|
||||||
| status == Stopped = baseps ++ ["--all"]
|
| status == AllContainers = baseps ++ ["--all"]
|
||||||
| otherwise = baseps
|
| otherwise = baseps
|
||||||
baseps = ["ps", "--no-trunc"]
|
baseps = ["ps", "--no-trunc"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue