1module Docker.Types where
3import Control.Monad (mzero)
4import Control.Monad.Except (ExceptT, runExceptT)
5import Control.Monad.Reader (ReaderT, runReaderT)
6import Data.Aeson (FromJSON, ToJSON, decode, encode,
7 genericParseJSON, genericToJSON, object,
8 parseJSON, toJSON, (.:), (.=))
9import qualified Data.Aeson as JSON
10import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
11import qualified Data.ByteString.Lazy as BL
12import Data.Char (toUpper)
13import qualified Data.Map as M
14import Data.Text (Text)
15import qualified Data.Text as T
16import GHC.Generics (Generic)
17import qualified Network.HTTP.Client as HTTP
22type ContainerID = Text
26type Request = HTTP.Request
27type Response = HTTP.Response BL.ByteString
29data Signal = SIGINT | SIGKILL deriving (Eq, Show)
31data DockerClientOpts m = DockerClientOpts {
32 http :: Request -> m Response
33 , apiVer :: ApiVersion
37type DockerT m a = ReaderT (DockerClientOpts m) (ExceptT String m) a
39runDockerT :: (Monad m) => DockerClientOpts m -> DockerT m a -> m (Either String a)
40runDockerT opts a = runExceptT $ runReaderT a opts
41-- runDockerT opts a = (runExceptT .) . flip runReaderT opts a
43data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
45defaultClientOpts :: DockerClientOpts IO
46defaultClientOpts = DockerClientOpts {
49 , baseUrl = "http://127.0.0.1:2375/"
52data DockerVersion = DockerVersion {
54 , apiVersion :: ApiVersion
59 , kernelVersion :: Text
61 } deriving (Show, Eq, Generic)
64instance ToJSON DockerVersion where
65 toJSON = genericToJSON defaultOptions {
66 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
68instance FromJSON DockerVersion where
69 parseJSON = genericParseJSON defaultOptions {
70 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
72data Container = Container
75newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
77instance FromJSON Labels where
78 parseJSON val = Labels <$> parseJSON val
80instance ToJSON Labels where
81 toJSON (Labels kvs) = object [k .= v | (k,v) <- (M.toList kvs)]
85data Image = DockerImage {
87 , imageCreated :: Integer
88 , imageParentId :: Maybe ImageID
89 , imageRepoTags :: [Tag]
90 , imageRepoDigests :: [Digest]
91 , imageSize :: Integer
92 , imageVirtualSize :: Integer
93 , imageLabels :: Labels
94 } deriving (Show, Eq, Generic)
96dropImagePrefix = drop 5
98instance FromJSON Image where
99 parseJSON = genericParseJSON defaultOptions {
100 fieldLabelModifier = dropImagePrefix}
102data CreateOpts = CreateOpts
103data StartOpts = StartOpts
105data DeleteOpts = DeleteOpts {
106 deleteVolumes :: Bool
108 } deriving (Eq, Show)
110type Timestamp = Integer
111data TailLogOpt = Tail Integer | All deriving (Eq, Show)
113data LogOpts = LogOpts {
120 } deriving (Eq, Show)
122data VolumePermission = Rw | Ro deriving (Eq, Show, Generic)
124instance ToJSON VolumePermission
125instance FromJSON VolumePermission
127data Volume = Volume { hostSrc :: Text
128 , containerDest :: Text
129 , volumePermission :: Maybe VolumePermission
130 } deriving (Eq, Show)
132type ContainerName = Text
134data VolumeFrom = VolumeFrom ContainerName VolumePermission deriving (Eq, Show)
136instance ToJSON Volume where
137 toJSON (Volume src dest mode) = toJSON $ case mode of
138 Nothing -> T.concat[src, ":", dest]
139 Just m -> T.concat[src, ":", dest, ":", (T.pack $ show m)]
141data Link = Link Text (Maybe Text) deriving (Eq, Show)
143instance ToJSON Link where
144 toJSON (Link n1 n2) = toJSON $ case n2 of
145 Nothing -> T.concat[n1, ":", n1]
146 Just n -> T.concat[n1, ":", n]
148-- { "Type": "<driver_name>", "Config": {"key1": "val1"} }
149data LogDriverType = JsonFile | Syslog | Journald | Gelf | AwsLogs | Splunk | LoggingDisabled deriving (Eq, Show)
151data LogDriverOptions = Map Text Text deriving (Eq, Show)
153data LogDriverConfig = LogDriverConfig LogDriverType (Maybe LogDriverOptions) deriving (Eq, Show)
155-- TODO: Add container:<name|id> mode
156data NetworkMode = Bridge | Host | NetworkDisabled deriving (Eq, Show)
158data PortType = TCP | UDP deriving (Eq, Show)
160newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
162-- { <port>/<protocol>: [{ "HostPort": "<port>" }] }
163data PortBinding = PortBinding {
164 containerPort :: Integer
165 , portType :: PortType
166 , hostPort :: [HostPort]
167 } deriving (Eq, Show)
169data HostPort = HostPort NetworkInterface Port deriving (Eq, Show)
171-- { "Name": "on-failure" , "MaximumRetryCount": 2}
172type RetryCount = Integer
173data RestartPolicy = RestartAlways | RestartUnlessStopped | RestartOnFailure RetryCount | RestartOff deriving (Eq, Show)
175data Isolation = Default | Process | Hyperv deriving (Eq, Show)
177newtype UTSMode = UTSMode Text deriving (Eq, Show)
179-- TODO: Add Tmpfs : List of tmpfs (mounts) used for the container
180-- TODO: Add UTSMode : UTS namespace to use for the container
181data HostConfig = HostConfig
183 , containerIDFile :: FilePath
184 , logConfig :: LogDriverConfig
185 , networkMode :: NetworkMode
186 , portBindings :: [PortBinding]
187 , restartPolicy :: RestartPolicy
188 , volumeDriver :: Text
189 , volumesFrom :: [VolumeFrom]
193 , dnsOptions :: [Text]
194 , dnsSearch :: [Text]
195 , extraHosts :: [Text]
196 , groupAdd :: [Integer]
199 , oomScoreAdj :: Integer
202 , publishAllPorts :: Bool
203 , readOnlyRootfs :: Bool
204 , securityOpt :: [Text]
205 , storageOpt :: [Text]
208 , consoleSize :: Integer
209 , isolation :: Isolation
210 , resources :: ContainerResources
211 } deriving (Eq, Show, Generic)
213-- { "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }
214-- { "Name": "nofile", "Soft": 1024, "Hard": 2048 }
215data Ulimit = Ulimit {
217 , ulimitSoft :: Integer
218 , ulimitHard :: Integer
219 } deriving (Eq, Show)
221data ContainerResources = ContainerResources {
223 , cgroupParent :: Text
224 , blkioWeight :: Text
225 , blkioWeightDevice :: Text
226 , blkioDeviceReadBps :: Text
227 , blkioDeviceWriteBps :: Text
228 , blkioDeviceReadIOps :: Text
229 , blkioDeviceWriteIOps :: Text
230 , cpuPeriod :: Integer
231 , cpuQuota :: Integer
232 , cpusetCpus :: Integer
234 , devices :: [Volume]
235 , diskQuota :: Integer
236 , kernelMemory :: Integer
238 , memoryReservation :: Integer
239 , memorySwap :: Integer
240 , memorySwappiness :: Integer
241 , oomKillDisable :: Bool
242 , pidsLimit :: Integer
243 , ulimits :: [Ulimit]
244 } deriving (Eq, Show)
251data EnvVar = EnvVar Name Value deriving (Eq, Show)
253data ContainerConfig = ContainerConfig {
257 , attachStdin :: Bool
258 , attachStdout :: Bool
259 , attachStderr :: Bool
260 , exposedPorts :: [Port]
261 , publishService :: Text
267 , argsEscaped :: Bool
269 , volumes :: [Volume]
270 , workingDir :: FilePath
272 , networkDisabled :: Bool
276 , stopSignal :: Signal
277 } deriving (Eq, Show)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list