propellor/src/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs

164 lines
5.9 KiB
Haskell
Raw Normal View History

{-# LANGUAGE FlexibleContexts #-}
2014-04-01 20:58:11 +00:00
module Propellor.Property.SiteSpecific.GitAnnexBuilder where
import Propellor
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.User as User
2014-04-01 22:06:02 +00:00
import qualified Propellor.Property.Cron as Cron
2014-05-20 22:49:03 +00:00
import qualified Propellor.Property.File as File
2015-05-26 15:24:22 +00:00
import qualified Propellor.Property.Systemd as Systemd
import qualified Propellor.Property.Chroot as Chroot
2015-02-01 21:34:04 +00:00
import Propellor.Property.Cron (Times)
2014-04-01 20:58:11 +00:00
builduser :: UserName
builduser = "builder"
2014-04-08 05:42:59 +00:00
homedir :: FilePath
homedir = "/home/builder"
gitbuilderdir :: FilePath
gitbuilderdir = homedir </> "gitbuilder"
2014-04-01 20:58:11 +00:00
builddir :: FilePath
2014-04-08 05:42:59 +00:00
builddir = gitbuilderdir </> "build"
2014-04-01 20:58:11 +00:00
2014-05-19 21:27:21 +00:00
type TimeOut = String -- eg, 5h
2015-02-01 21:34:04 +00:00
autobuilder :: Architecture -> Times -> TimeOut -> Property HasInfo
autobuilder arch crontimes timeout = combineProperties "gitannexbuilder" $ props
& Apt.serviceInstalledRunning "cron"
& Cron.niceJob "gitannexbuilder" crontimes (User builduser) gitbuilderdir
("git pull ; timeout " ++ timeout ++ " ./autobuild")
& rsyncpassword
where
context = Context ("gitannexbuilder " ++ arch)
pwfile = homedir </> "rsyncpassword"
2014-04-01 20:58:11 +00:00
-- The builduser account does not have a password set,
-- instead use the password privdata to hold the rsync server
-- password used to upload the built image.
rsyncpassword = withPrivData (Password builduser) context $ \getpw ->
2014-07-06 19:56:56 +00:00
property "rsync password" $ getpw $ \pw -> do
oldpw <- liftIO $ catchDefaultIO "" $
readFileStrict pwfile
if pw /= oldpw
then makeChange $ writeFile pwfile pw
else noChange
2014-05-19 21:27:21 +00:00
tree :: Architecture -> Property HasInfo
tree buildarch = combineProperties "gitannexbuilder tree" $ props
& Apt.installed ["git"]
& File.dirExists gitbuilderdir
& File.ownerGroup gitbuilderdir (User builduser) (Group builduser)
& gitannexbuildercloned
& builddircloned
where
gitannexbuildercloned = check (not <$> (doesDirectoryExist (gitbuilderdir </> ".git"))) $
userScriptProperty (User builduser)
2014-05-21 16:58:53 +00:00
[ "git clone git://git.kitenet.net/gitannexbuilder " ++ gitbuilderdir
, "cd " ++ gitbuilderdir
, "git checkout " ++ buildarch
]
`describe` "gitbuilder setup"
builddircloned = check (not <$> doesDirectoryExist builddir) $ userScriptProperty (User builduser)
2014-05-19 21:27:21 +00:00
[ "git clone git://git-annex.branchable.com/ " ++ builddir
]
2014-05-20 22:28:13 +00:00
buildDepsApt :: Property HasInfo
buildDepsApt = combineProperties "gitannexbuilder build deps" $ props
& Apt.buildDep ["git-annex"]
& Apt.installed ["liblockfile-simple-perl"]
& buildDepsNoHaskellLibs
& Apt.buildDepIn builddir
`describe` "git-annex source build deps installed"
2014-05-19 21:27:21 +00:00
buildDepsNoHaskellLibs :: Property NoInfo
2014-05-26 22:46:42 +00:00
buildDepsNoHaskellLibs = Apt.installed
["git", "rsync", "moreutils", "ca-certificates",
2014-05-20 22:28:13 +00:00
"debhelper", "ghc", "curl", "openssh-client", "git-remote-gcrypt",
2014-05-20 23:49:07 +00:00
"liblockfile-simple-perl", "cabal-install", "vim", "less",
2014-06-10 14:08:12 +00:00
-- needed by haskell libs
2014-12-03 23:05:18 +00:00
"libxml2-dev", "libidn11-dev", "libgsasl7-dev", "libgnutls28-dev",
2014-05-26 22:46:42 +00:00
"alex", "happy", "c2hs"
2014-05-20 23:49:07 +00:00
]
2014-05-20 22:28:13 +00:00
2015-06-01 17:55:07 +00:00
haskellPkgsInstalled :: String -> Property NoInfo
haskellPkgsInstalled dir = flagFile go ("/haskellpkgsinstalled")
where
go = userScriptProperty (User builduser)
[ "cd " ++ builddir ++ " && ./standalone/ " ++ dir ++ "/install-haskell-packages"
]
2014-05-19 21:27:21 +00:00
-- Installs current versions of git-annex's deps from cabal, but only
-- does so once.
cabalDeps :: Property NoInfo
2014-05-19 21:27:21 +00:00
cabalDeps = flagFile go cabalupdated
where
go = userScriptProperty (User builduser) ["cabal update && cabal install git-annex --only-dependencies || true"]
2014-05-19 21:27:21 +00:00
cabalupdated = homedir </> ".cabal" </> "packages" </> "hackage.haskell.org" </> "00-index.cache"
2014-05-23 01:42:57 +00:00
2015-06-01 17:55:07 +00:00
autoBuilderContainer :: (System -> Property HasInfo) -> System -> Times -> TimeOut -> Systemd.Container
autoBuilderContainer mkprop osver@(System _ arch) crontime timeout =
2015-05-29 23:18:35 +00:00
Systemd.container name bootstrap
2015-06-01 17:55:07 +00:00
& mkprop osver
& buildDepsApt
& autobuilder arch crontime timeout
2015-05-30 02:51:32 +00:00
where
name = arch ++ "-git-annex-builder"
bootstrap = Chroot.debootstrapped osver mempty
2015-06-01 17:55:07 +00:00
standardAutoBuilder :: System -> Property HasInfo
standardAutoBuilder osver@(System _ arch) =
2015-05-30 02:51:32 +00:00
propertyList "git-annex-builder" $ props
2015-05-29 23:18:35 +00:00
& os osver
& Apt.stdSourcesList
& Apt.unattendedUpgrades
& User.accountFor (User builduser)
& tree arch
2015-06-01 17:55:07 +00:00
armAutoBuilder :: System -> Times -> TimeOut -> Property HasInfo
armAutoBuilder osver@(System _ arch) crontime timeout =
propertyList "git-annex-builder (arm)" $ props
& standardAutoBuilder osver
& buildDepsNoHaskellLibs
-- Works around ghc crash with parallel builds on arm.
& (homedir </> ".cabal" </> "config")
`File.lacksLine` "jobs: $ncpus"
-- Install patched haskell packages for portability to
-- arm NAS's using old kernel versions.
& haskellPkgsInstalled "linux"
2015-05-29 23:18:35 +00:00
& autobuilder arch crontime timeout
2015-05-26 15:24:22 +00:00
2015-05-28 01:24:50 +00:00
androidAutoBuilderContainer :: Times -> TimeOut -> Systemd.Container
androidAutoBuilderContainer crontimes timeout =
androidContainer "android-git-annex-builder" (tree "android") builddir
& Apt.unattendedUpgrades
2014-07-06 19:56:56 +00:00
& autobuilder "android" crontimes timeout
2014-05-24 04:05:47 +00:00
-- Android is cross-built in a Debian i386 container, using the Android NDK.
androidContainer
:: (IsProp (Property (CInfo NoInfo i)), (Combines (Property NoInfo) (Property i)))
2015-05-28 01:24:50 +00:00
=> Systemd.MachineName
-> Property i
-> FilePath
2015-05-28 01:24:50 +00:00
-> Systemd.Container
androidContainer name setupgitannexdir gitannexdir = Systemd.container name bootstrap
& os osver
& Apt.stdSourcesList
& User.accountFor (User builduser)
2014-05-28 15:10:55 +00:00
& File.dirExists gitbuilderdir
& File.ownerGroup homedir (User builduser) (Group builduser)
2014-05-24 04:52:37 +00:00
& flagFile chrootsetup ("/chrootsetup")
2014-05-28 14:38:29 +00:00
`requires` setupgitannexdir
2015-05-28 13:34:47 +00:00
& buildDepsApt
2015-06-01 17:55:07 +00:00
& haskellPkgsInstalled "android"
2014-05-24 04:52:37 +00:00
where
2014-05-24 04:05:47 +00:00
-- Use git-annex's android chroot setup script, which will install
2014-05-24 04:09:58 +00:00
-- ghc-android and the NDK, all build deps, etc, in the home
-- directory of the builder user.
2014-05-24 04:52:37 +00:00
chrootsetup = scriptProperty
2014-05-28 14:38:29 +00:00
[ "cd " ++ gitannexdir ++ " && ./standalone/android/buildchroot-inchroot"
2014-10-16 16:13:55 +00:00
]
2015-04-25 15:24:47 +00:00
osver = System (Debian Testing) "i386"
2015-05-28 01:24:50 +00:00
bootstrap = Chroot.debootstrapped osver mempty