Skip to content

Commit f681cd7

Browse files
committed
Refactor server package structure
Previously, the `server` was built only with the `repository` API endpoints in mind. Since we now plan to also support `registry` and `discovery`, we need to adapt the `./server` project structure. For this reason, we did the following refactoring: - This moves the `pyproject.toml` from the `app` directory into the server project's top-level directory (`./server/pyproject.toml`). This aligns the `server` project directory with the `sdk` and the `compliance-tool` project directories. See #466 - This also moves the files for Docker image definition into the `./server/docker` subdirectories, where `./server/docker/common` are shared files across different Docker images, and `./server/docker/repository` and others contain the `Dockerfile`, as well as the image specific configuration files. See #468 - This moves the Docker `compose.yaml` into the `./server/example_configurations` and its subdirectories. Each example configuration should have its own `README.md` specifying what the example contains and how to run it. See #468 - Lastly, this moves the repository specific `main.py` to `.server/app/services/run_repository.py` And this adapts (hopefully) all relevant paths in all the different files accordingly. Fixes #466 Fixes #468
1 parent 1548574 commit f681cd7

11 files changed

Lines changed: 40 additions & 61 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ jobs:
292292

293293
defaults:
294294
run:
295-
working-directory: ./server/app
295+
working-directory: ./server
296296
steps:
297297
- uses: actions/checkout@v4
298298
- name: Set up Python ${{ env.X_PYTHON_MIN_VERSION }}
@@ -302,11 +302,11 @@ jobs:
302302
- name: Install Python dependencies
303303
run: |
304304
python -m pip install --upgrade pip
305-
python -m pip install ../../sdk
305+
python -m pip install ../sdk
306306
python -m pip install .[dev]
307307
- name: Check typing with MyPy
308308
run: |
309-
python -m mypy .
309+
python -m mypy app test
310310
- name: Check code style with PyCodestyle
311311
run: |
312312
python -m pycodestyle --count --max-line-length 120 .
@@ -316,12 +316,12 @@ jobs:
316316
runs-on: ubuntu-latest
317317
defaults:
318318
run:
319-
working-directory: ./server
319+
working-directory: ./server/docker/repository
320320
steps:
321321
- uses: actions/checkout@v4
322322
- name: Build the Docker image
323323
run: |
324-
docker build -t basyx-python-server -f Dockerfile ..
324+
docker build -t basyx-python-server -f Dockerfile ../../..
325325
- name: Run container
326326
run: |
327327
docker run -d --name basyx-python-server basyx-python-server

server/README.md

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The container image can be built via:
1919
$ docker build -t basyx-python-server -f Dockerfile ..
2020
```
2121

22-
Note that when cloning this repository on Windows, Git may convert the line separators to CRLF. This breaks [`entrypoint.sh`](entrypoint.sh) and [`stop-supervisor.sh`](stop-supervisor.sh). Ensure both files use LF line separators (`\n`) before building.
22+
Note that when cloning this repository on Windows, Git may convert the line separators to CRLF. This breaks [`entrypoint.sh`](docker/repository/entrypoint.sh) and [`stop-supervisor.sh`](docker/common/stop-supervisor.sh). Ensure both files use LF line separators (`\n`) before building.
2323

2424
## Running
2525

@@ -60,51 +60,13 @@ This implies the following start-up behaviour:
6060
- Any AAS/Submodel *already present* is skipped, unless `STORAGE_OVERWRITE = True`, in which case it is replaced.
6161
- Supplementary files (e.g., `File` SubmodelElements) are never persisted by the LocalFileBackend.
6262

63-
### Running Examples
64-
65-
Putting it all together, the container can be started via the following command:
66-
```
67-
$ docker run -p 8080:80 -v ./input:/input -v ./storage:/storage basyx-python-server
68-
```
69-
70-
Since Windows uses backslashes instead of forward slashes in paths, you'll have to adjust the path to the storage directory there:
71-
```
72-
> docker run -p 8080:80 -v .\input:/input -v .\storage:/storage basyx-python-server
73-
```
74-
75-
By default, the server will use the standard settings described [above](#options). Those settings can be adapted in the following way:
76-
```
77-
$ docker run -p 8080:80 -v ./input:/input2 -v ./storage:/storage2 -e API_BASE_PATH=/api/v3.1/ -e INPUT=/input2 -e STORAGE=/storage2 -e STORAGE_PERSISTENCY=True -e STORAGE_OVERWRITE=True basyx-python-server
78-
```
79-
8063
## Building and Running the Image with Docker Compose
8164

82-
The container image can also be built and run via:
83-
```
84-
$ docker compose up
85-
```
86-
87-
An exemplary [`compose.yml`](compose.yml) file for the server is given [here](compose.yml):
88-
```yaml
89-
name: basyx-python-server
90-
services:
91-
app:
92-
build:
93-
context: ..
94-
dockerfile: server/Dockerfile
95-
ports:
96-
- "8080:80"
97-
volumes:
98-
- ./input:/input
99-
- ./storage:/storage
100-
environment:
101-
STORAGE_PERSISTENCY: True
102-
```
65+
Example configurations can be found in the `./example_configurations` directory.
10366

104-
Input files are read from `./input` and stored persistently under `./storage` on your host system. The server can be accessed at http://localhost:8080/api/v3.0/ from your host system.
105-
To get a different setup, the [`compose.yml`](compose.yml) file can be adapted using the options described [above](#options), similar to the third [running example](#running-examples).
67+
Currently, we offer:
10668

107-
Note that the `Dockerfile` has to be specified explicitly via `dockerfile: server/Dockerfile`, as the build context must be set to the parent directory of `/server` to allow access to the local `/sdk`.
69+
- [repository_standalone](example_configurations/repository_standalone/README.md): Standalone repository server
10870

10971
## Running without Docker (Debugging Only)
11072

server/app/services/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from basyx.aas.adapter.aasx import DictSupplementaryFileContainer
1515
from basyx.aas.backend.local_file import LocalFileIdentifiableStore
1616
from basyx.aas.model.provider import DictIdentifiableStore
17-
from interfaces.repository import WSGIApp
17+
from app.interfaces.repository import WSGIApp
1818
from typing import Tuple, Union
1919

2020

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ RUN apk update && \
1515
pip install uwsgi && \
1616
apk del git bash
1717

18-
19-
COPY server/uwsgi.ini /etc/uwsgi/
20-
COPY server/supervisord.ini /etc/supervisor/conf.d/supervisord.ini
21-
COPY server/stop-supervisor.sh /etc/supervisor/stop-supervisor.sh
18+
# Copy only the files we need to run the container
19+
# The argumentation for this is to keep the containers as slim as possible.
20+
COPY ./sdk /sdk
21+
COPY ./server/app /server/app
22+
COPY ./server/pyproject.toml /server/pyproject.toml
23+
COPY ./server/docker/repository/uwsgi.ini /etc/uwsgi/
24+
COPY ./server/docker/common/supervisord.ini /etc/supervisor/conf.d/supervisord.ini
25+
COPY ./server/docker/common/stop-supervisor.sh /etc/supervisor/stop-supervisor.sh
2226
RUN chmod +x /etc/supervisor/stop-supervisor.sh
2327

2428
# Makes it possible to use a different configuration
@@ -41,17 +45,15 @@ ENV STORAGE_OVERWRITE=False
4145
VOLUME ["/input", "/storage"]
4246

4347
# Copy the entrypoint that will generate Nginx additional configs
44-
COPY server/entrypoint.sh /entrypoint.sh
48+
COPY server/docker/repository/entrypoint.sh /entrypoint.sh
4549
RUN chmod +x /entrypoint.sh
4650

4751
ENTRYPOINT ["/entrypoint.sh"]
4852

4953
ENV SETUPTOOLS_SCM_PRETEND_VERSION=1.0.0
5054

51-
COPY ./sdk /sdk
52-
COPY ./server/app /app
53-
WORKDIR /app
54-
RUN pip install ../sdk
55-
RUN pip install .
55+
WORKDIR /server/app
56+
RUN pip install ../../sdk
57+
RUN pip install ..
5658

5759
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.ini"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[uwsgi]
2-
wsgi-file = /app/main.py
2+
wsgi-file = /server/app/services/run_repository.py
33
socket = /tmp/uwsgi.sock
44
chown-socket = nginx:nginx
55
chmod-socket = 664
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Repository Standalone
2+
3+
This example Docker compose configuration starts a repository server.
4+
5+
The container image can also be built and run via:
6+
```
7+
$ docker compose up
8+
```
9+
10+
Input files are read from `./input` and stored persistently under `./storage` on your host system.
11+
The server can be accessed at http://localhost:8080/api/v3.0/ from your host system.
12+
To get a different setup, the `compose.yaml` file can be adapted using the options described in the main server [README.md](../../README.md#options), similar to the third [running example](#running-examples).
13+
14+
Note that the `Dockerfile` has to be specified explicitly via `dockerfile: server/Dockerfile`, as the build context must be set to the parent directory of `/server` to allow access to the local `/sdk`.
15+

0 commit comments

Comments
 (0)