From d7899e5a23f5f70475516dd0138e6eb72ccf6b2c Mon Sep 17 00:00:00 2001 From: Lars Bilke <lars.bilke@ufz.de> Date: Tue, 14 Jan 2020 14:49:16 +0100 Subject: [PATCH] Added --ccache parameter. --- ogscm/building_blocks/ccache.py | 6 +++--- ogscm/cli.py | 28 ++++++++++++++++++---------- ogscm/cli_args.py | 6 ++++++ ogscm/container_info.py | 6 ++++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ogscm/building_blocks/ccache.py b/ogscm/building_blocks/ccache.py index 5d75c0b..1d335ed 100644 --- a/ogscm/building_blocks/ccache.py +++ b/ogscm/building_blocks/ccache.py @@ -1,6 +1,6 @@ # pylint: disable=invalid-name, too-few-public-methods # pylint: disable=too-many-instance-attributes -"""Package manager Conan building block""" +"""ccache building block""" from __future__ import absolute_import from __future__ import unicode_literals @@ -15,12 +15,12 @@ from hpccm.primitives.shell import shell class ccache(bb_base): - """Package manager Conan building block""" + """ccache building block""" def __init__(self, **kwargs): """Initialize building block""" super(ccache, self).__init__() - self.__cache_dir = kwargs.get('cache_dir', '/opt/cache') + self.__cache_dir = kwargs.get('cache_dir', '/opt/ccache') self.__cache_size = kwargs.get('cache_size', '5G') self.__instructions() diff --git a/ogscm/cli.py b/ogscm/cli.py index 586cb2c..46fb1bf 100644 --- a/ogscm/cli.py +++ b/ogscm/cli.py @@ -307,6 +307,11 @@ def main(): # pragma: no cover ]) if ogs_version != 'off': + mount_args = '' + if args.ccache: + Stage0 += ccache(cache_size='15G') + if info.buildkit: + mount_args = f'{mount_args} --mount=type=cache,target=/opt/ccache,id=ccache' if args.cvode: cmake_args.append('-DOGS_USE_CVODE=ON') if args.gui: @@ -316,15 +321,15 @@ def main(): # pragma: no cover Stage0 += pip(packages=['scif'], pip='pip3') # SCI-F scif_installed = True Stage0 += raw(docker=f"ARG OGS_COMMIT_HASH={info.commit_hash}") - if info.buildkit: + + scif_file = f"{info.out_dir}/ogs.scif" + if info.ogsdir != '': context_path_size = len(ogs_version) os.chdir(ogs_version) - ogs_app = scif( - _arguments='--mount=type=bind,target=/scif/apps/ogs/src,rw', - name='ogs', - file=f"{info.out_dir[context_path_size+1:]}/ogs.scif") - else: - ogs_app = scif(name='ogs', file=f"{info.out_dir}/ogs.scif") + mount_args = f'{mount_args} --mount=type=bind,target=/scif/apps/ogs/src,rw' + scif_file = f"{info.out_dir[context_path_size+1:]}/ogs.scif" + + ogs_app = scif(_arguments=mount_args, name='ogs', file=scif_file) ogs_app += ogs(repo=info.repo, branch=info.branch, commit=info.commit_hash, @@ -382,10 +387,13 @@ def main(): # pragma: no cover # TODO: adapt this to else continue - build_cmd = (f"docker build " - f"-t {info.tag} -f {definition_file_path} .") + enable_buildkit = '' if info.buildkit: - build_cmd = "(cd {0} && DOCKER_BUILDKIT=1 {1})".format( + enable_buildkit = 'DOCKER_BUILDKIT=1' + build_cmd = (f"{enable_buildkit} docker build " + f"-t {info.tag} -f {definition_file_path} .") + if info.ogsdir != '': + build_cmd = "(cd {0} && {1})".format( ogs_version, build_cmd) print(f"Running: {build_cmd}") subprocess.run(build_cmd, shell=True) diff --git a/ogscm/cli_args.py b/ogscm/cli_args.py index b419124..b39c559 100644 --- a/ogscm/cli_args.py +++ b/ogscm/cli_args.py @@ -102,6 +102,12 @@ class Cli_Args(argparse.ArgumentParser): action='store_true', help='Generate multi-stage Dockerfiles for small runtime ' 'images') + build_g.add_argument( + '--ccache', + dest='ccache', + action='store_true', + help='Enables ccache build caching.' + ) switches_g = self.add_argument_group('Additional options') switches_g.add_argument('--base_image', type=str, diff --git a/ogscm/container_info.py b/ogscm/container_info.py index c573734..917adbb 100644 --- a/ogscm/container_info.py +++ b/ogscm/container_info.py @@ -20,7 +20,8 @@ from ogscm import config class container_info(): def __init__(self, args_iter, args): """Initialize container info""" - self.buildkit = False + self.buildkit = True + self.ogsdir = '' self.outdir = '' self.definition_file = '' self.images_out_dir = '' @@ -111,12 +112,13 @@ class container_info(): if os.path.isdir(ogs_version): self.buildkit = True + self.ogsdir = ogs_version if args.file != '': self.out_dir = args.out self.definition_file = args.file else: - if self.buildkit: + if self.ogsdir != '': self.out_dir = os.path.join( ogs_version, f"{args.out}/{container_format}/{img_folder}") else: -- GitLab