[buildbot] phase1: add logic to purge trees after maximum lifetime

LEDE Commits lede-commits at lists.infradead.org
Fri Nov 4 04:49:31 PDT 2016


jow pushed a commit to buildbot.git, branch master:
https://git.lede-project.org/dc4d2ec4fe3acf2c549df57f5a172e127de37d63

commit dc4d2ec4fe3acf2c549df57f5a172e127de37d63
Author: Jo-Philipp Wich <jo at mein.io>
AuthorDate: Fri Nov 4 12:47:31 2016 +0100

    phase1: add logic to purge trees after maximum lifetime
    
    Add logic to the phase1 build config to purge persistent build trees if a
    configurable maximum age in seconds is reached.
    
    Signed-off-by: Jo-Philipp Wich <jo at mein.io>
---
 phase1/config.ini.example |  1 +
 phase1/expire.sh          | 25 +++++++++++++++++++++++++
 phase1/master.cfg         | 19 +++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/phase1/config.ini.example b/phase1/config.ini.example
index 5c109fb..288b90a 100644
--- a/phase1/config.ini.example
+++ b/phase1/config.ini.example
@@ -3,6 +3,7 @@ title = LEDE Project
 title_url = http://lede-project.org/
 buildbot_url = http://phase1.builds.lede-project.org/
 homedir = .
+expire = 1209600
 
 [status]
 bind = tcp:8010:interface=127.0.0.1
diff --git a/phase1/expire.sh b/phase1/expire.sh
new file mode 100755
index 0000000..eeba668
--- /dev/null
+++ b/phase1/expire.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+max_lifetime="$1"
+
+tree_birth="$(date --reference=tree.timestamp +%s 2>/dev/null)"
+tree_age="$(( $(date +%s) - ${tree_birth:-0} ))"
+
+if [ $max_lifetime -le 0 ]; then
+	echo "No tree expiry set."
+
+elif [ $tree_age -ge $max_lifetime ]; then
+	echo "The build tree reached its maximum lifetime, cleaning up."
+	find . -mindepth 1 -maxdepth 1 -print0 | xargs -r -0 rm -vrf | while read entry do
+		printf "."
+	done
+
+	echo ""
+	echo "Writing new timestamp"
+	date +%s > tree.timestamp
+
+else
+	echo "The build tree is not expired."
+fi
+
+exit 0
diff --git a/phase1/master.cfg b/phase1/master.cfg
index 5eb70f4..1389ae5 100644
--- a/phase1/master.cfg
+++ b/phase1/master.cfg
@@ -48,6 +48,10 @@ c['mergeRequests'] = True
 ####### CHANGESOURCES
 
 home_dir = os.path.abspath(ini.get("general", "homedir"))
+tree_expire = 0
+
+if ini.has_option("general", "expire"):
+	tree_expire = ini.getint("general", "expire")
 
 repo_url = ini.get("repo", "url")
 
@@ -271,6 +275,21 @@ for target in targets:
 		description = "Finding number of CPUs",
 		command = ["nproc"]))
 
+	# expire tree if needed
+	if tree_expire > 0:
+		factory.addStep(FileDownload(
+			mastersrc = "expire.sh",
+			slavedest = "expire.sh",
+			mode = 0755))
+
+		factory.addStep(ShellCommand(
+			name = "expire",
+			description = "Checking for build tree expiry",
+			command = ["./expire.sh", tree_expire],
+			workdir = ".",
+			haltOnFailure = True,
+			timeout = 2400))
+
 	# check out the source
 	factory.addStep(Git(repourl=repo_url, mode='update'))
 



More information about the lede-commits mailing list