Skip to content

Commit 89215f2

Browse files
authored
Launch docker image from PyGeometry (#337)
1 parent 55d1516 commit 89215f2

File tree

15 files changed

+594
-18
lines changed

15 files changed

+594
-18
lines changed

.github/workflows/ci_cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
PACKAGE_NAME: 'ansys-geometry-core'
1414
PACKAGE_NAMESPACE: 'ansys.geometry.core'
1515
DOCUMENTATION_CNAME: 'geometry.docs.pyansys.com'
16-
ANSRV_GEO_IMAGE: ghcr.io/pyansys/pygeometry:latest
16+
ANSRV_GEO_IMAGE: ghcr.io/pyansys/pygeometry:windows-latest
1717
ANSRV_GEO_PORT: 700
1818
GEO_CONT_NAME: ans_geo
1919
RESET_IMAGE_CACHE: 6

.github/workflows/nightly_docker_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
name: Run all tests against server
1818
runs-on: [self-hosted, pygeometry]
1919
env:
20-
ANSRV_GEO_IMAGE: ghcr.io/pyansys/pygeometry:latest-unstable
20+
ANSRV_GEO_IMAGE: ghcr.io/pyansys/pygeometry:windows-latest-unstable
2121
ANSRV_GEO_PORT: 710
2222
GEO_CONT_NAME: ans_geo_nightly
2323

README.rst

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,56 @@ PyGeometry is a Python client library for the Ansys Geometry service.
3636
Usage
3737
-----
3838

39+
There are two different ways of getting started with the Geometry Service and its client-library, PyGeometry.
40+
41+
Using PyGeometry launcher
42+
^^^^^^^^^^^^^^^^^^^^^^^^^
43+
44+
PyGeometry is provided with an internal launcher that is capable of handling the specifics of
45+
launching the Geometry Service locally. The only requirements are that:
46+
47+
* Docker is installed on your machine.
48+
* You have access to the PyAnsys GitHub container registry, where the Geometry Service image is hosted.
49+
50+
.. caution::
51+
52+
The Geometry Service is currently available only as a Windows Docker image. The development
53+
team is working on getting the Linux Docker container available as soon as possible. In the meantime,
54+
make sure that your Docker engine is configured to run Windows Docker images.
55+
56+
First, bear in mind that you have to be `authenticated to ghcr.io
57+
<https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry>`_.
58+
Once authenticated, please proceed to download the Geometry Service Docker image:
59+
60+
.. code:: bash
61+
62+
docker pull ghcr.io/pyansys/pygeometry:<tag>
63+
64+
The following OS-dependent tags are available:
65+
66+
* ``windows-latest``
67+
* ``windows-latest-unstable``
68+
69+
Next, you will be ready to run the Geometry Service directly from PyGeometry:
70+
71+
.. code:: python
72+
73+
from ansys.geometry.core.connection import launch_modeler
74+
75+
modeler = launch_modeler()
76+
77+
The previous ``launch_modeler()`` method will launch the Geometry Service under the default
78+
conditions. For more configurability, please use ``launch_local_modeler()``.
79+
80+
Manual service launch
81+
^^^^^^^^^^^^^^^^^^^^^
82+
3983
First, start the Geometry service locally. If you have Docker installed and have
40-
`authenticated to ghcr.io
41-
<https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry>`_,
42-
you can start the service locally using Docker with:
84+
`authenticated to ghcr.io`_, you can start the service locally using Docker with:
4385

4486
.. code:: bash
4587
46-
docker run --name ans_geo -p 50051:50051 ghcr.io/pyansys/pygeometry:latest
88+
docker run --name ans_geo -p 50051:50051 ghcr.io/pyansys/pygeometry:windows-latest
4789
4890
Next, connect to the service with:
4991

doc/source/getting_started/docker.rst

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,47 @@ Install the PyGeometry image
2222
GH_USERNAME=<my-github-username>
2323
cat GH_TOKEN.txt | docker login docker.pkg.github.com -u $GH_USERNAME --password-stdin
2424
25-
#. Launch the Geometry service locally using Docker with:
25+
#. Pull the Geometry service locally using Docker with:
26+
2627

2728
.. code:: bash
2829
29-
docker run --name ans_geo -p 50051:50051 ghcr.io/pyansys/pygeometry:latest
30+
docker pull ghcr.io/pyansys/pygeometry:<tag>
31+
32+
The following OS-dependent tags are available:
33+
34+
* ``windows-latest``
35+
* ``windows-latest-unstable``
36+
37+
Launching the Geometry service
38+
------------------------------
39+
40+
The Geometry service can be launched locally in two different ways:
41+
42+
.. tab-set::
43+
44+
.. tab-item:: Using PyGeometry launcher
45+
46+
This method will directly launch for you the Geometry Service and it
47+
will provide a ``Modeler`` object.
48+
49+
.. code:: python
50+
51+
from ansys.geometry.core.connection import launch_modeler
52+
53+
modeler = launch_modeler()
54+
55+
The previous ``launch_modeler()`` method will launch the Geometry Service under the default
56+
conditions. For more configurability, please use ``launch_local_modeler()``.
57+
58+
.. tab-item:: Manual Geometry Service launch
59+
60+
This method will involve the user manually launching the Geometry Service. Afterwards, please
61+
refer to the next section in order to understand how to connect to it from PyGeometry.
62+
63+
.. code:: bash
64+
65+
docker run --name ans_geo -p 50051:50051 ghcr.io/pyansys/pygeometry:windows-latest
3066
3167
3268
Connect to the Geometry service

doc/source/user_guide/shapes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ which take as a starting point the last point of the previous edge.
4242
It is also able to get a desired shape of the sketch object by taking advantage of the user-defined labels.
4343

4444
.. code:: python
45+
4546
sketch.get("<tag>")
4647
4748
.. jupyter-execute::

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies = [
3838
"pyvista>=0.37.0",
3939
"scipy>=1.7.3",
4040
"six>=1.16.0",
41+
"docker>=6.0.1",
4142
]
4243

4344
[project.optional-dependencies]

src/ansys/geometry/core/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# Ease import statements
1616
# ------------------------------------------------------------------------------
1717

18-
from ansys.geometry.core.connection.launcher import launch_modeler
18+
from ansys.geometry.core.connection.launcher import (
19+
launch_local_modeler,
20+
launch_modeler,
21+
launch_remote_modeler,
22+
)
1923
from ansys.geometry.core.logger import LOG
2024
from ansys.geometry.core.modeler import Modeler

src/ansys/geometry/core/connection/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
unit_vector_to_grpc_direction,
99
)
1010
from ansys.geometry.core.connection.defaults import DEFAULT_HOST, DEFAULT_PORT
11-
from ansys.geometry.core.connection.launcher import launch_modeler
11+
from ansys.geometry.core.connection.launcher import (
12+
launch_local_modeler,
13+
launch_modeler,
14+
launch_remote_modeler,
15+
)
16+
from ansys.geometry.core.connection.localinstance import LocalDockerInstance

src/ansys/geometry/core/connection/client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from grpc_health.v1 import health_pb2, health_pb2_grpc
1212

1313
from ansys.geometry.core.connection.defaults import DEFAULT_HOST, DEFAULT_PORT, MAX_MESSAGE_LENGTH
14+
from ansys.geometry.core.connection.localinstance import LocalDockerInstance
1415
from ansys.geometry.core.logger import LOG as logger
1516
from ansys.geometry.core.logger import PyGeometryCustomAdapter
1617
from ansys.geometry.core.typing import Real
@@ -73,6 +74,11 @@ class GrpcClient:
7374
is launched through PyPIM. This instance is deleted when calling the
7475
:func:`GrpcClient.close <ansys.geometry.core.client.GrpcClient.close >`
7576
method.
77+
local_instance : LocalDockerInstance, default: None
78+
Corresponding local instance when the Geometry service is launched through
79+
the ``launch_local_modeler()`` interface. This instance will be deleted
80+
when the :func:`GrpcClient.close <ansys.geometry.core.client.GrpcClient.close >`
81+
method is called.
7682
timeout : real, default: 60
7783
Timeout in seconds to achieve the connection.
7884
logging_level : int, default: INFO
@@ -88,13 +94,15 @@ def __init__(
8894
port: Union[str, int] = DEFAULT_PORT,
8995
channel: Optional[grpc.Channel] = None,
9096
remote_instance: Optional["Instance"] = None,
97+
local_instance: Optional[LocalDockerInstance] = None,
9198
timeout: Optional[Real] = 60,
9299
logging_level: Optional[int] = logging.INFO,
93100
logging_file: Optional[Union[Path, str]] = None,
94101
):
95102
"""Initialize the ``GrpcClient`` object."""
96103
self._closed = False
97104
self._remote_instance = remote_instance
105+
self._local_instance = local_instance
98106
if channel:
99107
# Used for PyPIM when directly providing a channel
100108
self._channel = channel
@@ -162,10 +170,18 @@ def close(self):
162170
Notes
163171
-----
164172
If an instance of the Geometry service was started using
165-
PyPIM, this instance is deleted.
173+
PyPIM, this instance is deleted. Furthermore, if a local instance
174+
of the Geometry Service was started, it will be stopped.
166175
"""
167176
if self._remote_instance:
168177
self._remote_instance.delete() # pragma: no cover
178+
if self._local_instance:
179+
if not self._local_instance.existed_previously:
180+
self._local_instance.container.stop()
181+
else:
182+
self.log.warning(
183+
"Geometry Service will not be shutdown since it was already running..."
184+
)
169185
self._closed = True
170186
self._channel.close()
171187

src/ansys/geometry/core/connection/defaults.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
and if it does not exist, it falls back to ``127.0.0.1``.
1111
"""
1212

13-
DEFAULT_PORT = os.environ.get("ANSRV_GEO_PORT", 50051)
13+
DEFAULT_PORT: int = int(os.environ.get("ANSRV_GEO_PORT", 50051))
1414
"""
1515
Default HOST port used.
1616
@@ -25,3 +25,10 @@
2525
By default, it searches for the environment variable ``PYGEOMETRY_MAX_MESSAGE_LENGTH``,
2626
and if it does not exist, it falls back to ``256Mb``.
2727
"""
28+
29+
GEOMETRY_SERVICE_DOCKER_IMAGE = "ghcr.io/pyansys/pygeometry"
30+
"""
31+
Default Geometry Service Docker image location.
32+
33+
Tag is dependent on what OS service is requested.
34+
"""

0 commit comments

Comments
 (0)