@@ -11,9 +11,6 @@ module Docker.Client.Types (
1111 , ImageID
1212 , fromImageID
1313 , toImageID
14− , NetworkID
15− , fromNetworkID
16− , toNetworkID
1714 , Timeout(..)
1815 , StatusCode(..)
1916 , Signal(..)
@@ -26,30 +23,23 @@ module Docker.Client.Types (
2623 , ContainerPortInfo(..)
2724 , Container(..)
2825 , ContainerState(..)
29− , State(..)
26+ , Status(..)
3027 , Digest
3128 , Label(..)
3229 , Tag
3330 , Image(..)
34− , Entrypoint(..)
3531 , dropImagePrefix
3632 , CreateOpts(..)
37− , BuildOpts(..)
38− , defaultBuildOpts
3933 , defaultCreateOpts
4034 , DetachKeys(..)
4135 , StartOpts(..)
4236 , defaultStartOpts
43− , ContainerDeleteOpts(..)
44− , defaultContainerDeleteOpts
45− , ImageDeleteOpts(..)
46− , defaultImageDeleteOpts
37+ , DeleteOpts(..)
38+ , defaultDeleteOpts
4739 , Timestamp
4840 , TailLogOpt(..)
4941 , LogOpts(..)
5042 , defaultLogOpts
51− , CreateNetworkOpts(..)
52− , defaultCreateNetworkOpts
5343 , VolumePermission(..)
5444 , Bind(..)
5545 , Volume(..)
@@ -75,8 +65,6 @@ module Docker.Client.Types (
7565 , UTSMode(..)
7666 , HostConfig(..)
7767 , defaultHostConfig
78− , NetworkingConfig(..)
79− , EndpointConfig(..)
8068 , Ulimit(..)
8169 , ContainerResources(..)
8270 , defaultContainerResources
@@ -112,7 +100,6 @@ import Data.Scientific (floatingOrInteger)
112100import Data.Text (Text)
113101import qualified Data.Text as T
114102import Data.Time.Clock (UTCTime)
115−import qualified Data.Vector as V
116103import GHC.Generics (Generic)
117104import Prelude hiding (all, tail)
118105import Text.Read (readMaybe)
@@ -132,13 +119,8 @@ data Endpoint =
132119 | UnpauseContainerEndpoint ContainerID
133120 | ContainerLogsEndpoint LogOpts Bool ContainerID -- ^ Second argument (Bool) is whether to follow which is currently hardcoded to False.
134121 -- See note in 'Docker.Client.Api.getContainerLogs' for explanation why.
135− | DeleteContainerEndpoint ContainerDeleteOpts ContainerID
122+ | DeleteContainerEndpoint DeleteOpts ContainerID
136123 | InspectContainerEndpoint ContainerID
137− | 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)
139− | DeleteImageEndpoint ImageDeleteOpts ImageID
140− | CreateNetworkEndpoint CreateNetworkOpts
141− | RemoveNetworkEndpoint NetworkID
142124 deriving (Eq, Show)
143125
144126-- | We should newtype this
@@ -213,16 +195,16 @@ data Signal = SIGHUP
213195
214196instance FromJSON Signal where
215197 parseJSON (JSON.String "SIGTERM") = return SIGTERM
216− parseJSON (JSON.String "SIGHUP") = return SIGHUP -- Note: Guessing on the string values for these.
217− parseJSON (JSON.String "SIGINT") = return SIGINT
198+ parseJSON (JSON.String "SIGHUP") = return SIGHUP -- Note: Guessing on the string values for these.
199+ parseJSON (JSON.String "SIGINT") = return SIGINT
218200 parseJSON (JSON.String "SIGQUIT") = return SIGQUIT
219201 parseJSON (JSON.String "SIGSTOP") = return SIGSTOP
220202 parseJSON (JSON.String "SIGUSR1") = return SIGUSR1
221− parseJSON _ = fail "Unknown Signal"
203+ parseJSON _ = fail "Unknown Signal"
222204
223205instance ToJSON Signal where
224− toJSON SIGHUP = "SIGHUP"
225− toJSON SIGINT = "SIGINT"
206+ toJSON SIGHUP = "SIGHUP"
207+ toJSON SIGINT = "SIGINT"
226208 toJSON SIGQUIT = "SIGQUIT"
227209 toJSON SIGSTOP = "SIGSTOP"
228210 toJSON SIGTERM = "SIGTERM"
@@ -250,7 +232,7 @@ data ContainerDetails = ContainerDetails {
250232 , processLabel :: Text
251233 , resolveConfPath :: FilePath
252234 , restartCount :: Int
253− , containerDetailsState :: ContainerState
235+ , state :: ContainerState
254236 , mounts :: [Mount]
255237 }
256238 deriving (Eq, Show, Generic)
@@ -258,11 +240,11 @@ data ContainerDetails = ContainerDetails {
258240-- | Data type used for parsing the mount information from a container
259241-- list.
260242data Mount = Mount {
261− mountName :: Maybe Text -- this is optional
243+ mountName :: Text
262244 , mountSource :: FilePath
263245 , mountDestination :: FilePath
264− , mountDriver :: Maybe Text
265− -- , mountMode :: Maybe VolumePermission -- apparently this can be null
246+ , mountDriver :: Text
247+ , mountMode :: Maybe VolumePermission -- apparently this can be null
266248 , mountRW :: Bool
267249 , mountPropogation :: Text
268250 }
@@ -270,14 +252,14 @@ data Mount = Mount {
270252
271253instance FromJSON Mount where
272254 parseJSON (JSON.Object o) = do
273− name <- o .:? "Name"
255+ name <- o .: "Name"
274256 src <- o .: "Source"
275257 dest <- o .: "Destination"
276− driver <- o .:? "Driver"
277− -- mode <- o .: "Mode"
258+ driver <- o .: "Driver"
259+ mode <- o .: "Mode"
278260 rw <- o .: "RW"
279261 prop <- o .: "Propagation"
280− return $ Mount name src dest driver rw prop
262+ return $ Mount name src dest driver mode rw prop
281263 parseJSON _ = fail "Mount is not an object"
282264
283265-- | Data type used for parsing the container state from a list of
@@ -293,7 +275,7 @@ data ContainerState = ContainerState {
293275 , restarting :: Bool
294276 , running :: Bool
295277 , startedAt :: UTCTime
296− , state :: State
278+ , status :: Status
297279 }
298280 deriving (Eq, Show, Generic)
299281
@@ -523,8 +505,7 @@ data Container = Container
523505 , containerImageId :: ImageID
524506 , containerCommand :: Text
525507 , containerCreatedAt :: Int
526− , containerState :: State
527− , containerStatus :: Maybe Text
508+ , containerStatus :: Status
528509 , containerPorts :: [ContainerPortInfo]
529510 , containerLabels :: [Label]
530511 , containerNetworks :: [Network]
@@ -532,14 +513,13 @@ data Container = Container
532513 } deriving (Show, Eq)
533514
534515instance FromJSON Container where
535− parseJSON o@(JSON.Object v) =
536− Container <$> parseJSON o
516+ parseJSON (JSON.Object v) =
517+ Container <$> (v .: "Id")
537518 <*> (v .: "Names")
538519 <*> (v .: "Image")
539− <*> (v .: "ImageID") -- Doesn't exist anymore
540− <*> (v .: "Command") -- Doesn't exist anymore
520+ <*> (v .: "ImageID")
521+ <*> (v .: "Command")
541522 <*> (v .: "Created")
542− <*> (v .: "State")
543523 <*> (v .: "Status")
544524 <*> (v .: "Ports")
545525 <*> (v .: "Labels")
@@ -549,20 +529,21 @@ instance FromJSON Container where
549529 parseNetworks (JSON.Object v) =
550530 (v .: "Networks") >>= parseJSON
551531 parseNetworks _ = fail "Container NetworkSettings: Not a JSON object."
532+
552533 parseJSON _ = fail "Container: Not a JSON object."
553534
554−-- | Represents the state of the container life cycle.
555−data State = Created | Restarting | Running | Paused | Exited | Dead
535+-- | Represents the status of the container life cycle.
536+data Status = Created | Restarting | Running | Paused | Exited | Dead
556537 deriving (Eq, Show, Generic)
557538
558−instance FromJSON State where
559− parseJSON (JSON.String "running") = return Running
560− parseJSON (JSON.String "created") = return Created -- Note: Guessing on the string values of these.
539+instance FromJSON Status where
540+ parseJSON (JSON.String "running") = return Running
541+ parseJSON (JSON.String "created") = return Created -- Note: Guessing on the string values of these.
561542 parseJSON (JSON.String "restarting") = return Restarting
562− parseJSON (JSON.String "paused") = return Paused
563− parseJSON (JSON.String "exited") = return Exited
564− parseJSON (JSON.String "dead") = return Dead
565− parseJSON s = fail $ "Unknown Status: " ++ show s
543+ parseJSON (JSON.String "paused") = return Paused
544+ parseJSON (JSON.String "exited") = return Exited
545+ parseJSON (JSON.String "dead") = return Dead
546+ parseJSON _ = fail "Unknown Status"
566547
567548-- | Alias for representing a RepoDigest. We could newtype this and add
568549-- some validation.
@@ -623,46 +604,20 @@ instance FromJSON Image where
623604 return $ DockerImage imageId imageCreated imageParentId imageRepoTags imageRepoDigests imageSize imageVirtualSize imageLabels
624605 parseJSON _ = fail "Failed to parse DockerImage."
625606
626−-- | Alias for Aliases.
627−type Alias = Text
628−
629−-- | EndpointsConfig is container configuration for a specific network
630−newtype EndpointConfig = EndpointConfig [Alias] deriving (Eq, Show)
631−
632−instance ToJSON EndpointConfig where
633− toJSON (EndpointConfig aliases) = JSON.object
634− [ "Aliases" .= aliases
635− ]
636−
637−-- | Alias for endpoint name
638−type EndpointName = Text
639−
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)
644−
645−instance ToJSON NetworkingConfig where
646− toJSON (NetworkingConfig endpointsConfig) = JSON.object
647− [ "EndpointsConfig" .= endpointsConfig
648− ]
649607
650608-- | Options used for creating a Container.
651609data CreateOpts = CreateOpts {
652− containerConfig :: ContainerConfig
653− , hostConfig :: HostConfig
654− , networkingConfig :: NetworkingConfig
610+ containerConfig :: ContainerConfig
611+ , hostConfig :: HostConfig
655612 } deriving (Eq, Show)
656613
657614instance ToJSON CreateOpts where
658− toJSON (CreateOpts cc hc nc) = do
615+ toJSON (CreateOpts cc hc) = do
659616 let ccJSON = toJSON cc
660617 let hcJSON = toJSON hc
661618 case ccJSON of
662619 JSON.Object (o :: HM.HashMap T.Text JSON.Value) -> do
663− let o1 = HM.insert "HostConfig" hcJSON o
664− let o2 = HM.insert "NetworkingConfig" (toJSON nc) o1
665− JSON.Object o2
620+ JSON.Object $ HM.insert "HostConfig" hcJSON o
666621 _ -> error "ContainerConfig is not an object." -- This should never happen.
667622
668623-- | Container configuration used for creating a container with sensible
@@ -684,7 +639,7 @@ defaultContainerConfig imageName = ContainerConfig {
684639 , cmd=[]
685640 , volumes=[]
686641 , workingDir=Nothing
687− , entrypoint=Entrypoint []
642+ , entrypoint=Nothing
688643 , networkDisabled=Nothing
689644 , macAddress=Nothing
690645 , labels=[]
@@ -697,7 +652,7 @@ defaultHostConfig = HostConfig {
697652 binds=[]
698653 , containerIDFile=Nothing
699654 , logConfig=LogDriverConfig JsonFile []
700− , networkMode=NetworkBridge
655+ , networkMode=Bridge
701656 , portBindings=[]
702657 , restartPolicy=RestartOff
703658 , volumeDriver=Nothing
@@ -737,18 +692,14 @@ defaultContainerResources = ContainerResources {
737692 , memory=Nothing
738693 , memoryReservation=Nothing
739694 , memorySwap=Nothing
740− , oomKillDisable=Just False
695+ , oomKillDisable=False
741696 , ulimits=[]
742697 }
743698
744699-- | Default create options when creating a container. You only need to
745700-- specify an image name and the rest is all sensible defaults.
746701defaultCreateOpts :: T.Text -> CreateOpts
747−defaultCreateOpts imageName = CreateOpts
748− { containerConfig = defaultContainerConfig imageName
749− , hostConfig = defaultHostConfig
750− , networkingConfig = NetworkingConfig HM.empty
751− }
702+defaultCreateOpts imageName = CreateOpts { containerConfig = defaultContainerConfig imageName, hostConfig = defaultHostConfig }
752703
753704-- | Override the key sequence for detaching a container.
754705-- Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
@@ -762,45 +713,16 @@ defaultStartOpts :: StartOpts
762713defaultStartOpts = StartOpts { detachKeys = DefaultDetachKey }
763714
764715-- | Options for deleting a container.
765−data ContainerDeleteOpts = ContainerDeleteOpts {
716+data DeleteOpts = DeleteOpts {
766717 deleteVolumes :: Bool -- ^ Automatically cleanup volumes that the container created as well.
767718 , force :: Bool -- ^ If the container is still running force deletion anyway.
768719 } deriving (Eq, Show)
769720
770−-- TODO: Add support for container build constraints
771−-- | Options for when building images from a Dockerfile
772−data BuildOpts = BuildOpts {
773− buildImageName :: Text -- ^ Image name in the form of name:tag; ie. myimage:latest.:w
774− , buildDockerfileName :: Text -- ^ Name of dockerfile (default: Dockerfile)
775− , buildQuiet :: Bool
776− , buildNoCache :: Bool -- ^ Do not use cache when building the image.
777− , buildRemoveItermediate :: Bool -- ^ Remove intermediate containers after a successful build (default true).
778− , buildForceRemoveIntermediate :: Bool -- ^ Always remove intermediate containers.
779− , buildPullParent :: Bool -- ^ Always attempt to pull a newer version of the *parent* image (ie. FROM debian:jessie).
780− } deriving (Eq, Show)
781−
782−defaultBuildOpts :: Text -> BuildOpts
783−defaultBuildOpts nameTag = BuildOpts { buildImageName = nameTag
784− , buildDockerfileName = "Dockerfile"
785− , buildQuiet = False
786− , buildNoCache = False
787− , buildRemoveItermediate = True
788− , buildForceRemoveIntermediate = False
789− , buildPullParent = False
790− }
791−
792721-- | Default options for deleting a container. Most of the time we DON'T
793722-- want to delete the container's volumes or force delete it if it's
794723-- running.
795−defaultContainerDeleteOpts :: ContainerDeleteOpts
796−defaultContainerDeleteOpts = ContainerDeleteOpts { deleteVolumes = False, force = False }
797−
798−-- | Image delete opts
799−data ImageDeleteOpts = ImageDeleteOpts deriving (Eq, Show)
800−
801−-- | Sane image deletion defaults
802−defaultImageDeleteOpts :: ImageDeleteOpts
803−defaultImageDeleteOpts = ImageDeleteOpts
724+defaultDeleteOpts :: DeleteOpts
725+defaultDeleteOpts = DeleteOpts { deleteVolumes = False, force = False }
804726
805727-- | Timestamp alias.
806728type Timestamp = Integer
@@ -828,50 +750,18 @@ defaultLogOpts = LogOpts { stdout = True
828750 , tail = All
829751 }
830752
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)
839−
840−-- | Sensible defalut for create network options
841−defaultCreateNetworkOpts :: Text -> CreateNetworkOpts
842−defaultCreateNetworkOpts name =
843− CreateNetworkOpts
844− { createNetworkName = name
845− , createNetworkCheckDuplicate = False
846− , createNetworkDriver = "bridge"
847− , createNetworkInternal = True
848− , createNetworkEnableIPv6 = False
849− }
850−
851−instance ToJSON CreateNetworkOpts where
852− toJSON opts =
853− object
854− [ "Name" .= createNetworkName opts
855− , "CheckDuplicate" .= createNetworkCheckDuplicate opts
856− , "Driver" .= createNetworkDriver opts
857− , "Internal" .= createNetworkInternal opts
858− , "EnableIPv6" .= createNetworkEnableIPv6 opts
859− ]
860−
861753-- TOOD: Add support for SELinux Volume labels (eg. "ro,z" or "ro/Z")
862754-- | Set permissions on volumes that you mount in the container.
863755data VolumePermission = ReadWrite | ReadOnly deriving (Eq, Show, Generic)
864756
865757instance ToJSON VolumePermission where
866758 toJSON ReadWrite = "rw"
867− toJSON ReadOnly = "ro"
759+ toJSON ReadOnly = "ro"
868760
869761instance FromJSON VolumePermission where
870762 parseJSON "rw" = return ReadWrite
871763 parseJSON "ro" = return ReadOnly
872− parseJSON "RW" = return ReadWrite
873− parseJSON "RO" = return ReadOnly
874− parseJSON _ = fail "Failed to parse VolumePermission"
764+ parseJSON _ = fail "Failed to parse VolumePermission"
875765
876766-- | Used for marking a directory in the container as "exposed" hence
877767-- taking it outside of the COW filesystem and making it mountable
@@ -893,8 +783,8 @@ instance {-# OVERLAPPING #-} ToJSON [Volume] where
893783
894784instance {-# OVERLAPPING #-} FromJSON [Volume] where
895785 parseJSON (JSON.Object o) = return $ map (Volume . T.unpack) $ HM.keys o
896− parseJSON (JSON.Null) = return []
897− parseJSON _ = fail "Volume is not an object"
786+ parseJSON (JSON.Null) = return []
787+ parseJSON _ = fail "Volume is not an object"
898788
899789
900790data Bind = Bind { hostSrc :: Text
@@ -904,10 +794,10 @@ data Bind = Bind { hostSrc :: Text
904794
905795instance FromJSON Bind where
906796 parseJSON (JSON.String t) = case T.split (== ':') t of
907− [src, dest] -> return $ Bind src dest Nothing
797+ [src, dest] -> return $ Bind src dest Nothing
908798 [src, dest, "rw"] -> return $ Bind src dest $ Just ReadWrite
909799 [src, dest, "ro"] -> return $ Bind src dest $ Just ReadOnly
910− _ -> fail "Could not parse Bind"
800+ _ -> fail "Could not parse Bind"
911801 parseJSON _ = fail "Bind is not a string"
912802
913803data Device = Device {
@@ -930,15 +820,15 @@ data VolumeFrom = VolumeFrom ContainerName (Maybe VolumePermission) deriving (Eq
930820
931821instance FromJSON VolumeFrom where
932822 parseJSON (JSON.String t) = case T.split (== ':') t of
933− [vol] -> return $ VolumeFrom vol Nothing
823+ [vol] -> return $ VolumeFrom vol Nothing
934824 [vol, "rw"] -> return $ VolumeFrom vol $ Just ReadWrite
935825 [vol, "ro"] -> return $ VolumeFrom vol $ Just ReadOnly
936− _ -> fail "Could not parse VolumeFrom"
826+ _ -> fail "Could not parse VolumeFrom"
937827 parseJSON _ = fail "VolumeFrom is not a string"
938828
939829instance ToJSON VolumeFrom where
940830 toJSON (VolumeFrom n p) = case p of
941− Nothing -> toJSON $ n <> ":" <> "rw"
831+ Nothing -> toJSON $ n <> ":" <> "rw"
942832 Just per -> toJSON $ n <> ":" <> (T.pack $ show per)
943833
944834instance ToJSON Bind where
@@ -950,40 +840,40 @@ data Link = Link Text (Maybe Text) deriving (Eq, Show)
950840
951841instance FromJSON Link where
952842 parseJSON (JSON.String t) = case T.split (== ':') t of
953− [f] -> return $ Link f Nothing
843+ [f] -> return $ Link f Nothing
954844 [f,s] -> return $ Link f $ Just s
955− _ -> fail "Could not parse Link"
845+ _ -> fail "Could not parse Link"
956846 parseJSON _ = fail "Link is not a string"
957847
958848instance ToJSON Link where
959849 toJSON (Link n1 n2) = toJSON $ case n2 of
960850 Nothing -> T.concat[n1, ":", n1] -- use same name in container
961− Just n -> T.concat[n1, ":", n] -- used specified name in container
851+ Just n -> T.concat[n1, ":", n] -- used specified name in container
962852
963853-- { "Type": "<driver_name>", "Config": {"key1": "val1"} }
964854data LogDriverType = JsonFile | Syslog | Journald | Gelf | Fluentd | AwsLogs | Splunk | Etwlogs | LoggingDisabled deriving (Eq, Show)
965855
966856instance FromJSON LogDriverType where
967857 parseJSON (JSON.String "json-file") = return JsonFile
968− parseJSON (JSON.String "syslog") = return Syslog
969− parseJSON (JSON.String "journald") = return Journald
970− parseJSON (JSON.String "gelf") = return Gelf
971− parseJSON (JSON.String "fluentd") = return Fluentd
972− parseJSON (JSON.String "awslogs") = return AwsLogs
973− parseJSON (JSON.String "splunk") = return Splunk
974− parseJSON (JSON.String "etwlogs") = return Etwlogs
975− parseJSON (JSON.String "none") = return LoggingDisabled
976− parseJSON _ = fail "Unknown LogDriverType"
858+ parseJSON (JSON.String "syslog") = return Syslog
859+ parseJSON (JSON.String "journald") = return Journald
860+ parseJSON (JSON.String "gelf") = return Gelf
861+ parseJSON (JSON.String "fluentd") = return Fluentd
862+ parseJSON (JSON.String "awslogs") = return AwsLogs
863+ parseJSON (JSON.String "splunk") = return Splunk
864+ parseJSON (JSON.String "etwlogs") = return Etwlogs
865+ parseJSON (JSON.String "none") = return LoggingDisabled
866+ parseJSON _ = fail "Unknown LogDriverType"
977867
978868instance ToJSON LogDriverType where
979− toJSON JsonFile = JSON.String "json-file"
980− toJSON Syslog = JSON.String "syslog"
981− toJSON Journald = JSON.String "journald"
982− toJSON Gelf = JSON.String "gelf"
983− toJSON Fluentd = JSON.String "fluentd"
984− toJSON AwsLogs = JSON.String "awslogs"
985− toJSON Splunk = JSON.String "splunk"
986− toJSON Etwlogs = JSON.String "etwlogs"
869+ toJSON JsonFile = JSON.String "json-file"
870+ toJSON Syslog = JSON.String "syslog"
871+ toJSON Journald = JSON.String "journald"
872+ toJSON Gelf = JSON.String "gelf"
873+ toJSON Fluentd = JSON.String "fluentd"
874+ toJSON AwsLogs = JSON.String "awslogs"
875+ toJSON Splunk = JSON.String "splunk"
876+ toJSON Etwlogs = JSON.String "etwlogs"
987877 toJSON LoggingDisabled = JSON.String "none"
988878
989879data LogDriverOption = LogDriverOption Name Value deriving (Eq, Show)
@@ -1017,41 +907,19 @@ instance FromJSON LogDriverConfig where
1017907 parseJSON _ = fail "LogDriverConfig is not an object"
1018908
1019909-- TODO: Add container:<name|id> mode
1020−data NetworkMode = NetworkBridge | NetworkHost | NetworkDisabled | NetworkNamed Text
910+data NetworkMode = Bridge | Host | NetworkDisabled
1021911 deriving (Eq, Show, Ord)
1022912
1023913instance FromJSON NetworkMode where
1024− parseJSON (JSON.String "bridge") = return NetworkBridge
1025− parseJSON (JSON.String "host") = return NetworkHost -- Note: Guessing on these.
1026− parseJSON (JSON.String "none") = return NetworkDisabled
1027− parseJSON (JSON.String n) = return $ NetworkNamed n
1028− parseJSON _ = fail "Unknown NetworkMode"
914+ parseJSON (JSON.String "bridge") = return Bridge
915+ parseJSON (JSON.String "host") = return Host -- Note: Guessing on these.
916+ parseJSON (JSON.String "none") = return NetworkDisabled
917+ parseJSON _ = fail "Unknown NetworkMode"
1029918
1030919instance ToJSON NetworkMode where
1031− toJSON NetworkBridge = JSON.String "bridge"
1032− toJSON NetworkHost = JSON.String "host"
920+ toJSON Bridge = JSON.String "bridge"
921+ toJSON Host = JSON.String "host"
1033922 toJSON NetworkDisabled = JSON.String "none"
1034− toJSON (NetworkNamed n) = JSON.String n
1035−
1036−newtype NetworkID = NetworkID Text
1037− deriving (Eq, Show)
1038−
1039−-- | Used for extracting the id of the container from the newtype
1040−fromNetworkID :: NetworkID -> Text
1041−fromNetworkID (NetworkID t) = t
1042−
1043−-- | Used for parsing a Text value into a NetworkID.
1044−toNetworkID :: Text -> Maybe NetworkID
1045−toNetworkID t = Just $ NetworkID t
1046−
1047−instance FromJSON NetworkID where
1048− parseJSON (JSON.Object o) = do
1049− nid <- o .: "Id"
1050− return $ NetworkID nid
1051− parseJSON _ = fail "NetworkID is not an object."
1052−
1053−instance ToJSON NetworkID where
1054− toJSON (NetworkID nid) = object ["Id" .= nid]
1055923
1056924data PortType = TCP | UDP deriving (Eq, Generic, Read, Ord)
1057925
@@ -1067,7 +935,7 @@ instance FromJSON PortType where
1067935 parseJSON val = case val of
1068936 "tcp" -> return TCP
1069937 "udp" -> return UDP
1070− _ -> fail "PortType: Invalid port type."
938+ _ -> fail "PortType: Invalid port type."
1071939
1072940-- newtype NetworkInterface = NetworkInterface Text deriving (Eq, Show)
1073941--
@@ -1197,7 +1065,7 @@ instance FromJSON RestartPolicy where
11971065 "on-failure" -> do
11981066 retry <- o .: "MaximumRetryCount"
11991067 return $ RestartOnFailure retry
1200− "no" -> return RestartOff
1068+ "off" -> return RestartOff
12011069 _ -> fail "Could not parse RestartPolicy"
12021070 parseJSON _ = fail "RestartPolicy is not an object"
12031071
@@ -1205,7 +1073,7 @@ instance ToJSON RestartPolicy where
12051073 toJSON RestartAlways = object ["Name" .= JSON.String "always"]
12061074 toJSON RestartUnlessStopped = object ["Name" .= JSON.String "unless-stopped"]
12071075 toJSON (RestartOnFailure c) = object ["Name" .= JSON.String "on-failure", "MaximumRetryCount" .= c]
1208− toJSON RestartOff = object ["Name" .= JSON.String "no"]
1076+ toJSON RestartOff = object ["Name" .= JSON.String "off"]
12091077
12101078data Isolation = Default | Process | Hyperv deriving (Eq, Show)
12111079
@@ -1383,7 +1251,7 @@ data MemoryConstraintSize = B | MB | GB deriving (Eq, Show)
13831251data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
13841252
13851253instance ToJSON MemoryConstraint where
1386− toJSON (MemoryConstraint x B) = toJSON x
1254+ toJSON (MemoryConstraint x B) = toJSON x
13871255 toJSON (MemoryConstraint x MB) = toJSON $ x * 1024 * 1024
13881256 toJSON (MemoryConstraint x GB) = toJSON $ x * 1024 * 1024 * 1024
13891257
@@ -1414,7 +1282,7 @@ data ContainerResources = ContainerResources {
14141282 , memoryReservation :: Maybe MemoryConstraint
14151283 , memorySwap :: Maybe MemoryConstraint
14161284 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1417− , oomKillDisable :: Maybe Bool
1285+ , oomKillDisable :: Bool
14181286 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
14191287 , ulimits :: [Ulimit]
14201288 -- TODO: Missing from 1.24
@@ -1452,7 +1320,7 @@ instance FromJSON EnvVar where
14521320 parseJSON _ = fail "EnvVar is not a string"
14531321
14541322instance ToJSON EnvVar where
1455− toJSON (EnvVar n v) = JSON.String $ n <> T.pack "=" <> v
1323+ toJSON (EnvVar n v) = object [n .= v]
14561324
14571325-- | ExposedPort represents a port (and it's type)
14581326-- that a container should expose to other containers or the host system.
@@ -1492,21 +1360,6 @@ instance {-# OVERLAPPING #-} ToJSON [ExposedPort] where
14921360 where key (ExposedPort p t) = show p <> slash <> show t
14931361 slash = T.unpack "/"
14941362
1495−data Entrypoint = Entrypoint [T.Text] deriving (Eq, Show, Generic)
1496−
1497−instance ToJSON Entrypoint where
1498− toJSON (Entrypoint (e:es)) = toJSON (e:es)
1499− toJSON (Entrypoint []) = JSON.Null
1500−
1501−instance FromJSON Entrypoint where
1502− parseJSON (JSON.String e) = return $ Entrypoint [e]
1503− parseJSON (JSON.Array ar) = do
1504− arr <- mapM parseJSON (V.toList ar)
1505− return $ Entrypoint arr
1506− parseJSON JSON.Null = return $ Entrypoint []
1507− parseJSON _ = fail "Failed to parse Entrypoint"
1508−
1509−
15101363data ContainerConfig = ContainerConfig {
15111364 hostname :: Maybe Text
15121365 , domainname :: Maybe Text
@@ -1525,7 +1378,7 @@ data ContainerConfig = ContainerConfig {
15251378 , image :: Text
15261379 , volumes :: [Volume]
15271380 , workingDir :: Maybe FilePath
1528− , entrypoint :: Entrypoint
1381+ , entrypoint :: Maybe Text -- Can be null?
15291382 , networkDisabled :: Maybe Bool -- Note: Should we expand the JSON instance and take away the Maybe? Null is False?
15301383 , macAddress :: Maybe Text
15311384 -- , onBuild :: Maybe Text -- For 1.24, only see this in the inspect response.
@@ -1533,7 +1386,6 @@ data ContainerConfig = ContainerConfig {
15331386 , stopSignal :: Signal
15341387 } deriving (Eq, Show, Generic)
15351388
1536−
15371389instance ToJSON ContainerConfig where
15381390 toJSON = genericToJSON defaultOptions {
15391391 fieldLabelModifier = (\(x:xs) -> toUpper x : xs)}
@@ -1555,7 +1407,7 @@ instance FromJSON ContainerConfig where
15551407 image <- o .: "Image"
15561408 volumes <- o .: "Volumes"
15571409 workingDir <- o .:? "WorkingDir"
1558− entrypoint <- o .: "Entrypoint"
1410+ entrypoint <- o .:? "Entrypoint"
15591411 networkDisabled <- o .:? "networkDisabled"
15601412 macAddress <- o .:? "MacAddress"
15611413 labels <- o .:? "Labels" .!= []
@@ -1564,11 +1416,7 @@ instance FromJSON ContainerConfig where
15641416 macAddress labels stopSignal
15651417 parseJSON _ = fail "NetworkSettings is not an object."
15661418
1567−#if MIN_VERSION_base(4,13,0)
1568−parseIntegerText :: (MonadFail m) => Text -> m Integer
1569−#else
15701419parseIntegerText :: (Monad m) => Text -> m Integer
1571−#endif
15721420parseIntegerText t = case readMaybe $ T.unpack t of
15731421 Nothing ->
15741422 fail "Could not parse Integer"
@@ -1590,3 +1438,4 @@ toJsonKeyVal vs getKey getVal = JSON.Object $ foldl f HM.empty vs
15901438-- | Helper function that return an empty dictionary "{}"
15911439emptyJsonObject :: JSON.Value
15921440emptyJsonObject = JSON.Object HM.empty
1441+