on master help sign in
Moar types
2bf4a5cDeni Bertovic
src/Docker/Types.hs+168−4
@@ -3,9 +3,10 @@ module Docker.Types where
3import Control.Monad (mzero)
3import Control.Monad (mzero)
4import Control.Monad.Except (ExceptT, runExceptT)
4import Control.Monad.Except (ExceptT, runExceptT)
5import Control.Monad.Reader (ReaderT, runReaderT)
5import Control.Monad.Reader (ReaderT, runReaderT)
6−import Data.Aeson (FromJSON, ToJSON, encode,
6+import Data.Aeson (FromJSON, ToJSON, decode, encode,
7 genericParseJSON, genericToJSON, object,
7 genericParseJSON, genericToJSON, object,
8 parseJSON, toJSON, (.:), (.=))
8 parseJSON, toJSON, (.:), (.=))
9+import qualified Data.Aeson as JSON
9import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
10import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
10import qualified Data.ByteString.Lazy as BL
11import qualified Data.ByteString.Lazy as BL
11import Data.Char (toUpper)
12import Data.Char (toUpper)
@@ -71,9 +72,7 @@ instance FromJSON DockerVersion where
71data Container = Container
72data Container = Container
72
73
73type Digest = Text
74type Digest = Text
74−type Tag = Text
75−
76−newtype Labels = Labels (M.Map Text Text) deriving (Eq, Show)
75+newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
77
76
78instance FromJSON Labels where
77instance FromJSON Labels where
79 parseJSON val = Labels <$> parseJSON val
78 parseJSON val = Labels <$> parseJSON val
@@ -81,6 +80,8 @@ instance FromJSON Labels where
81instance ToJSON Labels where
80instance ToJSON Labels where
82 toJSON (Labels kvs) = object [k .= v | (k,v) <- (M.toList kvs)]
81 toJSON (Labels kvs) = object [k .= v | (k,v) <- (M.toList kvs)]
83
82
83+type Tag = Text
84+
84data Image = DockerImage {
85data Image = DockerImage {
85 imageId :: ImageID
86 imageId :: ImageID
86 , imageCreated :: Integer
87 , imageCreated :: Integer
@@ -118,3 +119,166 @@ data LogOpts = LogOpts {
118 , tail :: TailLogOpt
119 , tail :: TailLogOpt
119 } deriving (Eq, Show)
120 } deriving (Eq, Show)
120
121
122+data BindMountMode = Rw | Ro deriving (Eq, Show, Generic)
123+
124+instance ToJSON BindMountMode
125+instance FromJSON BindMountMode
126+
127+data BindMount = BindMount {
128+ hostSrc :: Text
129+ , containerDest :: Text
130+ , mountMode :: Maybe BindMountMode
131+ } deriving (Eq, Show)
132+
133+data Volume = Volume {
134+ containerName :: Text
135+ , volumeMode :: Maybe BindMountMode
136+ } deriving (Eq, Show)
137+
138+-- BindMount "/tmp" "/tmp2" (Just Rw)
139+-- instance FromJSON BindMount where
140+-- parseJSON (JSON.Object v) = TODO
141+
142+
143+instance ToJSON BindMount where
144+ toJSON (BindMount s d mode) = toJSON $ case mode of
145+ Nothing -> T.concat[s, ":", d]
146+ Just m -> T.concat[s, ":", d, ":", (T.pack $ show m)]
147+
148+data Link = Link Text (Maybe Text) deriving (Eq, Show)
149+
150+instance ToJSON Link where
151+ toJSON (Link n1 n2) = toJSON $ case n2 of
152+ Nothing -> T.concat[n1, ":", n1]
153+ Just n -> T.concat[n1, ":", n]
154+
155+-- { "Type": "<driver_name>", "Config": {"key1": "val1"} }
156+data LogDriverType = JsonFile | Syslog | Journald | Gelf | AwsLogs | Splunk | LoggingDisabled deriving (Eq, Show)
157+
158+data LogDriverOptions = Map Text Text deriving (Eq, Show)
159+
160+data LogDriverConfig = LogDriverConfig LogDriverType (Maybe LogDriverOptions) deriving (Eq, Show)
161+
162+-- TODO: Add container:<name|id> mode
163+data NetworkMode = Bridge | Host | NetworkDisabled deriving (Eq, Show)
164+
165+data PortType = TCP | UDP deriving (Eq, Show)
166+
167+newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
168+
169+-- { <port>/<protocol>: [{ "HostPort": "<port>" }] }
170+data PortBinding = PortBinding {
171+ containerPort :: Integer
172+ , portType :: PortType
173+ , hostPort :: [HostPort]
174+ } deriving (Eq, Show)
175+
176+data HostPort = HostPort NetworkInterface Port deriving (Eq, Show)
177+
178+-- { "Name": "on-failure" , "MaximumRetryCount": 2}
179+type RetryCount = Integer
180+data RestartPolicy = RestartAlways | RestartUnlessStopped | RestartOnFailure RetryCount | RestartOff deriving (Eq, Show)
181+
182+data Isolation = Default | Process | Hyperv deriving (Eq, Show)
183+
184+newtype UTSMode = UTSMode Text deriving (Eq, Show)
185+
186+-- TODO: Add Tmpfs : List of tmpfs (mounts) used for the container
187+-- TODO: Add UTSMode : UTS namespace to use for the container
188+data HostConfig = HostConfig
189+ { binds :: [BindMount]
190+ , containerIDFile :: FilePath
191+ , logConfig :: LogDriverConfig
192+ , networkMode :: NetworkMode
193+ , portBindings :: [PortBinding]
194+ , restartPolicy :: RestartPolicy
195+ , volumeDriver :: Text
196+ , volumesFrom :: Volume
197+ , capAdd :: [Text]
198+ , capDrop :: [Text]
199+ , dns :: [Text]
200+ , dnsOptions :: [Text]
201+ , dnsSearch :: [Text]
202+ , extraHosts :: [Text]
203+ , groupAdd :: [Integer]
204+ , ipcMode :: Text
205+ , links :: [Link]
206+ , oomScoreAdj :: Integer
207+ , pidMode :: Text
208+ , privileged :: Bool
209+ , publishAllPorts :: Bool
210+ , readOnlyRootfs :: Bool
211+ , securityOpt :: [Text]
212+ , storageOpt :: [Text]
213+ , utsMode :: UTSMode
214+ , shmSize :: Integer
215+ , consoleSize :: Integer
216+ , isolation :: Isolation
217+ , resources :: ContainerResources
218+ } deriving (Eq, Show, Generic)
219+
220+-- { "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }
221+-- { "Name": "nofile", "Soft": 1024, "Hard": 2048 }
222+data Ulimit = Ulimit {
223+ ulimitName :: Text
224+ , ulimitSoft :: Integer
225+ , ulimitHard :: Integer
226+ } deriving (Eq, Show)
227+
228+data ContainerResources = ContainerResources {
229+ cpuShares :: Integer
230+ , cgroupParent :: Text
231+ , blkioWeight :: Text
232+ , blkioWeightDevice :: Text
233+ , blkioDeviceReadBps :: Text
234+ , blkioDeviceWriteBps :: Text
235+ , blkioDeviceReadIOps :: Text
236+ , blkioDeviceWriteIOps :: Text
237+ , cpuPeriod :: Integer
238+ , cpuQuota :: Integer
239+ , cpusetCpus :: Integer
240+ , cpusetMems :: Text
241+ , devices :: [BindMount]
242+ , diskQuota :: Integer
243+ , kernelMemory :: Integer
244+ , memory :: Integer
245+ , memoryReservation :: Integer
246+ , memorySwap :: Integer
247+ , memorySwappiness :: Integer
248+ , oomKillDisable :: Bool
249+ , pidsLimit :: Integer
250+ , ulimits :: [Ulimit]
251+ } deriving (Eq, Show)
252+
253+type Port = Integer
254+
255+type Name = Text
256+type Value = Text
257+
258+data EnvVar = EnvVar Name Value deriving (Eq, Show)
259+
260+data ContainerConfig = ContainerConfig {
261+ hostname :: Text
262+ , domainname :: Text
263+ , user :: Text
264+ , attachStdin :: Bool
265+ , attachStdout :: Bool
266+ , attachStderr :: Bool
267+ , exposedPorts :: [Port]
268+ , publishService :: Text
269+ , tty :: Bool
270+ , openStdin :: Bool
271+ , stdinOnce :: Bool
272+ , env :: [EnvVar]
273+ , cmd :: Text
274+ , argsEscaped :: Bool
275+ , image :: Text
276+ , volumes :: [BindMount]
277+ , workingDir :: FilePath
278+ , entrypoint :: Text
279+ , networkDisabled :: Bool
280+ , macAddress :: Text
281+ , onBuild :: Text
282+ , labels :: Labels
283+ , stopSignal :: Signal
284+ } deriving (Eq, Show)