Skip to content

Commit a55629a

Browse files
b-matteoRobPasMueMaxJPRey
authored
Implementation of API server on Geometry Service (#291)
Co-authored-by: Roberto Pastor Muela <roberto.pastormuela@ansys.com> Co-authored-by: Maxime Rey <87315832+MaxJPRey@users.noreply.github.com>
1 parent 9a44cc4 commit a55629a

26 files changed

+338
-195
lines changed

.ci/clean_registry.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
3+
from ghapi.all import GhApi
4+
from ghapi.core import print_summary
5+
from ghapi.page import paged
6+
7+
org_str = "pyansys"
8+
pck_str = "geometry"
9+
valid_tags = ["windows-latest", "windows-latest-unstable", "linux-latest", "linux-latest-unstable"]
10+
11+
api = GhApi(debug=print_summary, token=os.getenv("PACKAGE_DELETION_TOKEN"))
12+
13+
paged_packages = paged(
14+
api.packages.get_all_package_versions_for_package_owned_by_org,
15+
org=org_str,
16+
package_name=pck_str,
17+
package_type="container",
18+
state="active",
19+
per_page=100,
20+
)
21+
22+
# Loop over all pages
23+
for page in paged_packages:
24+
for package in page:
25+
# Check if the given package should be deleted
26+
package_tags = package.metadata.container.tags
27+
delete = True
28+
for tag in package_tags:
29+
if tag in valid_tags:
30+
delete = False
31+
break
32+
33+
# In case it should, delete it
34+
if delete:
35+
print("Deleting:" + package)
36+
api.packages.delete_package_version_for_org(
37+
org=org_str,
38+
package_name=pck_str,
39+
package_type="container",
40+
package_version_id=package["id"],
41+
)

.github/workflows/ci_cd.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ 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:windows-latest
16+
ANSRV_GEO_IMAGE: ghcr.io/pyansys/geometry:windows-latest
1717
ANSRV_GEO_PORT: 700
18+
ANSRV_GEO_LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
1819
GEO_CONT_NAME: ans_geo
1920
RESET_IMAGE_CACHE: 6
2021
IS_WORKFLOW_RUNNING: True
@@ -127,7 +128,7 @@ jobs:
127128
run: |
128129
.\.venv\Scripts\Activate.ps1
129130
$env:ANSRV_GEO_PORT_MAP = $env:ANSRV_GEO_PORT + ":50051"
130-
docker run --detach --name $env:GEO_CONT_NAME -p $env:ANSRV_GEO_PORT_MAP $env:ANSRV_GEO_IMAGE
131+
docker run --detach --name $env:GEO_CONT_NAME -e LICENSE_SERVER=$env:ANSRV_GEO_LICENSE_SERVER -p $env:ANSRV_GEO_PORT_MAP $env:ANSRV_GEO_IMAGE
131132
python -c "from ansys.geometry.core.connection.validate import validate; validate()"
132133
133134
- uses: actions/cache@v3
@@ -215,7 +216,7 @@ jobs:
215216
run: |
216217
.\.venv\Scripts\Activate.ps1
217218
$env:ANSRV_GEO_PORT_MAP = $env:ANSRV_GEO_PORT + ":50051"
218-
docker run --detach --name $env:GEO_CONT_NAME -p $env:ANSRV_GEO_PORT_MAP $env:ANSRV_GEO_IMAGE
219+
docker run --detach --name $env:GEO_CONT_NAME -e LICENSE_SERVER=$env:ANSRV_GEO_LICENSE_SERVER -p $env:ANSRV_GEO_PORT_MAP $env:ANSRV_GEO_IMAGE
219220
python -c "from ansys.geometry.core.connection.validate import validate; validate()"
220221
221222
- name: Build the documentation (HTML)

.github/workflows/nightly_docker_test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ jobs:
1717
name: Run all tests against server
1818
runs-on: [self-hosted, pygeometry]
1919
env:
20-
ANSRV_GEO_IMAGE: ghcr.io/pyansys/pygeometry:windows-latest-unstable
20+
ANSRV_GEO_IMAGE: ghcr.io/pyansys/geometry:windows-latest-unstable
2121
ANSRV_GEO_PORT: 710
22+
ANSRV_GEO_LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
2223
GEO_CONT_NAME: ans_geo_nightly
2324

2425
steps:
@@ -59,7 +60,7 @@ jobs:
5960
run: |
6061
.\.venv\Scripts\Activate.ps1
6162
$env:ANSRV_GEO_PORT_MAP = $env:ANSRV_GEO_PORT + ":50051"
62-
docker run --detach --name $env:GEO_CONT_NAME -p $env:ANSRV_GEO_PORT_MAP $env:ANSRV_GEO_IMAGE
63+
docker run --detach --name $env:GEO_CONT_NAME -e LICENSE_SERVER=$env:ANSRV_GEO_LICENSE_SERVER -p $env:ANSRV_GEO_PORT_MAP $env:ANSRV_GEO_IMAGE
6364
python -c "from ansys.geometry.core.connection.validate import validate; validate()"
6465
6566
- name: Run PyGeometry tests

.github/workflows/package_cleanup.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Geometry Service - Package cleanup
2+
on:
3+
workflow_dispatch:
4+
schedule: # UTC at 0200
5+
- cron: "0 2 * * *"
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: write
13+
packages: write
14+
15+
jobs:
16+
cleanup:
17+
name: Cleaning unnecessary packages
18+
runs-on: ubuntu-latest
19+
env:
20+
PACKAGE_DELETION_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
22+
steps:
23+
- name: "Checkout repository"
24+
uses: actions/checkout@v3
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v4
28+
29+
- name: "Install requirements"
30+
run: |
31+
pip install ghapi
32+
33+
- name: "Perform cleanup"
34+
run: |
35+
python -m .ci/clean_registry.py

README.rst

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,45 @@ 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.
39+
There are two different ways of getting started with the Geometry service and its client-library, PyGeometry.
4040

4141
Using PyGeometry launcher
4242
^^^^^^^^^^^^^^^^^^^^^^^^^
4343

4444
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:
45+
launching the Geometry service locally. The only requirements are that:
4646

4747
* Docker is installed on your machine.
48-
* You have access to the PyAnsys GitHub container registry, where the Geometry Service image is hosted.
48+
* You have access to the PyAnsys GitHub container registry, where the Geometry service image is hosted.
4949

5050
.. caution::
5151

52-
The Geometry Service is currently available only as a Windows Docker image. The development
52+
The Geometry service is currently available only as a Windows Docker image. The development
5353
team is working on getting the Linux Docker container available as soon as possible. In the meantime,
5454
make sure that your Docker engine is configured to run Windows Docker images.
5555

5656
First, bear in mind that you have to be `authenticated to ghcr.io
5757
<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:
58+
Once authenticated, please proceed to download the Geometry service Docker image:
5959

6060
.. code:: bash
6161
62-
docker pull ghcr.io/pyansys/pygeometry:<tag>
62+
docker pull ghcr.io/pyansys/geometry:<tag>
6363
6464
The following OS-dependent tags are available:
6565

6666
* ``windows-latest``
6767
* ``windows-latest-unstable``
6868

69-
Next, you will be ready to run the Geometry Service directly from PyGeometry:
69+
Next, you will be ready to run the Geometry service directly from PyGeometry:
7070

7171
.. code:: python
7272
7373
from ansys.geometry.core.connection import launch_modeler
7474
7575
modeler = launch_modeler()
7676
77-
The previous ``launch_modeler()`` method will launch the Geometry Service under the default
77+
The previous ``launch_modeler()`` method will launch the Geometry service under the default
7878
conditions. For more configurability, please use ``launch_local_modeler()``.
7979

8080
Manual service launch
@@ -85,7 +85,17 @@ First, start the Geometry service locally. If you have Docker installed and have
8585

8686
.. code:: bash
8787
88-
docker run --name ans_geo -p 50051:50051 ghcr.io/pyansys/pygeometry:windows-latest
88+
docker run --name ans_geo -e LICENSE_SERVER=<LICENSE-SERVER> -p 50051:50051 ghcr.io/pyansys/geometry:windows-latest
89+
90+
The Geometry service has a set of environment variables that are **mandatory**:
91+
92+
* ``LICENSE_SERVER``: the license server (IP, DNS) to which the Geometry service shall connect. For example, ``127.0.0.1``.
93+
94+
Other optional environment variables are:
95+
96+
* ``ENABLE_TRACE``: whether to set up the trace level for debugging purposes. Expects either ``1`` or ``0``.
97+
By default, ``0`` (which means it is not activated).
98+
* ``LOG_LEVEL``: sets the Geometry service logging level. By default, ``2``.
8999

90100
Next, connect to the service with:
91101

doc/source/getting_started/docker.rst

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Install the PyGeometry image
2727

2828
.. code:: bash
2929
30-
docker pull ghcr.io/pyansys/pygeometry:<tag>
30+
docker pull ghcr.io/pyansys/geometry:<tag>
3131
3232
The following OS-dependent tags are available:
3333

@@ -37,13 +37,65 @@ Install the PyGeometry image
3737
Launching the Geometry service
3838
------------------------------
3939

40+
In this section there are two mechanisms for launching the Geometry service: either **using the PyGeometry launcher**
41+
or **manually launching the service**.
42+
43+
Environment variables
44+
^^^^^^^^^^^^^^^^^^^^^
45+
46+
The Geometry service has a set of environment variables that are **mandatory** for its use:
47+
48+
* ``LICENSE_SERVER``: the license server (IP, DNS) to which the Geometry service shall connect. For example, ``127.0.0.1``.
49+
50+
Other optional environment variables are:
51+
52+
* ``ENABLE_TRACE``: whether to set up the trace level for debugging purposes. Expects either ``1`` or ``0``.
53+
By default, ``0`` (which means it is not activated).
54+
* ``LOG_LEVEL``: sets the Geometry service logging level. By default, ``2``.
55+
56+
Depending on the mechanism chosen to launch the Geometry service, you can set them as follows:
57+
58+
.. tab-set::
59+
60+
.. tab-item:: Using PyGeometry launcher
61+
62+
In this case, users will have to define the following general environment variables prior
63+
to launching it. Bare in mind that the naming of the variables is not the same:
64+
65+
.. tab-set::
66+
67+
.. tab-item:: Linux/Mac
68+
69+
.. code-block:: bash
70+
71+
export ANSRV_GEO_LICENSE_SERVER=127.0.0.1
72+
export ANSRV_GEO_ENABLE_TRACE=0
73+
export ANSRV_GEO_LOG_LEVEL=2
74+
75+
.. tab-item:: Windows
76+
77+
.. code-block:: bash
78+
79+
SET ANSRV_GEO_LICENSE_SERVER=127.0.0.1
80+
SET ANSRV_GEO_ENABLE_TRACE=0
81+
SET ANSRV_GEO_LOG_LEVEL=2
82+
83+
.. tab-item:: Manual Geometry service launch
84+
85+
In this case, there is no prior environment variable definition needed. They can
86+
directly be passed to the Docker container itself.
87+
88+
89+
Geometry service launcher
90+
^^^^^^^^^^^^^^^^^^^^^^^^^
91+
4092
The Geometry service can be launched locally in two different ways:
4193

4294
.. tab-set::
4395

4496
.. tab-item:: Using PyGeometry launcher
4597

46-
This method will directly launch for you the Geometry Service and it
98+
This method will directly launch for you the Geometry service and it
4799
will provide a ``Modeler`` object.
48100

49101
.. code:: python
@@ -52,17 +104,18 @@ The Geometry service can be launched locally in two different ways:
52104
53105
modeler = launch_modeler()
54106
55-
The previous ``launch_modeler()`` method will launch the Geometry Service under the default
107+
The previous ``launch_modeler()`` method will launch the Geometry service under the default
56108
conditions. For more configurability, please use ``launch_local_modeler()``.
57109

58-
.. tab-item:: Manual Geometry Service launch
110+
.. tab-item:: Manual Geometry service launch
59111

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.
112+
This method will involve the user manually launching the Geometry service. Remember to pass
113+
in the different environment variables needed. Afterwards, please refer to the next section in
114+
order to understand how to connect to it from PyGeometry.
62115

63116
.. code:: bash
64117
65-
docker run --name ans_geo -p 50051:50051 ghcr.io/pyansys/pygeometry:windows-latest
118+
docker run --name ans_geo -e LICENSE_SERVER=<LICENSE_SERVER> -p 50051:50051 ghcr.io/pyansys/geometry:windows-latest
66119
67120
68121
Connect to the Geometry service

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
name = "ansys-geometry-core"
77
version = "0.2.dev0"
8-
description = "A python wrapper for Ansys Geometry Service"
8+
description = "A python wrapper for Ansys Geometry service"
99
readme = "README.rst"
1010
requires-python = ">=3.7,<4"
1111
license = {file = "LICENSE"}
@@ -25,7 +25,7 @@ classifiers = [
2525
]
2626

2727
dependencies = [
28-
"ansys-api-geometry==0.1.3",
28+
"ansys-api-geometry==0.2.0",
2929
"beartype>=0.11.0",
3030
"google-api-python-client>=1.7.11",
3131
"googleapis-common-protos>=1.52.0",
@@ -38,7 +38,6 @@ dependencies = [
3838
"pyvista>=0.37.0",
3939
"scipy>=1.7.3",
4040
"six>=1.16.0",
41-
"docker>=6.0.1",
4241
]
4342

4443
[project.optional-dependencies]
@@ -55,6 +54,7 @@ tests = [
5554
"scipy==1.10.0",
5655
"six==1.16.0",
5756
"ansys-platform-instancemanagement==1.0.3",
57+
"docker==6.0.1",
5858
"pytest==7.2.1",
5959
"pytest-cov==4.0.0",
6060
"pytest-pyvista==0.1.5",
@@ -70,9 +70,9 @@ doc = [
7070
"notebook==6.5.2",
7171
"numpydoc==1.5.0",
7272
"panel==0.14.3",
73-
"Sphinx==5.1.1",
73+
"Sphinx==5.1.1", # PR349 - Duplicated documentation entries...
7474
"sphinx-autoapi==2.0.1",
75-
"sphinx-autodoc-typehints==1.19.1",
75+
"sphinx-autodoc-typehints==1.19.1", # PR349 - Duplicated documentation entries...
7676
"sphinx-copybutton==0.5.1",
7777
"sphinx_design==0.3.0",
7878
"sphinx-gallery==0.7.0",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def close(self):
176176
-----
177177
If an instance of the Geometry service was started using
178178
PyPIM, this instance is deleted. Furthermore, if a local instance
179-
of the Geometry Service was started, it will be stopped.
179+
of the Geometry service was started, it will be stopped.
180180
"""
181181
if self._remote_instance:
182182
self._remote_instance.delete() # pragma: no cover
@@ -185,7 +185,7 @@ def close(self):
185185
self._local_instance.container.stop()
186186
else:
187187
self.log.warning(
188-
"Geometry Service will not be shutdown since it was already running..."
188+
"Geometry service will not be shutdown since it was already running..."
189189
)
190190
self._closed = True
191191
self._channel.close()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
and if it does not exist, it falls back to ``256Mb``.
2727
"""
2828

29-
GEOMETRY_SERVICE_DOCKER_IMAGE = "ghcr.io/pyansys/pygeometry"
29+
GEOMETRY_SERVICE_DOCKER_IMAGE = "ghcr.io/pyansys/geometry"
3030
"""
31-
Default Geometry Service Docker image location.
31+
Default Geometry service Docker image location.
3232
3333
Tag is dependent on what OS service is requested.
3434
"""

0 commit comments

Comments
 (0)