Skip to content

Commit d060150

Browse files
author
Jeny Sadadia
committed
src/get_builds: service to fetch kernel build nodes
Add a service to poll for `build` events i.e. listen to successful kernel build nodes and fetch artifacts. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent 424d602 commit d060150

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

docker-compose.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,17 @@ services:
209209
- './data/src:/home/kernelci/data/src'
210210
- './data/output:/home/kernelci/data/output'
211211

212+
get-builds:
213+
container_name: 'kernelci-pipeline-get-builds'
214+
image: 'kernelci/staging-kernelci'
215+
env_file: ['.env']
216+
stop_signal: 'SIGINT'
217+
command:
218+
- './pipeline/get_builds.py'
219+
- '--settings=${KCI_SETTINGS:-/home/kernelci/config/kernelci.toml}'
220+
- 'run'
221+
volumes:
222+
- './src:/home/kernelci/pipeline'
223+
- './config:/home/kernelci/config'
224+
extra_hosts:
225+
- "host.docker.internal:host-gateway"

src/get_builds.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
#
3+
# SPDX-License-Identifier: LGPL-2.1-or-later
4+
#
5+
# Copyright (C) 2024 Collabora Limited
6+
# Author: Jeny Sadadia <[email protected]>
7+
8+
import sys
9+
10+
import kernelci
11+
import kernelci.config
12+
from kernelci.legacy.cli import Args, Command, parse_opts
13+
14+
from base import Service
15+
16+
17+
class GetBuilds(Service):
18+
19+
def __init__(self, configs, args):
20+
super().__init__(configs, args, 'get_builds')
21+
22+
def _setup(self, args):
23+
return self._api_helper.subscribe_filters({
24+
'kind': 'kbuild',
25+
'state': 'done',
26+
'result': 'pass'
27+
}, 'build')
28+
29+
def _stop(self, sub_id):
30+
if sub_id:
31+
self._api_helper.unsubscribe_filters(sub_id)
32+
sys.stdout.flush()
33+
34+
def _run(self, sub_id):
35+
self.log.info("Listening for events... ")
36+
self.log.info("Press Ctrl-C to stop.")
37+
38+
while True:
39+
node, _ = self._api_helper.receive_event_node(sub_id)
40+
self.log.info(f"Build node received: {node}")
41+
self.log.info(f"artifacts: {node.get('artifacts')}")
42+
return True
43+
44+
45+
class cmd_run(Command):
46+
help = "Listen for successful kernel build events"
47+
args = [Args.api_config]
48+
49+
def __call__(self, configs, args):
50+
return GetBuilds(configs, args).run(args)
51+
52+
53+
if __name__ == '__main__':
54+
opts = parse_opts('get_builds', globals())
55+
yaml_configs = opts.get_yaml_configs() or 'config'
56+
configs = kernelci.config.load(yaml_configs)
57+
status = opts.command(configs, opts)
58+
sys.exit(0 if status is True else 1)

0 commit comments

Comments
 (0)