@@ -11,6 +11,9 @@ module Docker.Client.Types (
12 , fromImageID
12 , fromImageID
13 , toImageID
13 , toImageID
14 , Timeout(..)
17 , Timeout(..)
15 , StatusCode(..)
18 , StatusCode(..)
16 , Signal(..)
19 , Signal(..)
@@ -37,12 +40,16 @@ module Docker.Client.Types (
37 , DetachKeys(..)
40 , DetachKeys(..)
38 , StartOpts(..)
41 , StartOpts(..)
39 , defaultStartOpts
42 , defaultStartOpts
40− , DeleteOpts(..)
43+ , ContainerDeleteOpts(..)
41− , defaultDeleteOpts
44+ , defaultContainerDeleteOpts
45+ , ImageDeleteOpts(..)
46+ , defaultImageDeleteOpts
42 , Timestamp
47 , Timestamp
43 , TailLogOpt(..)
48 , TailLogOpt(..)
44 , LogOpts(..)
49 , LogOpts(..)
45 , defaultLogOpts
50 , defaultLogOpts
51+ , CreateNetworkOpts(..)
52+ , defaultCreateNetworkOpts
46 , VolumePermission(..)
53 , VolumePermission(..)
47 , Bind(..)
54 , Bind(..)
48 , Volume(..)
55 , Volume(..)
@@ -68,6 +75,8 @@ module Docker.Client.Types (
68 , UTSMode(..)
75 , UTSMode(..)
69 , HostConfig(..)
76 , HostConfig(..)
70 , defaultHostConfig
77 , defaultHostConfig
78+ , NetworkingConfig(..)
71 , Ulimit(..)
80 , Ulimit(..)
72 , ContainerResources(..)
81 , ContainerResources(..)
73 , defaultContainerResources
82 , defaultContainerResources
@@ -123,10 +132,13 @@ data Endpoint =
123 | UnpauseContainerEndpoint ContainerID
132 | UnpauseContainerEndpoint ContainerID
124 | ContainerLogsEndpoint LogOpts Bool ContainerID -- ^ Second argument (Bool) is whether to follow which is currently hardcoded to False.
133 | ContainerLogsEndpoint LogOpts Bool ContainerID -- ^ Second argument (Bool) is whether to follow which is currently hardcoded to False.
125 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
134 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
126− | DeleteContainerEndpoint DeleteOpts ContainerID
135+ | DeleteContainerEndpoint ContainerDeleteOpts ContainerID
127 | InspectContainerEndpoint ContainerID
136 | InspectContainerEndpoint ContainerID
128 | BuildImageEndpoint BuildOpts FilePath
137 | BuildImageEndpoint BuildOpts FilePath
129 | CreateImageEndpoint T.Text Tag (Maybe T.Text) -- ^ Either pull an image from docker hub or imports an image from a tarball (or URL)
138 | CreateImageEndpoint T.Text Tag (Maybe T.Text) -- ^ Either pull an image from docker hub or imports an image from a tarball (or URL)
139+ | DeleteImageEndpoint ImageDeleteOpts ImageID
140+ | CreateNetworkEndpoint CreateNetworkOpts
141+ | RemoveNetworkEndpoint NetworkID
130 deriving (Eq, Show)
142 deriving (Eq, Show)
132-- | We should newtype this
144-- | We should newtype this
@@ -611,20 +623,46 @@ instance FromJSON Image where
611 return $ DockerImage imageId imageCreated imageParentId imageRepoTags imageRepoDigests imageSize imageVirtualSize imageLabels
623 return $ DockerImage imageId imageCreated imageParentId imageRepoTags imageRepoDigests imageSize imageVirtualSize imageLabels
612 parseJSON _ = fail "Failed to parse DockerImage."
624 parseJSON _ = fail "Failed to parse DockerImage."
626+-- | Alias for Aliases.
629+-- | EndpointsConfig is container configuration for a specific network
630+newtype EndpointConfig = EndpointConfig [Alias] deriving (Eq, Show)
632+instance ToJSON EndpointConfig where
633+ toJSON (EndpointConfig aliases) = JSON.object
634+ [ "Aliases" .= aliases
637+-- | Alias for endpoint name
638+type EndpointName = Text
640+-- | Data type for the NetworkingConfig section of the container settings
641+newtype NetworkingConfig = NetworkingConfig
642+ { endpointsConfig :: HM.HashMap EndpointName EndpointConfig
643+ } deriving (Eq, Show)
645+instance ToJSON NetworkingConfig where
646+ toJSON (NetworkingConfig endpointsConfig) = JSON.object
647+ [ "EndpointsConfig" .= endpointsConfig
615-- | Options used for creating a Container.
650-- | Options used for creating a Container.
616data CreateOpts = CreateOpts {
651data CreateOpts = CreateOpts {
617− containerConfig :: ContainerConfig
652+ containerConfig :: ContainerConfig
618− , hostConfig :: HostConfig
653+ , hostConfig :: HostConfig
654+ , networkingConfig :: NetworkingConfig
619 } deriving (Eq, Show)
655 } deriving (Eq, Show)
621instance ToJSON CreateOpts where
657instance ToJSON CreateOpts where
622− toJSON (CreateOpts cc hc) = do
658+ toJSON (CreateOpts cc hc nc) = do
623 let ccJSON = toJSON cc
659 let ccJSON = toJSON cc
624 let hcJSON = toJSON hc
660 let hcJSON = toJSON hc
625 case ccJSON of
661 case ccJSON of
626 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
662 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
627− JSON.Object $ HM.insert "HostConfig" hcJSON o
663+ let o1 = HM.insert "HostConfig" hcJSON o
664+ let o2 = HM.insert "NetworkingConfig" (toJSON nc) o1
628 _ -> error "ContainerConfig is not an object." -- This should never happen.
666 _ -> error "ContainerConfig is not an object." -- This should never happen.
630-- | Container configuration used for creating a container with sensible
668-- | Container configuration used for creating a container with sensible
@@ -706,7 +744,11 @@ defaultContainerResources = ContainerResources {
706-- | Default create options when creating a container. You only need to
744-- | Default create options when creating a container. You only need to
707-- specify an image name and the rest is all sensible defaults.
745-- specify an image name and the rest is all sensible defaults.
708defaultCreateOpts :: T.Text -> CreateOpts
746defaultCreateOpts :: T.Text -> CreateOpts
747+defaultCreateOpts imageName = CreateOpts
709−defaultCreateOpts imageName = CreateOpts { containerConfig = defaultContainerConfig imageName, hostConfig = defaultHostConfig }
748+ { containerConfig = defaultContainerConfig imageName
749+ , hostConfig = defaultHostConfig
750+ , networkingConfig = NetworkingConfig HM.empty
711-- | Override the key sequence for detaching a container.
753-- | Override the key sequence for detaching a container.
712-- Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
754-- Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
@@ -720,7 +762,7 @@ defaultStartOpts :: StartOpts
720defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
762defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
722-- | Options for deleting a container.
764-- | Options for deleting a container.
723−data DeleteOpts = DeleteOpts {
765+data ContainerDeleteOpts = ContainerDeleteOpts {
724 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
766 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
725 , force :: Bool -- ^ If the container is still running force deletion anyway.
767 , force :: Bool -- ^ If the container is still running force deletion anyway.
726 } deriving (Eq, Show)
768 } deriving (Eq, Show)
@@ -750,8 +792,15 @@ defaultBuildOpts nameTag = BuildOpts { buildImageName = nameTag
750-- | Default options for deleting a container. Most of the time we DON'T
792-- | Default options for deleting a container. Most of the time we DON'T
751-- want to delete the container's volumes or force delete it if it's
793-- want to delete the container's volumes or force delete it if it's
752-- running.
794-- running.
753−defaultDeleteOpts :: DeleteOpts
795+defaultContainerDeleteOpts :: ContainerDeleteOpts
754−defaultDeleteOpts = DeleteOpts { deleteVolumes = False, force = False }
796+defaultContainerDeleteOpts = ContainerDeleteOpts { deleteVolumes = False, force = False }
798+-- | Image delete opts
799+data ImageDeleteOpts = ImageDeleteOpts deriving (Eq, Show)
801+-- | Sane image deletion defaults
802+defaultImageDeleteOpts :: ImageDeleteOpts
803+defaultImageDeleteOpts = ImageDeleteOpts
756-- | Timestamp alias.
805-- | Timestamp alias.
757type Timestamp = Integer
806type Timestamp = Integer
@@ -779,6 +828,36 @@ defaultLogOpts = LogOpts { stdout = True
779 , tail = All
828 , tail = All
831+-- | Options for creating a network
832+data CreateNetworkOpts = CreateNetworkOpts
833+ { createNetworkName :: Text -- ^ The network's name
834+ , createNetworkCheckDuplicate :: Bool -- ^ Check for networks with duplicate names.
835+ , createNetworkDriver :: Text -- ^ Name of the network driver plugin to use.
836+ , createNetworkInternal :: Bool -- ^ Restrict external access to the network.
837+ , createNetworkEnableIPv6 :: Bool -- ^ Enable IPv6 on the network.
838+ } deriving (Eq, Show)
840+-- | Sensible defalut for create network options
841+defaultCreateNetworkOpts :: Text -> CreateNetworkOpts
842+defaultCreateNetworkOpts name =
844+ { createNetworkName = name
845+ , createNetworkCheckDuplicate = False
846+ , createNetworkDriver = "bridge"
847+ , createNetworkInternal = True
848+ , createNetworkEnableIPv6 = False
851+instance ToJSON CreateNetworkOpts where
854+ [ "Name" .= createNetworkName opts
855+ , "CheckDuplicate" .= createNetworkCheckDuplicate opts
856+ , "Driver" .= createNetworkDriver opts
857+ , "Internal" .= createNetworkInternal opts
858+ , "EnableIPv6" .= createNetworkEnableIPv6 opts
782-- TOOD: Add support for SELinux Volume labels (eg. "ro,z" or "ro/Z")
861-- TOOD: Add support for SELinux Volume labels (eg. "ro,z" or "ro/Z")
783-- | Set permissions on volumes that you mount in the container.
862-- | Set permissions on volumes that you mount in the container.
784data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
863data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
@@ -954,6 +1033,26 @@ instance ToJSON NetworkMode where
954 toJSON NetworkDisabled = JSON.String "none"
1033 toJSON NetworkDisabled = JSON.String "none"
955 toJSON (NetworkNamed n) = JSON.String n
1034 toJSON (NetworkNamed n) = JSON.String n
1036+newtype NetworkID = NetworkID Text
1037+ deriving (Eq, Show)
1039+-- | Used for extracting the id of the container from the newtype
1040+fromNetworkID :: NetworkID -> Text
1041+fromNetworkID (NetworkID t) = t
1043+-- | Used for parsing a Text value into a NetworkID.
1044+toNetworkID :: Text -> Maybe NetworkID
1045+toNetworkID t = Just $ NetworkID t
1047+instance FromJSON NetworkID where
1048+ parseJSON (JSON.Object o) = do
1050+ return $ NetworkID nid
1051+ parseJSON _ = fail "NetworkID is not an object."
1053+instance ToJSON NetworkID where
1054+ toJSON (NetworkID nid) = object ["Id" .= nid]
957data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
1056data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
959instance Show PortType where
1058instance Show PortType where
@@ -1465,7 +1564,11 @@ instance FromJSON ContainerConfig where
1465 macAddress labels stopSignal
1564 macAddress labels stopSignal
1466 parseJSON _ = fail "NetworkSettings is not an object."
1565 parseJSON _ = fail "NetworkSettings is not an object."
1567+#if MIN_VERSION_base(4,13,0)
1568+parseIntegerText :: (MonadFail m) => Text -> m Integer
1468parseIntegerText :: (Monad m) => Text -> m Integer
1570parseIntegerText :: (Monad m) => Text -> m Integer
1469parseIntegerText t = case readMaybe $ T.unpack t of
1572parseIntegerText t = case readMaybe $ T.unpack t of
1470 Nothing ->
1573 Nothing ->
1471 fail "Could not parse Integer"
1574 fail "Could not parse Integer"