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
18import Network.HTTP.Types (StdMethod)
20type HttpVerb = StdMethod
24 | ListContainersEndpoint ListOpts
25 | ListImagesEndpoint ListOpts
26 | CreateContainerEndpoint
27 | StartContainerEndpoint ContainerID
28 | StopContainerEndpoint ContainerID
29 | KillContainerEndpoint ContainerID
30 | RestartContainerEndpoint ContainerID
31 | PauseContainerEndpoint ContainerName
32 | UnpauseContainerEndpoint ContainerID
33 | ContainerLogsEndpoint ContainerID LogOpts
34 | DeleteContainerEndpoint ContainerID DeleteOpts
38type ContainerID = Text
42type Request = HTTP.Request
43type Response = HTTP.Response BL.ByteString
45data Signal = SIGINT | SIGKILL deriving (Eq, Show)
47data DockerClientOpts = DockerClientOpts {
52type HttpHandler m = Request -> m Response
54type DockerT m a = ReaderT (DockerClientOpts, HttpHandler m) (ExceptT String m) a
56runDockerT :: (Monad m) => (DockerClientOpts, HttpHandler m) -> DockerT m a -> m (Either String a)
57runDockerT opts a = runExceptT $ runReaderT a opts
58-- runDockerT opts a = (runExceptT .) . flip runReaderT opts a
60data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
62defaultClientOpts :: DockerClientOpts
63defaultClientOpts = DockerClientOpts {
65 , baseUrl = "http://127.0.0.1:2375"
68data DockerVersion = DockerVersion {
70 , apiVersion :: ApiVersion
75 , kernelVersion :: Text
77 } deriving (Show, Eq, Generic)
80instance ToJSON DockerVersion where
81 toJSON = genericToJSON defaultOptions {
82 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
84instance FromJSON DockerVersion where
85 parseJSON = genericParseJSON defaultOptions {
86 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
88data Container = Container
91newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
93instance FromJSON Labels where
94 parseJSON val = Labels <$> parseJSON val
96instance ToJSON Labels where
97 toJSON (Labels kvs) = object [k .= v | (k,v) <- (M.toList kvs)]
101data Image = DockerImage {
103 , imageCreated :: Integer
104 , imageParentId :: Maybe ImageID
105 , imageRepoTags :: [Tag]
106 , imageRepoDigests :: [Digest]
107 , imageSize :: Integer
108 , imageVirtualSize :: Integer
109 , imageLabels :: Labels
110 } deriving (Show, Eq, Generic)
112dropImagePrefix = drop 5
114instance FromJSON Image where
115 parseJSON = genericParseJSON defaultOptions {
116 fieldLabelModifier = dropImagePrefix}
118data CreateOpts = CreateOpts
119data StartOpts = StartOpts
121data DeleteOpts = DeleteOpts {
122 deleteVolumes :: Bool
124 } deriving (Eq, Show)
126type Timestamp = Integer
127data TailLogOpt = Tail Integer | All deriving (Eq, Show)
129data LogOpts = LogOpts {
136 } deriving (Eq, Show)
138data VolumePermission = Rw | Ro deriving (Eq, Show, Generic)
140instance ToJSON VolumePermission
141instance FromJSON VolumePermission
143data Volume = Volume { hostSrc :: Text
144 , containerDest :: Text
145 , volumePermission :: Maybe VolumePermission
146 } deriving (Eq, Show)
148data Device = Device {
149 pathOnHost :: FilePath
150 , pathInContainer :: FilePath
151 , cgroupPermissions :: Text
152 } deriving (Eq, Show, Generic)
154instance ToJSON Device where
155 toJSON = genericToJSON defaultOptions {
156 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
158instance FromJSON Device where
159 parseJSON = genericParseJSON defaultOptions {
160 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
162type ContainerName = Text
164data VolumeFrom = VolumeFrom ContainerName VolumePermission deriving (Eq, Show)
166instance ToJSON Volume where
167 toJSON (Volume src dest mode) = toJSON $ case mode of
168 Nothing -> T.concat[src, ":", dest]
169 Just m -> T.concat[src, ":", dest, ":", (T.pack $ show m)]
171data Link = Link Text (Maybe Text) deriving (Eq, Show)
173instance ToJSON Link where
174 toJSON (Link n1 n2) = toJSON $ case n2 of
175 Nothing -> T.concat[n1, ":", n1]
176 Just n -> T.concat[n1, ":", n]
178-- { "Type": "<driver_name>", "Config": {"key1": "val1"} }
179data LogDriverType = JsonFile | Syslog | Journald | Gelf | AwsLogs | Splunk | LoggingDisabled deriving (Eq, Show)
181data LogDriverOptions = Map Text Text deriving (Eq, Show)
183data LogDriverConfig = LogDriverConfig LogDriverType (Maybe LogDriverOptions) deriving (Eq, Show)
185-- TODO: Add container:<name|id> mode
186data NetworkMode = Bridge | Host | NetworkDisabled deriving (Eq, Show)
188data PortType = TCP | UDP deriving (Eq, Show)
190newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
192-- { <port>/<protocol>: [{ "HostPort": "<port>" }] }
193data PortBinding = PortBinding {
194 containerPort :: Integer
195 , portType :: PortType
196 , hostPort :: [HostPort]
197 } deriving (Eq, Show)
199data HostPort = HostPort NetworkInterface Port deriving (Eq, Show)
201-- { "Name": "on-failure" , "MaximumRetryCount": 2}
202type RetryCount = Integer
203data RestartPolicy = RestartAlways | RestartUnlessStopped | RestartOnFailure RetryCount | RestartOff deriving (Eq, Show)
205data Isolation = Default | Process | Hyperv deriving (Eq, Show)
207newtype UTSMode = UTSMode Text deriving (Eq, Show)
209-- TODO: Add Tmpfs : List of tmpfs (mounts) used for the container
210-- TODO: Add UTSMode : UTS namespace to use for the container
211-- TODO: Sysctls map[string]string `json:",omitempty"` // List of Namespaced sysctls used for the container
212data HostConfig = HostConfig
214 , containerIDFile :: FilePath
215 , logConfig :: LogDriverConfig
216 , networkMode :: NetworkMode
217 , portBindings :: [PortBinding]
218 , restartPolicy :: RestartPolicy
219 , volumeDriver :: Text
220 , volumesFrom :: [VolumeFrom]
224 , dnsOptions :: [Text]
225 , dnsSearch :: [Text]
226 , extraHosts :: [Text]
227 , groupAdd :: [Integer]
230 , oomScoreAdj :: Integer
233 , publishAllPorts :: Bool
234 , readOnlyRootfs :: Bool
235 , securityOpt :: [Text]
236 , storageOpt :: [Text]
239 , consoleSize :: Integer
240 , isolation :: Isolation
241 , resources :: ContainerResources
242 } deriving (Eq, Show, Generic)
244-- { "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }
245-- { "Name": "nofile", "Soft": 1024, "Hard": 2048 }
246data Ulimit = Ulimit {
248 , ulimitSoft :: Integer
249 , ulimitHard :: Integer
250 } deriving (Eq, Show)
252data ContainerResources = ContainerResources {
254 , cgroupParent :: Text
255 , blkioWeight :: Text
256 , blkioWeightDevice :: Text
257 , blkioDeviceReadBps :: Text
258 , blkioDeviceWriteBps :: Text
259 , blkioDeviceReadIOps :: Text
260 , blkioDeviceWriteIOps :: Text
261 , cpuPeriod :: Integer
262 , cpuQuota :: Integer
263 , cpusetCpus :: Integer
265 , devices :: [Device]
266 , diskQuota :: Integer
267 , kernelMemory :: Integer
269 , memoryReservation :: Integer
270 , memorySwap :: Integer
271 , memorySwappiness :: Integer
272 , oomKillDisable :: Bool
273 , pidsLimit :: Integer
274 , ulimits :: [Ulimit]
275 } deriving (Eq, Show)
282data EnvVar = EnvVar Name Value deriving (Eq, Show)
284data ContainerConfig = ContainerConfig {
288 , attachStdin :: Bool
289 , attachStdout :: Bool
290 , attachStderr :: Bool
291 -- ExposedPorts are used for the PublishAllPorts flag
292 -- to know which ports to publish. Also it's used for
293 -- the deamon to know wich Environment variables to
294 -- inject into a container linking to our container.
295 -- Example linking a Postgres container named db:
296 -- DB_PORT_5432_TCP_PORT="5432"
297 -- DB_PORT_5432_TCP_PROTO="tcp"
298 -- DB_PORT_5432_TCP="tcp://172.17.0.1:5432"
299 , exposedPorts :: [Port]
300 , publishService :: Text
306 , argsEscaped :: Bool
308 , volumes :: [Volume]
309 , workingDir :: FilePath
311 , networkDisabled :: Bool
315 , stopSignal :: Signal
316 } 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