Skip to content

Commit

Permalink
mfkrogh/docker launcher enshell (#173)
Browse files Browse the repository at this point in the history
* working prototype for DockerLauncherEnShell

* comment out debug print statements

* working launch_ensight.py as needed in prep for pypim

* precommit cleanup

* fix sos

* fix linter complaints

* Add missing file.

* fixing a spelling error in a comment; not sure why it wasn't pointed out before...

* work in progress towards the PR comments

* Rework arguments for use_egl and use_sos. Fix handling of PIM service URIs. Adapt handling of host/port due to URIs. Fix Docker Image location at ghcr.io.  Disable egl for now. Needs further addressing in a later PR.

* clean up flake8 stuff

* fix PR comments

* Add two more checks to clean up containers that didn't start.  Modify testing to delete old hanging around containers (advice from Marina and what they do for pynexus).

* more error handling and cleanup. switch to urllib3 instead of urllib due to problems with urllib and docker modules.

* tweak requirements for urllib3
  • Loading branch information
mfkrogh authored May 8, 2023
1 parent 8b18750 commit 3008f26
Show file tree
Hide file tree
Showing 10 changed files with 713 additions and 22 deletions.
1 change: 1 addition & 0 deletions requirements/build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ requests>=2.20.1
twine>=4.0.1
pyansys-docker>=5.0.4
junitparser>=2.8.0
urllib3>=1.26.10
2 changes: 2 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pyansys-docker>=5.0.4
pytest-mock>=3.10.0
numpy>=1.13.0
junitparser>=2.8.0
requests<2.29.0
urllib3>=1.26.10
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"protobuf>=3.9.1",
"grpcio>=1.23.0",
"requests>=2.20.1",
"urllib3>=1.26.10",
"dill>=0.3.5.1",
]

Expand Down
7 changes: 7 additions & 0 deletions src/ansys/pyensight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
from ansys.pyensight.dockerlauncher import DockerLauncher
except Exception:
pass

try:
from ansys.pyensight.dockerlauncherenshell import DockerLauncherEnShell
except Exception:
pass

from ansys.pyensight.launch_ensight import launch_ensight
27 changes: 17 additions & 10 deletions src/ansys/pyensight/dockerlauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
launcher = DockerLauncher(data_directory="D:\\data")
launcher.pull()
session = launcher.start()
launcher.stop()
session.close()
"""
import os.path
Expand Down Expand Up @@ -39,6 +39,11 @@ class DockerLauncher(pyensight.Launcher):
In some cases where the EnSight session can take a significant amount of
timme to start up, this is the number of seconds to wait before failing
the connection. The default is 120.0.
use_egl:
If True, EGL hardware accelerated graphics will be used. The platform
must be able to support it.
use_sos:
If None, don't use SOS. Otherwise, it's the number of EnSight Servers to use (int).
Examples:
::
Expand All @@ -47,20 +52,21 @@ class DockerLauncher(pyensight.Launcher):
launcher = DockerLauncher(data_directory="D:\\data")
launcher.pull()
session = launcher.start()
launcher.stop()
session.close()
"""

def __init__(
self,
data_directory: str,
docker_image_name: Optional[str] = None,
use_dev: bool = False,
timeout: float = 120.0,
use_dev: Optional[bool] = False,
timeout: Optional[float] = 120.0,
use_egl: Optional[bool] = False,
use_sos: Optional[int] = None,
) -> None:
super().__init__()
super().__init__(timeout=timeout, use_egl=use_egl, use_sos=use_sos)

self._timeout = timeout
self._data_directory: str = data_directory
self._container = None

Expand Down Expand Up @@ -118,16 +124,14 @@ def pull(self) -> None:
except Exception:
raise RuntimeError(f"Can't pull Docker image: {self._image_name}")

def start(self, host: str = "127.0.0.1", use_egl: bool = False) -> "pyensight.Session":
def start(self, host: str = "127.0.0.1") -> "pyensight.Session":
"""Start an EnSight session using the local Docker ensight image
Launch a copy of EnSight in the container that supports the gRPC interface. Create and
bind a Session instance to the created gRPC session. Return that session.
Args:
host:
Optional hostname on which the EnSight gRPC service is running
use_egl:
Specify True if EnSight should try to use EGL. Beta flag.
Returns:
pyensight Session object instance
Expand Down Expand Up @@ -180,7 +184,7 @@ def start(self, host: str = "127.0.0.1", use_egl: bool = False) -> "pyensight.Se
# FIXME_MFK: probably need a unique name for our container
# in case the user launches multiple sessions
egl_env = os.environ.get("PYENSIGHT_FORCE_ENSIGHT_EGL")
use_egl = use_egl or egl_env or self._has_egl()
use_egl = self._use_egl or egl_env or self._has_egl()
if use_egl:
self._container = self._docker_client.containers.run(
self._image_name,
Expand Down Expand Up @@ -250,6 +254,9 @@ def start(self, host: str = "127.0.0.1", use_egl: bool = False) -> "pyensight.Se
if use_egl:
cmd2 += " -egl"

if self._use_sos:
cmd2 += " -sos -nservers " + str(int(self._use_sos))

cmd2 += " -grpc_server " + str(ports[0])

vnc_url = f"vnc://%%3Frfb_port={ports[1]}%%26use_auth=0"
Expand Down
Loading

0 comments on commit 3008f26

Please sign in to comment.