-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathci.py
More file actions
executable file
·107 lines (94 loc) · 4.35 KB
/
ci.py
File metadata and controls
executable file
·107 lines (94 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
# Copyright 2025 XTX Markets Technologies Limited
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
import argparse
from common import *
parser = argparse.ArgumentParser()
parser.add_argument('--functional', action='store_true')
parser.add_argument('--integration', action='store_true')
parser.add_argument('--short', action='store_true')
parser.add_argument('--kmod', action='store_true')
parser.add_argument('--build', action='store_true')
parser.add_argument('--docker', action='store_true', help='Build and run in docker image')
parser.add_argument('--prepare-image', default=None, type=str, help='Build the kmod image given the provided base image')
parser.add_argument('--leader-only', action='store_true', help='Run only LogsDB leader with LEADER_NO_FOLLOWERS')
parser.add_argument('--close-tracker-object', default=None, type=str, help='Run fuse driver with the given close tracker object')
parser.add_argument('--filter', default=None, type=str, help='Regex to filter test names')
args = parser.parse_args()
script_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(script_dir)
def is_rootless_docker() -> bool:
"""Checks if the Docker daemon is running in rootless mode."""
try:
result = subprocess.run(['docker', 'info', '-f', '{{json .SecurityOptions}}'],
capture_output=True,
text=True,
check=True
)
return 'rootless' in result.stdout
except subprocess.CalledProcessError:
print("Warning: Could not connect to Docker daemon.", file=sys.stderr)
return False
except FileNotFoundError:
print("Error: Docker command not found. Is Docker installed?", file=sys.stderr)
sys.exit(1)
def run_docker_unbuffered(docker_args, args):
# See <https://groups.google.com/g/seastar-dev/c/r7W-Kqzy9O4>
# for motivation for `--security-opt seccomp=unconfined`,
# the `--pids-limit -1` is not something I hit but it seems
# like a good idea.
container = 'ghcr.io/xtxmarkets/ternfs-ubuntu-build:2026-03-11'
cmd = ['docker', 'run', '--pids-limit', '-1', '--security-opt', 'seccomp=unconfined', '--mount', f'type=bind,src={script_dir},dst=/ternfs', '--cap-add', 'SYS_ADMIN', '--privileged', '--rm', '-i']
if not is_rootless_docker():
cmd += ['-e', f'UID={os.getuid()}', '-e', f'GID={os.getgid()}']
run_cmd_unbuffered(
cmd + docker_args + [container] + args
)
if args.build:
bold_print('building')
for r in (['ubuntu', 'ubuntusanitized', 'ubuntuvalgrind'] if args.docker else ['release', 'sanitized', 'valgrind']):
wait_cmd(run_cmd(['./build.sh', r]))
if args.docker:
run_docker_unbuffered(['-w', '/ternfs/kmod'], ['make', 'bincode_tests'])
else:
wait_cmd(run_cmd(['make', 'bincode_tests'], cwd='kmod'))
if args.functional:
bold_print('functional tests')
if args.docker:
bold_print('starting functional tests in docker')
container = 'ghcr.io/xtxmarkets/ternfs-ubuntu-build:2026-03-11'
run_docker_unbuffered(
['-w', '/ternfs'], ['./cpp/tests.sh']
)
run_docker_unbuffered(
['-w', '/ternfs/kmod'], ['./bincode_tests']
)
run_docker_unbuffered(
['-w', '/ternfs/go'], ['go', 'test', './...']
)
else:
wait_cmds([
run_cmd(['./bincode_tests'], cwd='kmod'),
run_cmd(['./cpp/tests.sh']),
run_cmd(['go', 'test', './...'], cwd='go')
])
if args.integration:
integration_args = (['--short'] if args.short else []) + (['--leader-only'] if args.leader_only else []) + (['--close-tracker-object', args.close_tracker_object] if args.close_tracker_object else []) + (['--filter', args.filter] if args.filter else [])
if args.docker:
bold_print('starting integration tests in docker')
run_docker_unbuffered(
[],
['/ternfs/integration.py', '--docker'] + integration_args
)
else:
run_cmd_unbuffered(
['./integration.py'] + integration_args
)
if args.prepare_image:
bold_print('prepare kmod image')
wait_cmd(run_cmd(['./kmod/ci_prepare.sh', args.prepare_image]))
if args.kmod:
bold_print('kmod tests')
wait_cmd(run_cmd(['./kmod/ci.sh'] + (['-short'] if args.short else []) + (['-leader-only'] if args.leader_only else []) + (['-filter', args.filter] if args.filter else [])))