summaryrefslogtreecommitdiff
path: root/src/Propellor/Property
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/Property')
-rw-r--r--src/Propellor/Property/Chroot.hs57
-rw-r--r--src/Propellor/Property/Docker.hs23
2 files changed, 67 insertions, 13 deletions
diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs
new file mode 100644
index 00000000..e5046937
--- /dev/null
+++ b/src/Propellor/Property/Chroot.hs
@@ -0,0 +1,57 @@
+module Propellor.Property.Chroot (
+ Chroot,
+ chroot,
+ provisioned,
+) where
+
+import Propellor
+import qualified Propellor.Property.Debootstrap as Debootstrap
+
+import qualified Data.Map as M
+
+data Chroot = Chroot FilePath System Host
+
+instance Hostlike Chroot where
+ (Chroot l s h) & p = Chroot l s (h & p)
+ (Chroot l s h) &^ p = Chroot l s (h &^ p)
+ getHost (Chroot _ _ h) = h
+
+-- | Defines a Chroot at the given location, containing the specified
+-- System. Properties can be added to configure the Chroot.
+--
+-- > chroot "/srv/chroot/ghc-dev" (System (Debian Unstable) "amd64"
+-- > & Apt.installed ["build-essential", "ghc", "haskell-platform"]
+-- > & ...
+chroot :: FilePath -> System -> Chroot
+chroot location system = Chroot location system (Host location [] mempty)
+
+-- | Ensures that the chroot exists and is provisioned according to its
+-- properties.
+--
+-- Reverting this property removes the chroot. Note that it does not ensure
+-- that any processes that might be running inside the chroot are stopped.
+provisioned :: Chroot -> RevertableProperty
+provisioned c@(Chroot loc system _) = RevertableProperty
+ (propigateChrootInfo c (go "exists" setup))
+ (go "removed" teardown)
+ where
+ go desc a = property ("chroot " ++ loc ++ " " ++ desc) $ do
+ ensureProperties [a]
+
+ setup = provisionChroot c `requires` built
+
+ built = case system of
+ (System (Debian _) _) -> debootstrap
+ (System (Ubuntu _) _) -> debootstrap
+
+ debootstrap = unrevertable (Debootstrap.built loc system [])
+
+ teardown = undefined
+
+propigateChrootInfo :: Chroot -> Property -> Property
+propigateChrootInfo c@(Chroot loc _ h) p = propigateInfo c p (<> chrootinfo)
+ where
+ chrootinfo = mempty $ mempty { _chroots = M.singleton loc h }
+
+provisionChroot :: Chroot -> Property
+provisionChroot = undefined
diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs
index 676d323a..92cc124a 100644
--- a/src/Propellor/Property/Docker.hs
+++ b/src/Propellor/Property/Docker.hs
@@ -52,7 +52,6 @@ import System.Posix.Process
import Prelude hiding (init)
import Data.List hiding (init)
import Data.List.Utils
-import qualified Data.Set as S
import qualified Data.Map as M
installed :: Property
@@ -78,8 +77,10 @@ data Container = Container Image Host
instance Hostlike Container where
(Container i h) & p = Container i (h & p)
(Container i h) &^ p = Container i (h &^ p)
+ getHost (Container _ h) = h
--- | Builds a Container with a given name, image, and properties.
+-- | Defines a Container with a given name, image, and properties.
+-- Properties can be added to configure the Container.
--
-- > container "web-server" "debian"
-- > & publish "80:80"
@@ -100,11 +101,9 @@ container cn image = Container image (Host cn [] info)
--
-- Reverting this property ensures that the container is stopped and
-- removed.
-docked
- :: Container
- -> RevertableProperty
+docked :: Container -> RevertableProperty
docked ctr@(Container _ h) = RevertableProperty
- (propigateInfo ctr (go "docked" setup))
+ (propigateContainerInfo ctr (go "docked" setup))
(go "undocked" teardown)
where
cn = hostName h
@@ -131,14 +130,12 @@ docked ctr@(Container _ h) = RevertableProperty
]
]
-propigateInfo :: Container -> Property -> Property
-propigateInfo (Container _ h@(Host hn _ containerinfo)) p =
- combineProperties (propertyDesc p) $ p' : dnsprops ++ privprops
+propigateContainerInfo :: Container -> Property -> Property
+propigateContainerInfo ctr@(Container _ h) p =
+ propigateInfo ctr p (<> dockerinfo)
where
- p' = p { propertyInfo = propertyInfo p <> dockerinfo }
- dockerinfo = dockerInfo $ mempty { _dockerContainers = M.singleton hn h }
- dnsprops = map addDNS (S.toList $ _dns containerinfo)
- privprops = map addPrivDataField (S.toList $ _privDataFields containerinfo)
+ dockerinfo = dockerInfo $
+ mempty { _dockerContainers = M.singleton (hostName h) h }
mkContainerInfo :: ContainerId -> Container -> ContainerInfo
mkContainerInfo cid@(ContainerId hn _cn) (Container img h) =