Skip to content

Commit

Permalink
Merge pull request #87 from eWaterCycle/sing-master-env-84
Browse files Browse the repository at this point in the history
Use `--env BMI_PORT=x` for singularity
  • Loading branch information
sverhoeven authored Oct 19, 2020
2 parents 053cc4c + db8b698 commit a88906b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions grpc4bmi/bmi_client_singularity.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import errno
import os
import time
from os.path import abspath
import subprocess
import sys
import logging

from semver import VersionInfo

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():
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="Run your BMI implementation in a separate process and expose it as BMI-python with GRPC",
Expand Down

0 comments on commit a88906b

Please sign in to comment.