@@ -41,7 +41,7 @@ module Docker.Client.Types (
41 , defaultLogOpts
41 , defaultLogOpts
42 , VolumePermission(..)
42 , VolumePermission(..)
43 , Bind(..)
43 , Bind(..)
44− , Volumes(..)
44+ , Volume(..)
45 , Device(..)
45 , Device(..)
46 , ContainerName
46 , ContainerName
47 , VolumeFrom(..)
47 , VolumeFrom(..)
@@ -79,6 +79,10 @@ module Docker.Client.Types (
79 , DeviceRate(..)
79 , DeviceRate(..)
80 , addPortBinding
80 , addPortBinding
84import Data.Aeson (FromJSON, ToJSON, genericParseJSON,
88import Data.Aeson (FromJSON, ToJSON, genericParseJSON,
@@ -595,7 +599,7 @@ defaultContainerConfig imageName = ContainerConfig {
595 , stdinOnce=False
599 , stdinOnce=False
598− , volumes=Nothing
602+ , volumes=[]
599 , workingDir=Nothing
603 , workingDir=Nothing
600 , entrypoint=Nothing
604 , entrypoint=Nothing
601 , networkDisabled=Nothing
605 , networkDisabled=Nothing
@@ -732,16 +736,24 @@ instance FromJSON VolumePermission where
732-- docker run --name app -v \/opt\/data -it myapp:latest
736-- docker run --name app -v \/opt\/data -it myapp:latest
733-- docker run --name app2 --volumes-from app \/bin\/bash -c "ls -l \/opt\/data"
737-- docker run --name app2 --volumes-from app \/bin\/bash -c "ls -l \/opt\/data"
735−newtype Volumes = Volumes [FilePath] deriving (Eq, Show)
739+newtype Volume = Volume FilePath deriving (Eq, Show)
741+instance ToJSON Volume where
742+ toJSON (Volume fp) = JSON.Object $ HM.insert (T.pack fp) (JSON.Object HM.empty) HM.empty
737−instance FromJSON Volumes where
744+instance FromJSON Volume where
738− parseJSON (JSON.Object o) = return $ Volumes $ map T.unpack $ HM.keys o
745+ parseJSON (JSON.Object o) = return $ Volume $ T.unpack $ head $ HM.keys o
746+ parseJSON _ = fail "Volume is not an object"
748+instance ToJSON [Volume] where
749+ toJSON [] = JSON.Object HM.empty
750+ toJSON (v:vs) = JSON.Object $ foldl f HM.empty (v:vs)
751+ where f acc (Volume k) = HM.insert (T.pack k) (JSON.Object HM.empty) acc
753+instance FromJSON [Volume] where
754+ parseJSON (JSON.Object o) = return $ map (Volume . T.unpack) $ HM.keys o
739− parseJSON _ = fail "Volumes is not an object"
755+ parseJSON _ = fail "Volume is not an object"
741−instance ToJSON Volumes where
742− toJSON (Volumes []) = JSON.Object HM.empty
743− toJSON (Volumes (v:vs)) = JSON.Object $ foldl f HM.empty (v:vs)
744− where f acc k = HM.insert (T.pack k) (JSON.Object HM.empty) acc
746data Bind = Bind { hostSrc :: Text
758data Bind = Bind { hostSrc :: Text
747 , containerDest :: Text
759 , containerDest :: Text
@@ -933,6 +945,33 @@ addBind b c = c{hostConfig=hc{binds=obs <> [b]}}
933 where hc = hostConfig c
945 where hc = hostConfig c
934 obs = binds $ hostConfig c
946 obs = binds $ hostConfig c
948+-- | Helper function for adding a Command to and existing
949+-- CreateOpts record.
950+setCmd :: Text -> CreateOpts -> CreateOpts
951+setCmd ccmd c = c{containerConfig=cc{cmd=[ccmd]}}
952+ where cc = containerConfig c
954+-- | Helper function for adding a "Link" to and existing
955+-- CreateOpts record.
956+addLink :: Link -> CreateOpts -> CreateOpts
957+addLink l c = c{hostConfig=hc{links=ols <> [l]}}
958+ where hc = hostConfig c
959+ ols = links $ hostConfig c
961+-- | Helper function for adding a "Volume" to and existing
962+-- CreateOpts record.
963+addVolume :: Volume -> CreateOpts -> CreateOpts
964+addVolume v c = c{containerConfig=cc{volumes=oldvs <> [v]}}
965+ where cc = containerConfig c
968+-- | Helper function for adding a "VolumeFrom" to and existing
969+-- CreateOpts record.
970+addVolumeFrom :: VolumeFrom -> CreateOpts -> CreateOpts
971+addVolumeFrom vf c = c{hostConfig=hc{volumesFrom=oldvfs <> [vf]}}
972+ where hc = hostConfig c
973+ oldvfs = volumesFrom hc
936-- | A convenience function that adds PortBindings to and exiting
975-- | A convenience function that adds PortBindings to and exiting
937-- "CreateOpts" record. Useful with 'defaultCreateOpts'
976-- "CreateOpts" record. Useful with 'defaultCreateOpts'
938-- Example:
977-- Example:
@@ -1295,7 +1334,7 @@ data ContainerConfig = ContainerConfig {
1295 , cmd :: [Text]
1334 , cmd :: [Text]
1296 -- , argsEscaped :: Bool -- Don't see this in 1.24
1335 -- , argsEscaped :: Bool -- Don't see this in 1.24
1297 , image :: Text
1336 , image :: Text
1298− , volumes :: Maybe Volumes
1337+ , volumes :: [Volume]
1299 , workingDir :: Maybe FilePath
1338 , workingDir :: Maybe FilePath
1300 , entrypoint :: Maybe Text -- Can be null?
1339 , entrypoint :: Maybe Text -- Can be null?
1301 , networkDisabled :: Maybe Bool -- Note: Should we expand the JSON instance and take away the Maybe? Null is False?
1340 , networkDisabled :: Maybe Bool -- Note: Should we expand the JSON instance and take away the Maybe? Null is False?