From cf8dd181ee5e25762754e712b44b20d01ac49216 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Thu, 2 Jan 2025 11:24:45 -0800 Subject: [PATCH 1/2] Allow microtest to run under docker --- micall/utils/release_test_microtest.py | 54 +++++++++++++++++++------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/micall/utils/release_test_microtest.py b/micall/utils/release_test_microtest.py index 0c76d0aa5..0240bb15a 100644 --- a/micall/utils/release_test_microtest.py +++ b/micall/utils/release_test_microtest.py @@ -391,8 +391,9 @@ def create_sample_scratch(fastq_file): class SampleRunner: - def __init__(self, image_path: Path): + def __init__(self, image_path: Path, is_docker: bool = False): self.image_path = image_path + self.is_docker = is_docker self.is_denovo = False self.bad_cycles_path = None @@ -572,21 +573,46 @@ def process_resistance(self, sample_group: SampleGroup): def build_command(self, inputs, outputs, app_name=None): input_path = inputs[0].parent output_path = outputs[0].parent - command = ['singularity', - 'run', - '--contain', - '--cleanenv', - '-B', - '{}:/mnt/input,{}:/mnt/output'.format(input_path, - output_path)] - if app_name: - command.append('--app') - command.append(app_name) - command.append(self.image_path) + + if self.is_docker: + command = ['docker', + 'run', + '--rm', + '--read-only', + '--volume', '{}:/mnt/input'.format(input_path), + '--volume', '{}:/mnt/output'.format(output_path), + '--volume', '{}:/tmp'.format(output_path / 'tmp'), + '--entrypoint', 'micall', + '--', str(self.image_path), + ] + + app_arguments = { + None: ['micall_kive'], + 'filter_quality': ['filter_quality'], + 'resistance': ['micall_kive_resistance'], + 'denovo': ['micall_kive', '--denovo'], + }[app_name] + + command.extend(app_arguments) + + else: + command = ['singularity', + 'run', + '--contain', + '--cleanenv', + '-B', + '{}:/mnt/input,{}:/mnt/output'.format(input_path, + output_path)] + if app_name: + command.append('--app') + command.append(app_name) + command.append(str(self.image_path)) + for arguments, guest_path in zip((inputs, outputs), ('/mnt/input', '/mnt/output')): for argument in arguments: command.append(os.path.join(guest_path, argument.name)) + return command @@ -622,6 +648,8 @@ def main(): help='Folder to copy microtest samples into.') parser.add_argument('--sample', help='Prefix of sample name to run.') + parser.add_argument('--docker', action='store_true', + help='If to use docker instead of Singularity.') # noinspection PyTypeChecker parser.add_argument('image', type=Path, @@ -642,7 +670,7 @@ def main(): for source_file in source_files: target_file: Path = sandbox_path / source_file.name shutil.copy(str(source_file), str(target_file)) - runner = SampleRunner(args.image) + runner = SampleRunner(args.image, is_docker=args.docker) with ProcessPoolExecutor() as pool: search_pattern = '*_R1_*.fastq' if args.sample: From 324836b8b05703c42c9c10a7bacb3327dae5ed83 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Thu, 2 Jan 2025 11:26:36 -0800 Subject: [PATCH 2/2] Run docker microtest on CI --- .github/workflows/build-and-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c2d870fe0..f0379d937 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -83,6 +83,8 @@ jobs: run: docker run micall --help - name: Check docker image entrypoint run: docker run micall --help | grep -i -e 'docker' + - name: Check docker image microtest + run: python micall/main.py release_test_microtest micall --docker singularity-test: runs-on: ubuntu-20.04