@@ -11,9 +11,6 @@ module Docker.Client.Types (
12 , fromImageID
12 , fromImageID
13 , toImageID
13 , toImageID
17 , Timeout(..)
14 , Timeout(..)
18 , StatusCode(..)
15 , StatusCode(..)
19 , Signal(..)
16 , Signal(..)
@@ -40,16 +37,12 @@ module Docker.Client.Types (
40 , DetachKeys(..)
37 , DetachKeys(..)
41 , StartOpts(..)
38 , StartOpts(..)
42 , defaultStartOpts
39 , defaultStartOpts
43− , ContainerDeleteOpts(..)
40+ , DeleteOpts(..)
44− , defaultContainerDeleteOpts
41+ , defaultDeleteOpts
45− , ImageDeleteOpts(..)
46− , defaultImageDeleteOpts
47 , Timestamp
42 , Timestamp
48 , TailLogOpt(..)
43 , TailLogOpt(..)
49 , LogOpts(..)
44 , LogOpts(..)
50 , defaultLogOpts
45 , defaultLogOpts
51− , CreateNetworkOpts(..)
52− , defaultCreateNetworkOpts
53 , VolumePermission(..)
46 , VolumePermission(..)
54 , Bind(..)
47 , Bind(..)
55 , Volume(..)
48 , Volume(..)
@@ -75,8 +68,6 @@ module Docker.Client.Types (
75 , UTSMode(..)
68 , UTSMode(..)
76 , HostConfig(..)
69 , HostConfig(..)
77 , defaultHostConfig
70 , defaultHostConfig
78− , NetworkingConfig(..)
80 , Ulimit(..)
71 , Ulimit(..)
81 , ContainerResources(..)
72 , ContainerResources(..)
82 , defaultContainerResources
73 , defaultContainerResources
@@ -132,13 +123,10 @@ data Endpoint =
132 | UnpauseContainerEndpoint ContainerID
123 | UnpauseContainerEndpoint ContainerID
133 | ContainerLogsEndpoint LogOpts Bool ContainerID -- ^ Second argument (Bool) is whether to follow which is currently hardcoded to False.
124 | ContainerLogsEndpoint LogOpts Bool ContainerID -- ^ Second argument (Bool) is whether to follow which is currently hardcoded to False.
134 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
125 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
135− | DeleteContainerEndpoint ContainerDeleteOpts ContainerID
126+ | DeleteContainerEndpoint DeleteOpts ContainerID
136 | InspectContainerEndpoint ContainerID
127 | InspectContainerEndpoint ContainerID
137 | BuildImageEndpoint BuildOpts FilePath
128 | BuildImageEndpoint BuildOpts FilePath
138 | CreateImageEndpoint T.Text Tag (Maybe T.Text) -- ^ Either pull an image from docker hub or imports an image from a tarball (or URL)
129 | 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
142 deriving (Eq, Show)
130 deriving (Eq, Show)
144-- | We should newtype this
132-- | We should newtype this
@@ -623,46 +611,20 @@ instance FromJSON Image where
623 return $ DockerImage imageId imageCreated imageParentId imageRepoTags imageRepoDigests imageSize imageVirtualSize imageLabels
611 return $ DockerImage imageId imageCreated imageParentId imageRepoTags imageRepoDigests imageSize imageVirtualSize imageLabels
624 parseJSON _ = fail "Failed to parse DockerImage."
612 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
650-- | Options used for creating a Container.
615-- | Options used for creating a Container.
651data CreateOpts = CreateOpts {
616data CreateOpts = CreateOpts {
652− containerConfig :: ContainerConfig
617+ containerConfig :: ContainerConfig
653− , hostConfig :: HostConfig
618+ , hostConfig :: HostConfig
654− , networkingConfig :: NetworkingConfig
655 } deriving (Eq, Show)
619 } deriving (Eq, Show)
657instance ToJSON CreateOpts where
621instance ToJSON CreateOpts where
658− toJSON (CreateOpts cc hc nc) = do
622+ toJSON (CreateOpts cc hc) = do
659 let ccJSON = toJSON cc
623 let ccJSON = toJSON cc
660 let hcJSON = toJSON hc
624 let hcJSON = toJSON hc
661 case ccJSON of
625 case ccJSON of
662 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
626 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
663− let o1 = HM.insert "HostConfig" hcJSON o
627+ JSON.Object $ HM.insert "HostConfig" hcJSON o
664− let o2 = HM.insert "NetworkingConfig" (toJSON nc) o1
666 _ -> error "ContainerConfig is not an object." -- This should never happen.
628 _ -> error "ContainerConfig is not an object." -- This should never happen.
668-- | Container configuration used for creating a container with sensible
630-- | Container configuration used for creating a container with sensible
@@ -744,11 +706,7 @@ defaultContainerResources = ContainerResources {
744-- | Default create options when creating a container. You only need to
706-- | Default create options when creating a container. You only need to
745-- specify an image name and the rest is all sensible defaults.
707-- specify an image name and the rest is all sensible defaults.
746defaultCreateOpts :: T.Text -> CreateOpts
708defaultCreateOpts :: T.Text -> CreateOpts
747−defaultCreateOpts imageName = CreateOpts
748− { containerConfig = defaultContainerConfig imageName
709+defaultCreateOpts imageName = CreateOpts { containerConfig = defaultContainerConfig imageName, hostConfig = defaultHostConfig }
749− , hostConfig = defaultHostConfig
750− , networkingConfig = NetworkingConfig HM.empty
753-- | Override the key sequence for detaching a container.
711-- | Override the key sequence for detaching a container.
754-- Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
712-- Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
@@ -762,7 +720,7 @@ defaultStartOpts :: StartOpts
762defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
720defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
764-- | Options for deleting a container.
722-- | Options for deleting a container.
765−data ContainerDeleteOpts = ContainerDeleteOpts {
723+data DeleteOpts = DeleteOpts {
766 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
724 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
767 , force :: Bool -- ^ If the container is still running force deletion anyway.
725 , force :: Bool -- ^ If the container is still running force deletion anyway.
768 } deriving (Eq, Show)
726 } deriving (Eq, Show)
@@ -792,15 +750,8 @@ defaultBuildOpts nameTag = BuildOpts { buildImageName = nameTag
792-- | Default options for deleting a container. Most of the time we DON'T
750-- | Default options for deleting a container. Most of the time we DON'T
793-- want to delete the container's volumes or force delete it if it's
751-- want to delete the container's volumes or force delete it if it's
794-- running.
752-- running.
795−defaultContainerDeleteOpts :: ContainerDeleteOpts
753+defaultDeleteOpts :: DeleteOpts
796−defaultContainerDeleteOpts = ContainerDeleteOpts { deleteVolumes = False, force = False }
754+defaultDeleteOpts = DeleteOpts { 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
805-- | Timestamp alias.
756-- | Timestamp alias.
806type Timestamp = Integer
757type Timestamp = Integer
@@ -828,36 +779,6 @@ defaultLogOpts = LogOpts { stdout = True
828 , tail = All
779 , 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
861-- TOOD: Add support for SELinux Volume labels (eg. "ro,z" or "ro/Z")
782-- TOOD: Add support for SELinux Volume labels (eg. "ro,z" or "ro/Z")
862-- | Set permissions on volumes that you mount in the container.
783-- | Set permissions on volumes that you mount in the container.
863data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
784data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
@@ -1033,26 +954,6 @@ instance ToJSON NetworkMode where
1033 toJSON NetworkDisabled = JSON.String "none"
954 toJSON NetworkDisabled = JSON.String "none"
1034 toJSON (NetworkNamed n) = JSON.String n
955 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]
1056data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
957data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
1058instance Show PortType where
959instance Show PortType where
@@ -1564,11 +1465,7 @@ instance FromJSON ContainerConfig where
1564 macAddress labels stopSignal
1465 macAddress labels stopSignal
1565 parseJSON _ = fail "NetworkSettings is not an object."
1466 parseJSON _ = fail "NetworkSettings is not an object."
1567−#if MIN_VERSION_base(4,13,0)
1568−parseIntegerText :: (MonadFail m) => Text -> m Integer
1570parseIntegerText :: (Monad m) => Text -> m Integer
1468parseIntegerText :: (Monad m) => Text -> m Integer
1572parseIntegerText t = case readMaybe $ T.unpack t of
1469parseIntegerText t = case readMaybe $ T.unpack t of
1573 Nothing ->
1470 Nothing ->
1574 fail "Could not parse Integer"
1471 fail "Could not parse Integer"