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
21 | ListContainersEndpoint ListOpts
22 | ListImagesEndpoint ListOpts
23 | CreateContainerEndpoint
24 | StartContainerEndpoint ContainerID
25 | StopContainerEndpoint ContainerID
26 | KillContainerEndpoint ContainerID
27 | RestartContainerEndpoint ContainerID
28 | PauseContainerEndpoint ContainerName
29 | UnpauseContainerEndpoint ContainerID
30 | ContainerLogsEndpoint ContainerID LogOpts
31 | DeleteContainerEndpoint ContainerID DeleteOpts
35type ContainerID = Text
39type Request = HTTP.Request
40type Response = HTTP.Response BL.ByteString
42data Signal = SIGINT | SIGKILL deriving (Eq, Show)
44data DockerClientOpts = DockerClientOpts {
49type HttpHandler m = Request -> m Response
51type DockerT m a = ReaderT (DockerClientOpts, HttpHandler m) (ExceptT String m) a
53runDockerT :: (Monad m) => (DockerClientOpts, HttpHandler m) -> DockerT m a -> m (Either String a)
54runDockerT opts a = runExceptT $ runReaderT a opts
55-- runDockerT opts a = (runExceptT .) . flip runReaderT opts a
57data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
59defaultClientOpts :: DockerClientOpts
60defaultClientOpts = DockerClientOpts {
62 , baseUrl = "http://127.0.0.1:2375/"
65data DockerVersion = DockerVersion {
67 , apiVersion :: ApiVersion
72 , kernelVersion :: Text
74 } deriving (Show, Eq, Generic)
77instance ToJSON DockerVersion where
78 toJSON = genericToJSON defaultOptions {
79 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
81instance FromJSON DockerVersion where
82 parseJSON = genericParseJSON defaultOptions {
83 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
85data Container = Container
88newtype Labels = Labels (M.Map Name Value) deriving (Eq, Show)
90instance FromJSON Labels where
91 parseJSON val = Labels <$> parseJSON val
93instance ToJSON Labels where
94 toJSON (Labels kvs) = object [k .= v | (k,v) <- (M.toList kvs)]
98data Image = DockerImage {
100 , imageCreated :: Integer
101 , imageParentId :: Maybe ImageID
102 , imageRepoTags :: [Tag]
103 , imageRepoDigests :: [Digest]
104 , imageSize :: Integer
105 , imageVirtualSize :: Integer
106 , imageLabels :: Labels
107 } deriving (Show, Eq, Generic)
109dropImagePrefix = drop 5
111instance FromJSON Image where
112 parseJSON = genericParseJSON defaultOptions {
113 fieldLabelModifier = dropImagePrefix}
115data CreateOpts = CreateOpts
116data StartOpts = StartOpts
118data DeleteOpts = DeleteOpts {
119 deleteVolumes :: Bool
121 } deriving (Eq, Show)
123type Timestamp = Integer
124data TailLogOpt = Tail Integer | All deriving (Eq, Show)
126data LogOpts = LogOpts {
133 } deriving (Eq, Show)
135data VolumePermission = Rw | Ro deriving (Eq, Show, Generic)
137instance ToJSON VolumePermission
138instance FromJSON VolumePermission
140data Volume = Volume { hostSrc :: Text
141 , containerDest :: Text
142 , volumePermission :: Maybe VolumePermission
143 } deriving (Eq, Show)
145type ContainerName = Text
147data VolumeFrom = VolumeFrom ContainerName VolumePermission deriving (Eq, Show)
149instance ToJSON Volume where
150 toJSON (Volume src dest mode) = toJSON $ case mode of
151 Nothing -> T.concat[src, ":", dest]
152 Just m -> T.concat[src, ":", dest, ":", (T.pack $ show m)]
154data Link = Link Text (Maybe Text) deriving (Eq, Show)
156instance ToJSON Link where
157 toJSON (Link n1 n2) = toJSON $ case n2 of
158 Nothing -> T.concat[n1, ":", n1]
159 Just n -> T.concat[n1, ":", n]
161-- { "Type": "<driver_name>", "Config": {"key1": "val1"} }
162data LogDriverType = JsonFile | Syslog | Journald | Gelf | AwsLogs | Splunk | LoggingDisabled deriving (Eq, Show)
164data LogDriverOptions = Map Text Text deriving (Eq, Show)
166data LogDriverConfig = LogDriverConfig LogDriverType (Maybe LogDriverOptions) deriving (Eq, Show)
168-- TODO: Add container:<name|id> mode
169data NetworkMode = Bridge | Host | NetworkDisabled deriving (Eq, Show)
171data PortType = TCP | UDP deriving (Eq, Show)
173newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
175-- { <port>/<protocol>: [{ "HostPort": "<port>" }] }
176data PortBinding = PortBinding {
177 containerPort :: Integer
178 , portType :: PortType
179 , hostPort :: [HostPort]
180 } deriving (Eq, Show)
182data HostPort = HostPort NetworkInterface Port deriving (Eq, Show)
184-- { "Name": "on-failure" , "MaximumRetryCount": 2}
185type RetryCount = Integer
186data RestartPolicy = RestartAlways | RestartUnlessStopped | RestartOnFailure RetryCount | RestartOff deriving (Eq, Show)
188data Isolation = Default | Process | Hyperv deriving (Eq, Show)
190newtype UTSMode = UTSMode Text deriving (Eq, Show)
192-- TODO: Add Tmpfs : List of tmpfs (mounts) used for the container
193-- TODO: Add UTSMode : UTS namespace to use for the container
194data HostConfig = HostConfig
196 , containerIDFile :: FilePath
197 , logConfig :: LogDriverConfig
198 , networkMode :: NetworkMode
199 , portBindings :: [PortBinding]
200 , restartPolicy :: RestartPolicy
201 , volumeDriver :: Text
202 , volumesFrom :: [VolumeFrom]
206 , dnsOptions :: [Text]
207 , dnsSearch :: [Text]
208 , extraHosts :: [Text]
209 , groupAdd :: [Integer]
212 , oomScoreAdj :: Integer
215 , publishAllPorts :: Bool
216 , readOnlyRootfs :: Bool
217 , securityOpt :: [Text]
218 , storageOpt :: [Text]
221 , consoleSize :: Integer
222 , isolation :: Isolation
223 , resources :: ContainerResources
224 } deriving (Eq, Show, Generic)
226-- { "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }
227-- { "Name": "nofile", "Soft": 1024, "Hard": 2048 }
228data Ulimit = Ulimit {
230 , ulimitSoft :: Integer
231 , ulimitHard :: Integer
232 } deriving (Eq, Show)
234data ContainerResources = ContainerResources {
236 , cgroupParent :: Text
237 , blkioWeight :: Text
238 , blkioWeightDevice :: Text
239 , blkioDeviceReadBps :: Text
240 , blkioDeviceWriteBps :: Text
241 , blkioDeviceReadIOps :: Text
242 , blkioDeviceWriteIOps :: Text
243 , cpuPeriod :: Integer
244 , cpuQuota :: Integer
245 , cpusetCpus :: Integer
247 , devices :: [Volume]
248 , diskQuota :: Integer
249 , kernelMemory :: Integer
251 , memoryReservation :: Integer
252 , memorySwap :: Integer
253 , memorySwappiness :: Integer
254 , oomKillDisable :: Bool
255 , pidsLimit :: Integer
256 , ulimits :: [Ulimit]
257 } deriving (Eq, Show)
264data EnvVar = EnvVar Name Value deriving (Eq, Show)
266data ContainerConfig = ContainerConfig {
270 , attachStdin :: Bool
271 , attachStdout :: Bool
272 , attachStderr :: Bool
273 -- ExposedPorts are used for the PublishAllPorts flag
274 -- to know which ports to publish. Also it's used for
275 -- the deamon to know wich Environment variables to
276 -- inject into a container linking to our container.
277 -- Example linking a Postgres container named db:
278 -- DB_PORT_5432_TCP_PORT="5432"
279 -- DB_PORT_5432_TCP_PROTO="tcp"
280 -- DB_PORT_5432_TCP="tcp://172.17.0.1:5432"
281 , exposedPorts :: [Port]
282 , publishService :: Text
288 , argsEscaped :: Bool
290 , volumes :: [Volume]
291 , workingDir :: FilePath
293 , networkDisabled :: Bool
297 , stopSignal :: Signal
298 } 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