@@ -16,6 +16,7 @@ import qualified Data.Text as T
1616import GHC.Generics (Generic)
1717import qualified Network.HTTP.Client as HTTP
1818import Network.HTTP.Types (StdMethod)
19+import Prelude hiding (all)
1920
2021type HttpVerb = StdMethod
2122
@@ -24,25 +25,33 @@ data Endpoint =
2425 | ListContainersEndpoint ListOpts
2526 | ListImagesEndpoint ListOpts
2627 | CreateContainerEndpoint
27− | StartContainerEndpoint ContainerID
28− | StopContainerEndpoint ContainerID
29− | KillContainerEndpoint ContainerID
30− | RestartContainerEndpoint ContainerID
31− | PauseContainerEndpoint ContainerName
28+ | StartContainerEndpoint StartOpts ContainerID
29+ | StopContainerEndpoint Timeout ContainerID
30+ | KillContainerEndpoint Signal ContainerID
31+ | RestartContainerEndpoint Timeout ContainerID
32+ | PauseContainerEndpoint ContainerID
3233 | UnpauseContainerEndpoint ContainerID
3334 | ContainerLogsEndpoint ContainerID LogOpts
34− | DeleteContainerEndpoint ContainerID DeleteOpts
35+ | DeleteContainerEndpoint DeleteOpts ContainerID
3536
3637type URL = Text
3738type ApiVersion = Text
3839type ContainerID = Text
3940type ImageID = Text
40−type Timeout = Integer
41+
42+data Timeout = Timeout Integer | DefaultTimeout deriving (Eq, Show)
4143
4244type Request = HTTP.Request
4345type Response = HTTP.Response BL.ByteString
4446
45−data Signal = SIGINT | SIGKILL deriving (Eq, Show)
47+data Signal = SIGHUP
48+ | SIGINT
49+ | SIGQUIT
50+ | SIGSTOP
51+ | SIGTERM
52+ | SIGUSR1
53+ | SIG Integer
54+ | SIGKILL deriving (Eq, Show)
4655
4756data DockerClientOpts = DockerClientOpts {
4857 apiVer :: ApiVersion
@@ -59,6 +68,8 @@ runDockerT (opts, h) r = runExceptT $ runReaderT r (opts, h)
5968
6069data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
6170
71+defaultListOpts = ListOpts { all=False }
72+
6273defaultClientOpts :: DockerClientOpts
6374defaultClientOpts = DockerClientOpts {
6475 apiVer = "v1.22"
@@ -85,7 +96,40 @@ instance FromJSON DockerVersion where
8596 parseJSON = genericParseJSON defaultOptions {
8697 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
8798
99+-- TODO: Add NetworkSettings
100+-- TODO: Add PortBindings
88101data 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)
113+
114+instance FromJSON Container where
115+ parseJSON (JSON.Object v) =
116+ Container <$> (v .: "Id")
117+ <*> (v .: "Names")
118+ <*> (v .: "Image")
119+ <*> (v .: "ImageID")
120+ <*> (v .: "Command")
121+ <*> (v .: "Created")
122+ <*> (v .: "Status")
123+ -- <*> (v .: "Ports")
124+ <*> (v .: "Labels")
125+ -- <*> (v .: "NetworkSettings")
126+
127+
128+
129+data Status = Created | Restarting | Running | Paused | Exited | Dead deriving (Eq, Show, Generic)
130+
131+instance FromJSON Status
132+instance ToJSON Status
89133
90134type Digest = Text
91135newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
@@ -116,7 +160,14 @@ instance FromJSON Image where
116160 fieldLabelModifier = dropImagePrefix}
117161
118162data CreateOpts = CreateOpts
119−data StartOpts = StartOpts
163+
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)
167+
168+data StartOpts = StartOpts { detachKeys :: DetachKeys } deriving (Eq, Show)
169+
170+defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
120171
121172data DeleteOpts = DeleteOpts {
122173 deleteVolumes :: Bool