diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5dc5fe..1ba5126 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,9 @@ jobs: pip install -r requirements.txt python setup.py install - name: Setup Singularity - uses: eWaterCycle/setup-singularity@v3 + uses: eWaterCycle/setup-singularity@v4 with: - singularity-version: 3.5.3 + singularity-version: 3.6.4 - name: Pull Docker image run: docker pull ewatercycle/walrus-grpc4bmi:v0.3.1 - name: Cache Singularity image diff --git a/grpc4bmi/bmi_client_singularity.py b/grpc4bmi/bmi_client_singularity.py index 13a7704..f5b7cda 100644 --- a/grpc4bmi/bmi_client_singularity.py +++ b/grpc4bmi/bmi_client_singularity.py @@ -1,8 +1,8 @@ import errno import os +import time from os.path import abspath import subprocess -import sys import logging from semver import VersionInfo @@ -10,7 +10,7 @@ from grpc4bmi.bmi_grpc_client import BmiClient from grpc4bmi.utils import stage_config_file -REQUIRED_SINGULARITY_VERSION = '>=3.1.0' +REQUIRED_SINGULARITY_VERSION = '>=3.6.0' def check_singularity_version(): @@ -41,6 +41,7 @@ class BmiClientSingularity(BmiClient): input_dir (str): Directory for input files of model output_dir (str): Directory for input files of model timeout (int): Seconds to wait for gRPC client to connect to server + delay (int): Seconds to wait for Singularity container to startup, before connecting to it extra_volumes (Dict[str,str]): Extra volumes to attach to Singularity container. The key is the hosts path and the value the mounted volume inside the container. @@ -56,13 +57,15 @@ class BmiClientSingularity(BmiClient): INPUT_MOUNT_POINT = "/data/input" OUTPUT_MOUNT_POINT = "/data/output" - def __init__(self, image, input_dir=None, output_dir=None, timeout=None, extra_volumes=None): + def __init__(self, image, input_dir=None, output_dir=None, timeout=None, + delay=0, extra_volumes=None): check_singularity_version() host = 'localhost' port = BmiClient.get_unique_port(host) args = [ "singularity", "run", + "--env", f"BMI_PORT={port}" ] mount_points = {} if extra_volumes is None else extra_volumes if input_dir is not None: @@ -80,10 +83,9 @@ def __init__(self, image, input_dir=None, output_dir=None, timeout=None, extra_v raise e args += ["--bind", output_dir + ':' + BmiClientSingularity.OUTPUT_MOUNT_POINT] args.append(image) - env = os.environ.copy() - env['BMI_PORT'] = str(port) logging.info(f'Running {image} singularity container on port {port}') - self.container = subprocess.Popen(args, env=env, preexec_fn=os.setsid) + self.container = subprocess.Popen(args, preexec_fn=os.setsid) + time.sleep(delay) super(BmiClientSingularity, self).__init__(BmiClient.create_grpc_channel(port=port, host=host), timeout=timeout) def __del__(self): diff --git a/setup.py b/setup.py index 21f11ea..23e003e 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def read(fname): setup(name="grpc4bmi", - version="0.3.1", + version="0.3.2", author="Gijs van den Oord", author_email="g.vandenoord@esciencecenter.nl", description="Run your BMI implementation in a separate process and expose it as BMI-python with GRPC",