Merge ubuntu-cdimage:stop-autobuild into ubuntu-cdimage:main

Proposed by Łukasz Zemczak
Status: Needs review
Proposed branch: ubuntu-cdimage:stop-autobuild
Merge into: ubuntu-cdimage:main
Diff against target: 162 lines (+82/-3)
6 files modified
README (+13/-1)
bin/rebuild-requests (+3/-0)
etc/crontab (+3/-0)
lib/cdimage/build.py (+18/-2)
lib/cdimage/config.py (+1/-0)
lib/cdimage/tests/test_build.py (+44/-0)
Reviewer Review Type Date Requested Status
Ubuntu CD Image Team Pending
Review via email: mp+450705@code.launchpad.net

Commit message

Implement support for AUTOBUILD_STOP to stop crontab-started builds for a given imageset.

Description of the change

Implement support for AUTOBUILD_STOP to stop crontab-started builds for a given imageset.

This might be useful if we want to add additional operator scripts for easy turning on/off selected image types. Will be very useful when we'd want to get cdimage deployed for the partner engineering team.

To post a comment you must log in.

Unmerged commits

2e9f4ef... by Łukasz Zemczak

Implement support for AUTOBUILD_STOP to stop crontab-started builds for a given imageset.

Succeeded
[SUCCEEDED] run-tests:0 (build)
[SUCCEEDED] lint:0 (build)
12 of 2 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README b/README
2index ef0bd61..bb706cf 100644
3--- a/README
4+++ b/README
5@@ -133,6 +133,18 @@ images.
6 Trigger mirrors to update from the WWW output tree, thereby making the
7 images available to the world.
8
9+cdimage, at least on the official infrastructure, builds daily images by
10+executing the cron.* scripts via a crontab schedule. Those daily builds can
11+be disabled in two ways: either by commenting out the relevant build crontab
12+entry or by the AUTOBUILD_STOP flag.
13+
14+If cdimage is triggered automatically from the crontab, a cdimage operator can
15+touch a AUTOBUILD_STOP flag in the publish_base of a given project to stop it
16+from building when triggered automatically. Rebuild requests or manual runs
17+on cdimage will still work. This is useful when working on addional tools or
18+automation for cdimage operators.
19+
20+ touch www/full/ubuntu-server/focal/daily-live/AUTOBUILD_STOP
21
22 Releasing images
23 ----------------
24@@ -247,4 +259,4 @@ For example:
25 CDIMAGE_ROOT/www/full/optimized/test/kubuntu/daily-live/...
26
27 Subtree builds do not clash with the regular builds (or with other subtrees),
28-so they can be ran in parallel.
29\ No newline at end of file
30+so they can be ran in parallel.
31diff --git a/bin/rebuild-requests b/bin/rebuild-requests
32index 786c80b..c29b694 100755
33--- a/bin/rebuild-requests
34+++ b/bin/rebuild-requests
35@@ -53,6 +53,9 @@ def main():
36 tree = Tree.get_daily(config)
37 publisher = Publisher.get_daily(tree, "daily")
38
39+ # Rebuild-request requests should never be treated as autobuilds
40+ config["AUTOBUILD_TRIGGERED"] = "0"
41+
42 # Only import it here to avoid --help failing from the bzr branch
43 from isotracker import ISOTracker
44
45diff --git a/etc/crontab b/etc/crontab
46index ce897e8..b46036e 100644
47--- a/etc/crontab
48+++ b/etc/crontab
49@@ -6,6 +6,9 @@ PATH=/srv/cdimage.ubuntu.com/bin:/usr/sbin:/usr/bin:/sbin:/bin
50
51 # CD image cron jobs, run out of cdimage's crontab.
52
53+# Mark all the builds here as 'autobuild triggered'
54+AUTOBUILD_TRIGGERED=1
55+
56 # core16 daily builds
57 30 8 * * * DIST=xenial for-project ubuntu-core cron.daily-live --live
58 # core18 daily builds
59diff --git a/lib/cdimage/build.py b/lib/cdimage/build.py
60index 4b96c60..bd97d01 100644
61--- a/lib/cdimage/build.py
62+++ b/lib/cdimage/build.py
63@@ -721,8 +721,26 @@ def is_live_fs_only(config):
64 return live_fs_only
65
66
67+def check_should_build(config, publisher):
68+ if ("AUTOBUILD_TRIGGERED" in config and
69+ config["AUTOBUILD_TRIGGERED"] == "1"):
70+ # Autobuild (daily) - check if autobuilds are enabled or not for this
71+ # project.
72+ lock_path = os.path.join(publisher.publish_base, "AUTOBUILD_STOP")
73+ if os.path.exists(lock_path):
74+ return False
75+
76+ return True
77+
78+
79 def build_image_set_locked(config, options):
80 image_type = config.image_type
81+ tree = Tree.get_daily(config)
82+ publisher = Publisher.get_daily(tree, image_type)
83+
84+ if not check_should_build(config, publisher):
85+ return True
86+
87 config["CDIMAGE_DATE"] = date = next_build_id(config, image_type)
88 log_path = None
89
90@@ -786,8 +804,6 @@ def build_image_set_locked(config, options):
91
92 if not config["DEBUG"] and not config["CDIMAGE_NOPUBLISH"]:
93 log_marker("Publishing")
94- tree = Tree.get_daily(config)
95- publisher = Publisher.get_daily(tree, image_type)
96 publisher.publish(date)
97
98 log_marker("Purging old images")
99diff --git a/lib/cdimage/config.py b/lib/cdimage/config.py
100index 4196d19..3ed7598 100644
101--- a/lib/cdimage/config.py
102+++ b/lib/cdimage/config.py
103@@ -320,6 +320,7 @@ _allowed_keys = (
104 "EXTRA_PPAS",
105 "CHANNEL",
106 "SIMPLESTREAMS",
107+ "AUTOBUILD_TRIGGERED",
108 )
109
110
111diff --git a/lib/cdimage/tests/test_build.py b/lib/cdimage/tests/test_build.py
112index 8de4881..4f766e9 100644
113--- a/lib/cdimage/tests/test_build.py
114+++ b/lib/cdimage/tests/test_build.py
115@@ -1269,3 +1269,47 @@ class TestBuildImageSet(TestCase):
116
117 mock_build_image_set_locked.side_effect = side_effect
118 build_image_set(self.config, None)
119+
120+ @mock.patch("cdimage.build.next_build_id")
121+ def test_lock_build_image_set_not_build(self, mock_next_build_id):
122+ mock_next_build_id.side_effect = Exception
123+ self.config["PROJECT"] = "ubuntu-server"
124+ self.config["DIST"] = "jammy"
125+ self.config["IMAGE_TYPE"] = "daily-live"
126+ self.config["AUTOBUILD_TRIGGERED"] = "1"
127+ stop_path = os.path.join(
128+ self.config.root, "www", "full", "ubuntu-server", "jammy",
129+ "daily-live", "AUTOBUILD_STOP")
130+ touch(stop_path)
131+
132+ build_image_set_locked(self.config, None)
133+
134+ @mock.patch("cdimage.build.next_build_id")
135+ def test_lock_build_image_set_not_build_subtree(self, mock_next_build_id):
136+ mock_next_build_id.side_effect = Exception
137+ self.config["PROJECT"] = "ubuntu-server"
138+ self.config["DIST"] = "jammy"
139+ self.config["IMAGE_TYPE"] = "daily-live"
140+ self.config["AUTOBUILD_TRIGGERED"] = "1"
141+ self.config.subtree = "subtree"
142+ stop_path = os.path.join(
143+ self.config.root, "www", "full", "subtree", "ubuntu-server",
144+ "jammy", "daily-live", "AUTOBUILD_STOP")
145+ touch(stop_path)
146+
147+ build_image_set_locked(self.config, None)
148+
149+ @mock.patch("cdimage.build.next_build_id")
150+ def test_lock_build_image_set_build_not_auto(self, mock_next_build_id):
151+ mock_next_build_id.side_effect = Exception
152+ self.config["PROJECT"] = "ubuntu-server"
153+ self.config["DIST"] = "jammy"
154+ self.config["IMAGE_TYPE"] = "daily-live"
155+ stop_path = os.path.join(
156+ self.config.root, "www", "full", "ubuntu-server", "jammy",
157+ "daily-live", "AUTOBUILD_STOP")
158+ touch(stop_path)
159+
160+ # This time we want to build the imageset
161+ with self.assertRaises(Exception):
162+ build_image_set_locked(self.config, None)

Subscribers

People subscribed via source and target branches

to all changes: