Skip to content
Snippets Groups Projects
Commit d7899e5a authored by Lars Bilke's avatar Lars Bilke
Browse files

Added --ccache parameter.

parent 1291dbe1
No related branches found
No related tags found
No related merge requests found
# 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()
......
......@@ -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)
......
......@@ -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,
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment