add debootstrap parameters
This commit is contained in:
parent
fbce215f33
commit
9e611d87cd
|
@ -86,12 +86,12 @@ clam = standardSystem "clam.kitenet.net" Unstable "amd64"
|
||||||
& Systemd.nspawned meow
|
& Systemd.nspawned meow
|
||||||
|
|
||||||
meow :: Systemd.Container
|
meow :: Systemd.Container
|
||||||
meow = Systemd.container "meow" (System (Debian Unstable) "amd64")
|
meow = Systemd.container "meow" (Chroot.debootstrapped (System (Debian Unstable) "amd64") mempty)
|
||||||
& Apt.serviceInstalledRunning "uptimed"
|
& Apt.serviceInstalledRunning "uptimed"
|
||||||
& alias "meow.kitenet.net"
|
& alias "meow.kitenet.net"
|
||||||
|
|
||||||
testChroot :: Chroot.Chroot
|
testChroot :: Chroot.Chroot
|
||||||
testChroot = Chroot.chroot "/tmp/chroot" (System (Debian Unstable) "amd64")
|
testChroot = Chroot.debootstrapped (System (Debian Unstable) "amd64") mempty "/tmp/chroot"
|
||||||
& File.hasContent "/foo" ["hello"]
|
& File.hasContent "/foo" ["hello"]
|
||||||
|
|
||||||
orca :: Host
|
orca :: Host
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Propellor.Property.Chroot (
|
module Propellor.Property.Chroot (
|
||||||
Chroot(..),
|
Chroot(..),
|
||||||
chroot,
|
debootstrapped,
|
||||||
provisioned,
|
provisioned,
|
||||||
-- * Internal use
|
-- * Internal use
|
||||||
provisioned',
|
provisioned',
|
||||||
|
@ -18,23 +18,33 @@ import qualified Data.Map as M
|
||||||
import Data.List.Utils
|
import Data.List.Utils
|
||||||
import System.Posix.Directory
|
import System.Posix.Directory
|
||||||
|
|
||||||
data Chroot = Chroot FilePath System Host
|
data Chroot = Chroot FilePath System BuilderConf Host
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
|
data BuilderConf
|
||||||
|
= UsingDeboostrap Debootstrap.DebootstrapConfig
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
instance Hostlike Chroot where
|
instance Hostlike Chroot where
|
||||||
(Chroot l s h) & p = Chroot l s (h & p)
|
(Chroot l s c h) & p = Chroot l s c (h & p)
|
||||||
(Chroot l s h) &^ p = Chroot l s (h &^ p)
|
(Chroot l s c h) &^ p = Chroot l s c (h &^ p)
|
||||||
getHost (Chroot _ _ h) = h
|
getHost (Chroot _ _ _ h) = h
|
||||||
|
|
||||||
-- | Defines a Chroot at the given location, containing the specified
|
-- | Defines a Chroot at the given location, built with debootstrap.
|
||||||
-- System. Properties can be added to configure the Chroot.
|
|
||||||
--
|
--
|
||||||
-- > chroot "/srv/chroot/ghc-dev" (System (Debian Unstable) "amd64")
|
-- Properties can be added to configure the Chroot.
|
||||||
-- > & Apt.installed ["build-essential", "ghc", "haskell-platform"]
|
--
|
||||||
|
-- > debootstrapped (System (Debian Unstable) "amd64") Debootstrap.BuildD "/srv/chroot/ghc-dev"
|
||||||
|
-- > & Apt.installed ["ghc", "haskell-platform"]
|
||||||
-- > & ...
|
-- > & ...
|
||||||
chroot :: FilePath -> System -> Chroot
|
debootstrapped :: System -> Debootstrap.DebootstrapConfig -> FilePath -> Chroot
|
||||||
chroot location system = Chroot location system (Host location [] mempty)
|
debootstrapped system conf location = case system of
|
||||||
& os system
|
(System (Debian _) _) -> mk
|
||||||
|
(System (Ubuntu _) _) -> mk
|
||||||
|
where
|
||||||
|
h = Host location [] mempty
|
||||||
|
mk = Chroot location system (UsingDeboostrap conf) h
|
||||||
|
& os system
|
||||||
|
|
||||||
-- | Ensures that the chroot exists and is provisioned according to its
|
-- | Ensures that the chroot exists and is provisioned according to its
|
||||||
-- properties.
|
-- properties.
|
||||||
|
@ -45,7 +55,7 @@ provisioned :: Chroot -> RevertableProperty
|
||||||
provisioned c = provisioned' (propigateChrootInfo c) c
|
provisioned c = provisioned' (propigateChrootInfo c) c
|
||||||
|
|
||||||
provisioned' :: (Property -> Property) -> Chroot -> RevertableProperty
|
provisioned' :: (Property -> Property) -> Chroot -> RevertableProperty
|
||||||
provisioned' propigator c@(Chroot loc system _) = RevertableProperty
|
provisioned' propigator c@(Chroot loc system builderconf _) = RevertableProperty
|
||||||
(propigator $ go "exists" setup)
|
(propigator $ go "exists" setup)
|
||||||
(go "removed" teardown)
|
(go "removed" teardown)
|
||||||
where
|
where
|
||||||
|
@ -53,11 +63,11 @@ provisioned' propigator c@(Chroot loc system _) = RevertableProperty
|
||||||
|
|
||||||
setup = propellChroot c (inChrootProcess c) `requires` toProp built
|
setup = propellChroot c (inChrootProcess c) `requires` toProp built
|
||||||
|
|
||||||
built = case system of
|
built = case (system, builderconf) of
|
||||||
(System (Debian _) _) -> debootstrap
|
((System (Debian _) _), UsingDeboostrap cf) -> debootstrap cf
|
||||||
(System (Ubuntu _) _) -> debootstrap
|
((System (Ubuntu _) _), UsingDeboostrap cf) -> debootstrap cf
|
||||||
|
|
||||||
debootstrap = Debootstrap.built loc system []
|
debootstrap = Debootstrap.built loc system
|
||||||
|
|
||||||
teardown = toProp (revert built)
|
teardown = toProp (revert built)
|
||||||
|
|
||||||
|
@ -65,12 +75,12 @@ propigateChrootInfo :: Chroot -> Property -> Property
|
||||||
propigateChrootInfo c p = propigateInfo c p (<> chrootInfo c)
|
propigateChrootInfo c p = propigateInfo c p (<> chrootInfo c)
|
||||||
|
|
||||||
chrootInfo :: Chroot -> Info
|
chrootInfo :: Chroot -> Info
|
||||||
chrootInfo (Chroot loc _ h) =
|
chrootInfo (Chroot loc _ _ h) =
|
||||||
mempty { _chrootinfo = mempty { _chroots = M.singleton loc h } }
|
mempty { _chrootinfo = mempty { _chroots = M.singleton loc h } }
|
||||||
|
|
||||||
-- | Propellor is run inside the chroot to provision it.
|
-- | Propellor is run inside the chroot to provision it.
|
||||||
propellChroot :: Chroot -> ([String] -> CreateProcess) -> Property
|
propellChroot :: Chroot -> ([String] -> CreateProcess) -> Property
|
||||||
propellChroot c@(Chroot loc _ _) mkproc = property (chrootDesc c "provisioned") $ do
|
propellChroot c@(Chroot loc _ _ _) mkproc = property (chrootDesc c "provisioned") $ do
|
||||||
let d = localdir </> shimdir c
|
let d = localdir </> shimdir c
|
||||||
let me = localdir </> "propellor"
|
let me = localdir </> "propellor"
|
||||||
shim <- liftIO $ ifM (doesDirectoryExist d)
|
shim <- liftIO $ ifM (doesDirectoryExist d)
|
||||||
|
@ -105,7 +115,7 @@ propellChroot c@(Chroot loc _ _) mkproc = property (chrootDesc c "provisioned")
|
||||||
processChainOutput
|
processChainOutput
|
||||||
|
|
||||||
toChain :: HostName -> Chroot -> IO CmdLine
|
toChain :: HostName -> Chroot -> IO CmdLine
|
||||||
toChain parenthost (Chroot loc _ _) = do
|
toChain parenthost (Chroot loc _ _ _) = do
|
||||||
onconsole <- isConsole <$> mkMessageHandle
|
onconsole <- isConsole <$> mkMessageHandle
|
||||||
return $ ChrootChain parenthost loc onconsole
|
return $ ChrootChain parenthost loc onconsole
|
||||||
|
|
||||||
|
@ -124,16 +134,16 @@ chain hostlist hn loc onconsole = case findHostNoAlias hostlist hn of
|
||||||
putStrLn $ "\n" ++ show r
|
putStrLn $ "\n" ++ show r
|
||||||
|
|
||||||
inChrootProcess :: Chroot -> [String] -> CreateProcess
|
inChrootProcess :: Chroot -> [String] -> CreateProcess
|
||||||
inChrootProcess (Chroot loc _ _) cmd = proc "chroot" (loc:cmd)
|
inChrootProcess (Chroot loc _ _ _) cmd = proc "chroot" (loc:cmd)
|
||||||
|
|
||||||
provisioningLock :: FilePath -> FilePath
|
provisioningLock :: FilePath -> FilePath
|
||||||
provisioningLock containerloc = "chroot" </> mungeloc containerloc ++ ".lock"
|
provisioningLock containerloc = "chroot" </> mungeloc containerloc ++ ".lock"
|
||||||
|
|
||||||
shimdir :: Chroot -> FilePath
|
shimdir :: Chroot -> FilePath
|
||||||
shimdir (Chroot loc _ _) = "chroot" </> mungeloc loc ++ ".shim"
|
shimdir (Chroot loc _ _ _) = "chroot" </> mungeloc loc ++ ".shim"
|
||||||
|
|
||||||
mungeloc :: FilePath -> String
|
mungeloc :: FilePath -> String
|
||||||
mungeloc = replace "/" "_"
|
mungeloc = replace "/" "_"
|
||||||
|
|
||||||
chrootDesc :: Chroot -> String -> String
|
chrootDesc :: Chroot -> String -> String
|
||||||
chrootDesc (Chroot loc _ _) desc = "chroot " ++ loc ++ " " ++ desc
|
chrootDesc (Chroot loc _ _ _) desc = "chroot " ++ loc ++ " " ++ desc
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module Propellor.Property.Debootstrap (
|
module Propellor.Property.Debootstrap (
|
||||||
Url,
|
Url,
|
||||||
|
DebootstrapConfig(..),
|
||||||
built,
|
built,
|
||||||
installed,
|
installed,
|
||||||
programPath,
|
programPath,
|
||||||
|
@ -18,6 +19,27 @@ import System.Posix.Directory
|
||||||
|
|
||||||
type Url = String
|
type Url = String
|
||||||
|
|
||||||
|
-- | A monoid for debootstrap configuration.
|
||||||
|
-- mempty is a default debootstrapped system.
|
||||||
|
data DebootstrapConfig
|
||||||
|
= DefaultConfig
|
||||||
|
| MinBase
|
||||||
|
| BuilddD
|
||||||
|
| DebootstrapParam String
|
||||||
|
| DebootstrapConfig :+ DebootstrapConfig
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
|
instance Monoid DebootstrapConfig where
|
||||||
|
mempty = DefaultConfig
|
||||||
|
mappend = (:+)
|
||||||
|
|
||||||
|
toParams :: DebootstrapConfig -> [CommandParam]
|
||||||
|
toParams DefaultConfig = []
|
||||||
|
toParams MinBase = [Param "--variant=minbase"]
|
||||||
|
toParams BuilddD = [Param "--variant=buildd"]
|
||||||
|
toParams (DebootstrapParam p) = [Param p]
|
||||||
|
toParams (c1 :+ c2) = toParams c1 <> toParams c2
|
||||||
|
|
||||||
-- | Builds a chroot in the given directory using debootstrap.
|
-- | Builds a chroot in the given directory using debootstrap.
|
||||||
--
|
--
|
||||||
-- The System can be any OS and architecture that debootstrap
|
-- The System can be any OS and architecture that debootstrap
|
||||||
|
@ -28,8 +50,8 @@ type Url = String
|
||||||
--
|
--
|
||||||
-- Note that reverting this property does not stop any processes
|
-- Note that reverting this property does not stop any processes
|
||||||
-- currently running in the chroot.
|
-- currently running in the chroot.
|
||||||
built :: FilePath -> System -> [CommandParam] -> RevertableProperty
|
built :: FilePath -> System -> DebootstrapConfig -> RevertableProperty
|
||||||
built target system@(System _ arch) extraparams =
|
built target system@(System _ arch) config =
|
||||||
RevertableProperty setup teardown
|
RevertableProperty setup teardown
|
||||||
where
|
where
|
||||||
setup = check (unpopulated target <||> ispartial) setupprop
|
setup = check (unpopulated target <||> ispartial) setupprop
|
||||||
|
@ -44,7 +66,7 @@ built target system@(System _ arch) extraparams =
|
||||||
suite <- case extractSuite system of
|
suite <- case extractSuite system of
|
||||||
Nothing -> errorMessage $ "don't know how to debootstrap " ++ show system
|
Nothing -> errorMessage $ "don't know how to debootstrap " ++ show system
|
||||||
Just s -> pure s
|
Just s -> pure s
|
||||||
let params = extraparams ++
|
let params = toParams config ++
|
||||||
[ Param $ "--arch=" ++ arch
|
[ Param $ "--arch=" ++ arch
|
||||||
, Param suite
|
, Param suite
|
||||||
, Param target
|
, Param target
|
||||||
|
|
|
@ -23,11 +23,11 @@ type ServiceName = String
|
||||||
|
|
||||||
type MachineName = String
|
type MachineName = String
|
||||||
|
|
||||||
data Container = Container MachineName System Host
|
data Container = Container MachineName Chroot.Chroot Host
|
||||||
|
|
||||||
instance Hostlike Container where
|
instance Hostlike Container where
|
||||||
(Container n s h) & p = Container n s (h & p)
|
(Container n c h) & p = Container n c (h & p)
|
||||||
(Container n s h) &^ p = Container n s (h &^ p)
|
(Container n c h) &^ p = Container n c (h &^ p)
|
||||||
getHost (Container _ _ h) = h
|
getHost (Container _ _ h) = h
|
||||||
|
|
||||||
-- dbus is only a Recommends of systemd, but is needed for communication
|
-- dbus is only a Recommends of systemd, but is needed for communication
|
||||||
|
@ -68,15 +68,19 @@ persistentJournal = check (not <$> doesDirectoryExist dir) $
|
||||||
where
|
where
|
||||||
dir = "/var/log/journal"
|
dir = "/var/log/journal"
|
||||||
|
|
||||||
-- | Defines a container with a given machine name, containing the specified
|
-- | Defines a container with a given machine name.
|
||||||
-- System. Properties can be added to configure the Container.
|
|
||||||
--
|
--
|
||||||
-- > container "webserver" (System (Debian Unstable) "amd64")
|
-- Properties can be added to configure the Container.
|
||||||
|
--
|
||||||
|
-- > container "webserver" (Chroot.debootstrapped (System (Debian Unstable) "amd64") mempty)
|
||||||
-- > & Apt.installedRunning "apache2"
|
-- > & Apt.installedRunning "apache2"
|
||||||
-- > & ...
|
-- > & ...
|
||||||
container :: MachineName -> System -> Container
|
container :: MachineName -> (FilePath -> Chroot.Chroot) -> Container
|
||||||
container name system = Container name system (Host name [] mempty)
|
container name mkchroot = Container name c h
|
||||||
& os system
|
& os system
|
||||||
|
where
|
||||||
|
c@(Chroot.Chroot _ system _ _) = mkchroot (containerDir name)
|
||||||
|
h = Host name [] mempty
|
||||||
|
|
||||||
-- | Runs a container using systemd-nspawn.
|
-- | Runs a container using systemd-nspawn.
|
||||||
--
|
--
|
||||||
|
@ -93,7 +97,8 @@ container name system = Container name system (Host name [] mempty)
|
||||||
-- Reverting this property stops the container, removes the systemd unit,
|
-- Reverting this property stops the container, removes the systemd unit,
|
||||||
-- and deletes the chroot and all its contents.
|
-- and deletes the chroot and all its contents.
|
||||||
nspawned :: Container -> RevertableProperty
|
nspawned :: Container -> RevertableProperty
|
||||||
nspawned c@(Container name system h) = RevertableProperty setup teardown
|
nspawned c@(Container name (Chroot.Chroot loc system builderconf _) h) =
|
||||||
|
RevertableProperty setup teardown
|
||||||
where
|
where
|
||||||
setup = combineProperties ("nspawned " ++ name) $
|
setup = combineProperties ("nspawned " ++ name) $
|
||||||
map toProp steps ++ [containerprovisioned]
|
map toProp steps ++ [containerprovisioned]
|
||||||
|
@ -117,7 +122,7 @@ nspawned c@(Container name system h) = RevertableProperty setup teardown
|
||||||
containerprovisioned = Chroot.propellChroot chroot
|
containerprovisioned = Chroot.propellChroot chroot
|
||||||
(enterContainerProcess c)
|
(enterContainerProcess c)
|
||||||
|
|
||||||
mkChroot = Chroot.Chroot (containerDir name) system
|
mkChroot = Chroot.Chroot loc system builderconf
|
||||||
chroot = mkChroot h
|
chroot = mkChroot h
|
||||||
|
|
||||||
nspawnService :: Container -> RevertableProperty
|
nspawnService :: Container -> RevertableProperty
|
||||||
|
|
Loading…
Reference in New Issue