@@ -16,6 +16,7 @@ import qualified Data.Text as T
16import GHC.Generics (Generic)
16import GHC.Generics (Generic)
17import qualified Network.HTTP.Client as HTTP
17import qualified Network.HTTP.Client as HTTP
18import Network.HTTP.Types (StdMethod)
18import Network.HTTP.Types (StdMethod)
19+import Prelude hiding (all)
20type HttpVerb = StdMethod
21type HttpVerb = StdMethod
@@ -24,25 +25,33 @@ data Endpoint =
24 | ListContainersEndpoint ListOpts
25 | ListContainersEndpoint ListOpts
25 | ListImagesEndpoint ListOpts
26 | ListImagesEndpoint ListOpts
26 | CreateContainerEndpoint
27 | CreateContainerEndpoint
27− | StartContainerEndpoint ContainerID
28+ | StartContainerEndpoint StartOpts ContainerID
28− | StopContainerEndpoint ContainerID
29+ | StopContainerEndpoint Timeout ContainerID
29− | KillContainerEndpoint ContainerID
30+ | KillContainerEndpoint Signal ContainerID
30− | RestartContainerEndpoint ContainerID
31+ | RestartContainerEndpoint Timeout ContainerID
31− | PauseContainerEndpoint ContainerName
32+ | PauseContainerEndpoint ContainerID
32 | UnpauseContainerEndpoint ContainerID
33 | UnpauseContainerEndpoint ContainerID
33 | ContainerLogsEndpoint ContainerID LogOpts
34 | ContainerLogsEndpoint ContainerID LogOpts
34− | DeleteContainerEndpoint ContainerID DeleteOpts
35+ | DeleteContainerEndpoint DeleteOpts ContainerID
36type URL = Text
37type URL = Text
37type ApiVersion = Text
38type ApiVersion = Text
38type ContainerID = Text
39type ContainerID = Text
39type ImageID = Text
40type ImageID = Text
40−type Timeout = Integer
41+
42+data Timeout = Timeout Integer | DefaultTimeout deriving (Eq, Show)
42type Request = HTTP.Request
44type Request = HTTP.Request
43type Response = HTTP.Response BL.ByteString
45type Response = HTTP.Response BL.ByteString
45−data Signal = SIGINT | SIGKILL deriving (Eq, Show)
54+ | SIGKILL deriving (Eq, Show)
47data DockerClientOpts = DockerClientOpts {
56data DockerClientOpts = DockerClientOpts {
48 apiVer :: ApiVersion
57 apiVer :: ApiVersion
@@ -59,6 +68,8 @@ runDockerT (opts, h) r = runExceptT $ runReaderT r (opts, h)
60data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
69data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
71+defaultListOpts = ListOpts { all=False }
62defaultClientOpts :: DockerClientOpts
73defaultClientOpts :: DockerClientOpts
63defaultClientOpts = DockerClientOpts {
74defaultClientOpts = DockerClientOpts {
64 apiVer = "v1.22"
75 apiVer = "v1.22"
@@ -85,7 +96,40 @@ instance FromJSON DockerVersion where
85 parseJSON = genericParseJSON defaultOptions {
96 parseJSON = genericParseJSON defaultOptions {
86 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
97 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
99+-- TODO: Add NetworkSettings
100+-- TODO: Add PortBindings
88data Container = Container
101data Container = Container
102+ { containerId :: ContainerID
103+ , containerNames :: [Text]
104+ , containerImageName :: Text
105+ , containerImageId :: ImageID
106+ , containerCommand :: Text
107+ , containerCreatedAt :: Int
108+ , containerStatus :: Text
109+ -- , containerPorts :: Text
110+ , containerLabels :: Labels
111+ -- , containerNetworkSettings :: Text
112+ } deriving (Show, Eq)
114+instance FromJSON Container where
115+ parseJSON (JSON.Object v) =
116+ Container <$> (v .: "Id")
119+ <*> (v .: "ImageID")
120+ <*> (v .: "Command")
121+ <*> (v .: "Created")
123+ -- <*> (v .: "Ports")
125+ -- <*> (v .: "NetworkSettings")
129+data Status = Created | Restarting | Running | Paused | Exited | Dead deriving (Eq, Show, Generic)
131+instance FromJSON Status
132+instance ToJSON Status
90type Digest = Text
134type Digest = Text
91newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
135newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
@@ -116,7 +160,14 @@ instance FromJSON Image where
116 fieldLabelModifier = dropImagePrefix}
160 fieldLabelModifier = dropImagePrefix}
118data CreateOpts = CreateOpts
162data CreateOpts = CreateOpts
164+-- detachKeys – Override the key sequence for detaching a container.
165+-- Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
166+data DetachKeys = WithCtrl Char | WithoutCtrl Char | DefaultDetachKey deriving (Eq, Show)
119−data StartOpts = StartOpts
168+data StartOpts = StartOpts { detachKeys :: DetachKeys } deriving (Eq, Show)
170+defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
121data DeleteOpts = DeleteOpts {
172data DeleteOpts = DeleteOpts {
122 deleteVolumes :: Bool
173 deleteVolumes :: Bool