Skip to content

Commit f769e8f

Browse files
authored
Merge branch 'master' into snyk-fix-4cc2868dfbe153c384dc3e7fd0c06488
2 parents 2cfdd7e + ee15142 commit f769e8f

File tree

8 files changed

+122
-30
lines changed

8 files changed

+122
-30
lines changed

benchbuild/environments/adapters/podman.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def _create(
157157
interactive = bool(CFG['container']['interactive'])
158158

159159
create_cmd = bb_podman('create', '--replace')
160+
161+
if seccomp_config := CFG['container']['seccomp_config']:
162+
create_cmd = create_cmd['--security-opt',
163+
f'seccomp={seccomp_config}', '--cap-add',
164+
'PERFMON']
165+
160166
if interactive:
161167
create_cmd = create_cmd['-it', '--entrypoint', '/bin/sh']
162168

benchbuild/environments/domain/commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class RunProjectContainer(model.Command):
7575
name: str = attr.ib(converter=oci_compliant_name)
7676

7777
build_dir: str = attr.ib()
78+
tmp_dir: str = attr.ib()
79+
mount_build_dir: bool = attr.ib()
80+
mount_tmp_dir: bool = attr.ib()
7881
args: tp.Sequence[str] = attr.ib(default=attr.Factory(list))
7982

8083

benchbuild/environments/entrypoints/cli.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def set_group(self, groups: tp.List[str]) -> None:
7272
requires=['experiment', 'debug'],
7373
help='Run a container interactively.')
7474

75+
no_mount_build_dir = cli.Flag(
76+
['no-mount-build-dir'],
77+
default=True,
78+
help="Do not mount benchbuild's build directory."
79+
)
80+
81+
mount_tmp_dir = cli.Flag(['mount-tmp-dir'],
82+
default=False,
83+
help="Mount benchbuild's tmp directory.")
84+
7585
def main(self, *projects: str) -> int:
7686
plugins.discover()
7787

@@ -116,7 +126,8 @@ def main(self, *projects: str) -> int:
116126
),
117127
"Run":
118128
partial(
119-
run_experiment_images, wanted_experiments, wanted_projects
129+
run_experiment_images, wanted_experiments, wanted_projects,
130+
not self.no_mount_build_dir, self.mount_tmp_dir
120131
)
121132
}
122133

@@ -422,6 +433,7 @@ def create_project_images(
422433
Tuples.
423434
"""
424435
build_dir = local.path(BB_APP_ROOT) / 'results'
436+
tmp_dir = local.path(BB_APP_ROOT) / 'tmp'
425437
publish = bootstrap.bus()
426438

427439
for prj in enumerate_projects(experiments, projects):
@@ -432,9 +444,10 @@ def create_project_images(
432444
layers.context(partial(__pull_sources_in_context, prj))
433445
layers.add('.', BB_APP_ROOT)
434446
layers.run('mkdir', str(build_dir))
447+
layers.run('mkdir', str(tmp_dir))
435448
layers.env(
436449
BB_BUILD_DIR=str(build_dir),
437-
BB_TMP_DIR=BB_APP_ROOT,
450+
BB_TMP_DIR=str(tmp_dir),
438451
BB_PLUGINS_PROJECTS=f'["{prj.__module__}"]'
439452
)
440453
layers.workingdir(BB_APP_ROOT)
@@ -491,7 +504,8 @@ def create_experiment_images(
491504

492505

493506
def run_experiment_images(
494-
experiments: ExperimentIndex, projects: ProjectIndex
507+
experiments: ExperimentIndex, projects: ProjectIndex, mount_build_dir: bool,
508+
mount_tmp_dir: bool
495509
) -> None:
496510
"""
497511
Run experiments on given projects.
@@ -503,6 +517,7 @@ def run_experiment_images(
503517
projects: Index of projects to run.
504518
"""
505519
build_dir = str(CFG['build_dir'])
520+
tmp_dir = str(CFG['tmp_dir'])
506521
publish = bootstrap.bus()
507522

508523
for exp in enumerate_experiments(experiments, projects):
@@ -516,7 +531,8 @@ def run_experiment_images(
516531

517532
publish(
518533
commands.RunProjectContainer(
519-
image_tag, container_name, build_dir
534+
image_tag, container_name, build_dir, tmp_dir,
535+
mount_build_dir, mount_tmp_dir
520536
)
521537
)
522538

benchbuild/environments/service_layer/handlers.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,25 @@ def run_project_container(
7070
with uow:
7171
ensure.container_image_exists(cmd.image, uow)
7272

73-
build_dir = uow.registry.env(cmd.image, 'BB_BUILD_DIR')
74-
if build_dir:
75-
uow.registry.mount(cmd.image, cmd.build_dir, build_dir)
76-
else:
77-
LOG.warning(
78-
'The image misses a configured "BB_BUILD_DIR" variable.'
79-
)
80-
LOG.warning('No result artifacts will be copied out.')
73+
if cmd.mount_build_dir:
74+
build_dir = uow.registry.env(cmd.image, 'BB_BUILD_DIR')
75+
if build_dir:
76+
uow.registry.mount(cmd.image, cmd.build_dir, build_dir)
77+
else:
78+
LOG.warning(
79+
'The image misses a configured "BB_BUILD_DIR" variable.'
80+
)
81+
LOG.warning('No result artifacts will be copied out.')
82+
83+
if cmd.mount_tmp_dir:
84+
tmp_dir = uow.registry.env(cmd.image, 'BB_TMP_DIR')
85+
if tmp_dir:
86+
uow.registry.mount(cmd.image, cmd.tmp_dir, tmp_dir)
87+
else:
88+
LOG.warning(
89+
'The image misses a configured "BB_TMP_DIR" variable.'
90+
)
91+
LOG.warning('Temporary files will not be shared.')
8192

8293
container = uow.create(cmd.image, cmd.name, cmd.args)
8394
uow.start(container)

benchbuild/project.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ def discovered() -> tp.Dict[str, ProjectT]:
476476

477477

478478
def __add_single_filter__(project: ProjectT, version: str) -> ProjectT:
479+
if version == "*":
480+
return project
481+
479482
sources = project.SOURCE
480483
sources = [src for src in project.SOURCE if src.is_expandable]
481484

@@ -493,6 +496,8 @@ def __add_indexed_filters__(
493496
sources = [src for src in project.SOURCE if src.is_expandable]
494497

495498
for i in range(min(len(sources), len(versions))):
499+
if versions[i] == "*":
500+
continue
496501
sources[i] = source.SingleVersionFilter(sources[i], versions[i])
497502

498503
project.SOURCE = sources
@@ -508,6 +513,9 @@ def __add_named_filters__(
508513
s.key: s for s in sources
509514
}
510515
for k, v in versions.items():
516+
if v == "*":
517+
continue
518+
511519
if k in named_sources:
512520
victim: source.base.FetchableSource = named_sources[k]
513521
victim = source.SingleVersionFilter(victim, v)

benchbuild/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@
392392
"desc": "Storage options for containers."
393393
"If 'null', ignore 'storage.conf'."
394394
},
395+
"seccomp_config": {
396+
"default": None,
397+
"desc": "Path to a custom seccomp.json to use."
398+
},
395399
"input": {
396400
"default": "container.tar.bz2",
397401
"desc": "Input container file/folder."

benchbuild/source/git.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
Declare a git source.
33
"""
4+
import logging
45
import os
56
import typing as tp
6-
import logging
77
from pathlib import Path
88

99
import plumbum as pb
@@ -18,6 +18,8 @@
1818
VarRemotes = tp.Union[str, tp.Dict[str, str]]
1919
Remotes = tp.Dict[str, str]
2020

21+
_fetched_cache: tp.Set['Git'] = set()
22+
2123

2224
class Git(base.FetchableSource):
2325
"""
@@ -32,6 +34,7 @@ def __init__(
3234
limit: tp.Optional[int] = 10,
3335
refspec: str = 'HEAD',
3436
shallow: bool = True,
37+
submodule_set_urls: tp.Optional[tp.Dict[str, str]] = None,
3538
version_filter: tp.Callable[[str], bool] = lambda version: True
3639
):
3740
super().__init__(local, remote)
@@ -40,6 +43,7 @@ def __init__(
4043
self.limit = limit
4144
self.refspec = refspec
4245
self.shallow = shallow
46+
self.submodule_set_urls = submodule_set_urls
4347
self.version_filter = version_filter
4448

4549
@property
@@ -62,18 +66,35 @@ def fetch(self) -> pb.LocalPath:
6266
str: [description]
6367
"""
6468
prefix = base.target_prefix()
65-
clone = maybe_shallow(
66-
git['clone', '--recurse-submodules'], self.shallow
67-
)
69+
clone = maybe_shallow(git['clone'], self.shallow)
6870
fetch = git['fetch', '--update-shallow', '--all']
71+
checkout = git['checkout', '-f', '--recurse-submodules']
72+
set_url = git['submodule', 'set-url']
73+
submodule_update = git['submodule', 'update', '--init', '--recursive']
74+
6975
flat_local = self.local.replace(os.sep, '-')
7076
cache_path = pb.local.path(prefix) / flat_local
7177

7278
if clone_needed(self.remote, cache_path):
7379
clone(self.remote, cache_path)
74-
else:
80+
7581
with pb.local.cwd(cache_path):
76-
fetch()
82+
if "HEAD" not in self.refspec:
83+
checkout(self.refspec.split('/')[-1])
84+
85+
if self.submodule_set_urls:
86+
for submodule, url in self.submodule_set_urls.items():
87+
LOG.debug('Setting url for submodule %s to %s.', submodule, url)
88+
set_url(submodule, url)
89+
submodule_update()
90+
else:
91+
if self in _fetched_cache:
92+
LOG.debug('Already fetched %s, skipping.', self.local)
93+
else:
94+
LOG.debug('Fetching %s.', self.local)
95+
_fetched_cache.add(self)
96+
with pb.local.cwd(cache_path):
97+
fetch()
7798

7899
return cache_path
79100

@@ -99,7 +120,9 @@ def version(self, target_dir: str, version: str = 'HEAD') -> pb.LocalPath:
99120
clone = git['clone']
100121
pull = git['pull']
101122
rev_parse = git['rev-parse']
102-
checkout = git['checkout']
123+
set_url = git['submodule', 'set-url']
124+
submodule_update = git['submodule', 'update', '--init', '--recursive']
125+
checkout = git['checkout', '-f']
103126

104127
with pb.local.cwd(src_loc):
105128
is_shallow = rev_parse('--is-shallow-repository').strip()
@@ -114,12 +137,15 @@ def version(self, target_dir: str, version: str = 'HEAD') -> pb.LocalPath:
114137
else:
115138
mkdir('-p', tgt_loc)
116139
with pb.local.cwd(tgt_loc):
117-
clone(
118-
'--dissociate', '--recurse-submodules', '--reference',
119-
src_loc, self.remote, '.'
120-
)
140+
clone('--dissociate', '--reference', src_loc, self.remote, '.')
121141
checkout('--detach', version)
122142

143+
if self.submodule_set_urls:
144+
for submodule, url in self.submodule_set_urls.items():
145+
LOG.debug('Setting url for submodule %s to %s.', submodule, url)
146+
set_url(submodule, url)
147+
submodule_update()
148+
123149
ln('-nsf', tgt_subdir, active_loc)
124150
return tgt_loc
125151

benchbuild/source/http.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ class HTTP(base.FetchableSource):
1717
Fetch the downloadable source via http.
1818
"""
1919

20+
def __init__(
21+
self,
22+
local: str,
23+
remote: tp.Union[str, tp.Dict[str, str]],
24+
check_certificate: bool = True
25+
):
26+
super().__init__(local, remote)
27+
self._check_certificate = check_certificate
28+
2029
@property
2130
def default(self) -> base.Variant:
2231
return self.versions()[0]
@@ -43,7 +52,7 @@ def fetch_version(self, version: str) -> pb.LocalPath:
4352
url = remotes[version]
4453
target_name = versioned_target_name(self.local, version)
4554
cache_path = pb.local.path(prefix) / target_name
46-
download_single_version(url, cache_path)
55+
download_single_version(url, cache_path, self._check_certificate)
4756

4857
return cache_path
4958

@@ -102,7 +111,7 @@ def version(self, target_dir: str, version: str) -> pb.LocalPath:
102111
active_loc = pb.local.path(target_dir) / self.local
103112

104113
mkdir(target_path)
105-
tar("-x", "-C", target_path, "-f", archive_path)
114+
tar("-x", "--no-same-owner", "-C", target_path, "-f", archive_path)
106115

107116
ln('-sf', target_path, active_loc)
108117

@@ -118,9 +127,10 @@ def __init__(
118127
self,
119128
local: str,
120129
remote: tp.Union[str, tp.Dict[str, str]],
121-
files: tp.List[str]
130+
files: tp.List[str],
131+
check_certificate: bool = True
122132
):
123-
super().__init__(local, remote)
133+
super().__init__(local, remote, check_certificate)
124134
self._files = files
125135

126136
def fetch_version(self, version: str) -> pb.LocalPath:
@@ -134,7 +144,9 @@ def fetch_version(self, version: str) -> pb.LocalPath:
134144
mkdir('-p', cache_path)
135145

136146
for file in self._files:
137-
download_single_version(f'{url}/{file}', cache_path / file)
147+
download_single_version(
148+
f'{url}/{file}', cache_path / file, self._check_certificate
149+
)
138150

139151
return cache_path
140152

@@ -153,11 +165,17 @@ def versioned_target_name(target_name: str, version: str) -> str:
153165
return "{}-{}".format(version, target_name)
154166

155167

156-
def download_single_version(url: str, target_path: str) -> str:
168+
def download_single_version(
169+
url: str, target_path: str, check_certificate: bool
170+
) -> str:
157171
if not download_required(target_path):
158172
return target_path
159173

160-
wget(url, '-O', target_path)
174+
if check_certificate:
175+
wget(url, '-O', target_path)
176+
else:
177+
wget(url, '--no-check-certificate', '-O', target_path)
178+
161179
from benchbuild.utils.download import update_hash
162180
update_hash(target_path)
163181
return target_path

0 commit comments

Comments
 (0)