@@ -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(..)
@@ -125,10 +132,13 @@ data Endpoint =
125 | UnpauseContainerEndpoint ContainerID
132 | UnpauseContainerEndpoint ContainerID
126 | 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.
127 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
134 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
128− | DeleteContainerEndpoint DeleteOpts ContainerID
135+ | DeleteContainerEndpoint ContainerDeleteOpts ContainerID
129 | InspectContainerEndpoint ContainerID
136 | InspectContainerEndpoint ContainerID
130 | BuildImageEndpoint BuildOpts FilePath
137 | BuildImageEndpoint BuildOpts FilePath
131 | 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
132 deriving (Eq, Show)
142 deriving (Eq, Show)
134-- | We should newtype this
144-- | We should newtype this
@@ -624,9 +634,12 @@ instance ToJSON EndpointConfig where
624 [ "Aliases" .= aliases
634 [ "Aliases" .= aliases
637+-- | Alias for endpoint name
638+type EndpointName = Text
627-- | Data type for the NetworkingConfig section of the container settings
640-- | Data type for the NetworkingConfig section of the container settings
628newtype NetworkingConfig = NetworkingConfig
641newtype NetworkingConfig = NetworkingConfig
629− { endpointsConfig :: HM.HashMap Text EndpointConfig
642+ { endpointsConfig :: HM.HashMap EndpointName EndpointConfig
630 } deriving (Eq, Show)
643 } deriving (Eq, Show)
632instance ToJSON NetworkingConfig where
645instance ToJSON NetworkingConfig where
@@ -636,9 +649,9 @@ instance ToJSON NetworkingConfig where
637-- | Options used for creating a Container.
650-- | Options used for creating a Container.
638data CreateOpts = CreateOpts {
651data CreateOpts = CreateOpts {
639− containerConfig :: ContainerConfig
652+ containerConfig :: ContainerConfig
640− , hostConfig :: HostConfig
653+ , hostConfig :: HostConfig
641− , networkingConfig :: Maybe NetworkingConfig
654+ , networkingConfig :: NetworkingConfig
642 } deriving (Eq, Show)
655 } deriving (Eq, Show)
644instance ToJSON CreateOpts where
657instance ToJSON CreateOpts where
@@ -648,9 +661,7 @@ instance ToJSON CreateOpts where
648 case ccJSON of
661 case ccJSON of
649 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
662 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
650 let o1 = HM.insert "HostConfig" hcJSON o
663 let o1 = HM.insert "HostConfig" hcJSON o
653− Just _ -> HM.insert "NetworkingConfig" (toJSON nc) o1
664+ let o2 = HM.insert "NetworkingConfig" (toJSON nc) o1
654 JSON.Object o2
665 JSON.Object o2
655 _ -> error "ContainerConfig is not an object." -- This should never happen.
666 _ -> error "ContainerConfig is not an object." -- This should never happen.
@@ -736,7 +747,7 @@ defaultCreateOpts :: T.Text -> CreateOpts
736defaultCreateOpts imageName = CreateOpts
747defaultCreateOpts imageName = CreateOpts
737 { containerConfig = defaultContainerConfig imageName
748 { containerConfig = defaultContainerConfig imageName
738 , hostConfig = defaultHostConfig
749 , hostConfig = defaultHostConfig
739− , networkingConfig = Nothing
750+ , networkingConfig = NetworkingConfig HM.empty
742-- | Override the key sequence for detaching a container.
753-- | Override the key sequence for detaching a container.
@@ -751,7 +762,7 @@ defaultStartOpts :: StartOpts
751defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
762defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
753-- | Options for deleting a container.
764-- | Options for deleting a container.
754−data DeleteOpts = DeleteOpts {
765+data ContainerDeleteOpts = ContainerDeleteOpts {
755 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
766 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
756 , force :: Bool -- ^ If the container is still running force deletion anyway.
767 , force :: Bool -- ^ If the container is still running force deletion anyway.
757 } deriving (Eq, Show)
768 } deriving (Eq, Show)
@@ -781,8 +792,15 @@ defaultBuildOpts nameTag = BuildOpts { buildImageName = nameTag
781-- | 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
782-- 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
783-- running.
794-- running.
784−defaultDeleteOpts :: DeleteOpts
795+defaultContainerDeleteOpts :: ContainerDeleteOpts
785−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
787-- | Timestamp alias.
805-- | Timestamp alias.
788type Timestamp = Integer
806type Timestamp = Integer
@@ -810,6 +828,36 @@ defaultLogOpts = LogOpts { stdout = True
810 , 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
813-- 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")
814-- | Set permissions on volumes that you mount in the container.
862-- | Set permissions on volumes that you mount in the container.
815data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
863data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
@@ -985,6 +1033,26 @@ instance ToJSON NetworkMode where
985 toJSON NetworkDisabled = JSON.String "none"
1033 toJSON NetworkDisabled = JSON.String "none"
986 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]
988data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
1056data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
990instance Show PortType where
1058instance Show PortType where
@@ -1496,7 +1564,11 @@ instance FromJSON ContainerConfig where
1496 macAddress labels stopSignal
1564 macAddress labels stopSignal
1497 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
1499parseIntegerText :: (Monad m) => Text -> m Integer
1570parseIntegerText :: (Monad m) => Text -> m Integer
1500parseIntegerText t = case readMaybe $ T.unpack t of
1572parseIntegerText t = case readMaybe $ T.unpack t of
1501 Nothing ->
1573 Nothing ->
1502 fail "Could not parse Integer"
1574 fail "Could not parse Integer"