You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, the repository server used one and the same folder for
loading data during start-up and storing it persistently. This resulted
in a mixture of input AAS/Submodel files (AASX, JSON and XML) and
persistently stored AAS/Submodel files from the `LocalFileObjectStore`
(JSON).
This separates the server's input and storage into two different
directories to prevent their files being mixed. Moreover, the option to
overwrite existing AAS/Submodels in the storage got added and the option
to persistently store data got adapted. In accordance with the new
changes, the `README` and `Dockerfile` were adapted to present the
changes to the end users.
Fixes#404
---------
Co-authored-by: s-heppner <[email protected]>
Co-authored-by: Igor Garmaev <[email protected]>
It uses the [HTTP API][1] and the [AASX][7], [JSON][8], and [XML][9] Adapters of the [BaSyx Python SDK][3], to serve regarding files from a given directory.
9
+
It uses the [HTTP API][1] and the [*AASX*][7], [*JSON*][8], and [*XML*][9] Adapters of the [BaSyx Python SDK][3], to serve regarding files from a given directory.
10
10
The files are only read, changes won't persist.
11
11
12
-
Alternatively, the container can also be told to use the [Local-File Backend][2] instead, which stores AAS and Submodels as individual JSON files and allows for persistent changes (except supplementary files, i.e. files referenced by `File`submodel elements).
12
+
Alternatively, the container can also be told to use the [Local-File Backend][2] instead, which stores Asset Administration Shells (AAS) and Submodels as individual *JSON* files and allows for persistent changes (except supplementary files, i.e. files referenced by `File`SubmodelElements).
13
13
See [below](#options) on how to configure this.
14
14
15
15
## Building
@@ -19,17 +19,20 @@ The container image can be built via:
Note that when cloning this repository on Windows, Git may convert the line separators to CRLF. This breaks `entrypoint.sh` and `stop-supervisor.sh`. Ensure both files use LF line separators before building.
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.
23
23
24
24
## Running
25
25
26
26
### Storage
27
27
28
-
The container needs to be provided with the directory `/storage` to store AAS and Submodel files: AASX, JSON, XML or JSON files of Local-File Backend.
28
+
The server makes use of two directories:
29
29
30
-
This directory can be mapped via the `-v` option from another image or a local directory.
31
-
To map the directory `storage` inside the container, `-v ./storage:/storage` can be used.
32
-
The directory `storage` will be created in the current working directory, if it doesn't already exist.
30
+
-**`/input`** - *start-up data*: Directory from which the server loads AAS and Submodel files in *AASX*, *JSON* or *XML* format during start-up. The server will not modify these files.
31
+
-**`/storage`** - *persistent store*: Directory where all AAS and Submodels are stored as individual *JSON* files if the server is [configured](#options) for persistence. The server will modify these files.
32
+
33
+
The directories can be mapped via the `-v` option from another image or a local directory.
34
+
To mount the host directories into the container, `-v ./input:/input -v ./storage:/storage` can be used.
35
+
Both local directories `./input` and `./storage` will be created in the current working directory, if they don't already exist.
33
36
34
37
### Port
35
38
@@ -38,31 +41,40 @@ To expose it on the host on port 8080, use the option `-p 8080:80` when running
38
41
39
42
### Options
40
43
41
-
The container can be configured via environment variables:
42
-
-`API_BASE_PATH` determines the base path under which all other API paths are made available.
43
-
Default: `/api/v3.0`
44
-
-`STORAGE_TYPE` can be one of `LOCAL_FILE_READ_ONLY` or `LOCAL_FILE_BACKEND`:
45
-
- When set to `LOCAL_FILE_READ_ONLY` (the default), the server will read and serve AASX, JSON, XML files from the storage directory.
46
-
The files are not modified, all changes done via the API are only stored in memory.
47
-
- When instead set to `LOCAL_FILE`, the server makes use of the [LocalFileBackend][2], where AAS and Submodels are persistently stored as JSON files.
48
-
Supplementary files, i.e. files referenced by `File` submodel elements, are not stored in this case.
49
-
-`STORAGE_PATH` sets the directory to read the files from *within the container*. If you bind your files to a directory different from the default `/storage`, you can use this variable to adjust the server accordingly.
44
+
The container can be configured via environment variables. The most important ones are summarised below:
|`API_BASE_PATH`| Base path under which the API is served. |`/api/v3.0/`|
49
+
|`INPUT`| Path inside the container pointing to the directory from which the server takes its start-up data (*AASX*, *JSON*, *XML*). |`/input`|
50
+
|`STORAGE`| Path inside the container pointing to the directory used by the server to persistently store data (*JSON*). |`/storage`|
51
+
|`STORAGE_PERSISTENCY`| Flag to enable data persistence via the [LocalFileBackend][2]. AAS/Submodels are stored as *JSON* files in the directory specified by `STORAGE`. Supplementary files, i.e. files referenced by `File` SubmodelElements, are not stored. If disabled, any changes made via the API are only stored in memory. |`False`|
52
+
|`STORAGE_OVERWRITE`| Flag to enable storage overwrite if `STORAGE_PERSISTENCY` is enabled. Any AAS/Submodel from the `INPUT` directory already present in the LocalFileBackend replaces its existing version. If disabled, the existing version is kept. |`False`|
53
+
54
+
55
+
This implies the following start-up behaviour:
56
+
57
+
- Any AAS/Submodel found in `INPUT` is loaded during start-up.
58
+
- If `STORAGE_PERSISTENCY = True`:
59
+
- Any AAS/Submodel *not* present in the LocalFileBackend is added to it.
60
+
- Any AAS/Submodel *already present* is skipped, unless `STORAGE_OVERWRITE = True`, in which case it is replaced.
61
+
- Supplementary files (e.g., `File` SubmodelElements) are never persisted by the LocalFileBackend.
50
62
51
63
### Running Examples
52
64
53
65
Putting it all together, the container can be started via the following command:
54
66
```
55
-
$ docker run -p 8080:80 -v ./storage:/storage basyx-python-server
67
+
$ docker run -p 8080:80 -v ./input:/input -v ./storage:/storage basyx-python-server
56
68
```
57
69
58
70
Since Windows uses backslashes instead of forward slashes in paths, you'll have to adjust the path to the storage directory there:
59
71
```
60
-
> docker run -p 8080:80 -v .\storage:/storage basyx-python-server
72
+
> docker run -p 8080:80 -v .\input:/input -v .\storage:/storage basyx-python-server
61
73
```
62
74
63
-
Per default, the server will use the `LOCAL_FILE_READ_ONLY` storage type and serve the API under `/api/v3.0` and read files from `/storage`. If you want to change this, you can do so like this:
75
+
By default, the server will use the standard settings described [above](#options). Those settings can be adapted in the following way:
## Building and Running the Image with Docker Compose
@@ -72,8 +84,9 @@ The container image can also be built and run via:
72
84
$ docker compose up
73
85
```
74
86
75
-
This is the exemplary `compose.yml` file for the server:
87
+
An exemplary [`compose.yml`](compose.yml) file for the server is given [here](compose.yml):
76
88
```yaml
89
+
name: basyx-python-server
77
90
services:
78
91
app:
79
92
build:
@@ -82,13 +95,16 @@ services:
82
95
ports:
83
96
- "8080:80"
84
97
volumes:
98
+
- ./input:/input
85
99
- ./storage:/storage
100
+
environment:
101
+
STORAGE_PERSISTENCY: True
86
102
```
87
103
88
-
Here files are read from `/storage` and the server can be accessed at http://localhost:8080/api/v3.0/ from your host system.
89
-
To get a different setup this compose.yaml file can be adapted and expanded.
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).
90
106
91
-
Note that the `Dockerfile` has to be specified explicitly, as the build context must be set to the parent directory of `/server` to allow access to the local `/sdk`.
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`.
92
108
93
109
## Running without Docker (Debugging Only)
94
110
@@ -103,7 +119,7 @@ The server can also be run directly on the host system without Docker, NGINX and
103
119
$ pip install ./app
104
120
```
105
121
106
-
2. Run the server by executing the main function in [`./app/interfaces/repository.py`](./app/interfaces/repository.py) from within the current folder.
122
+
2. Run the server by executing the main function in [`./app/interfaces/repository.py`](./app/interfaces/repository.py).
107
123
```bash
108
124
$ python -m app.interfaces.repository
109
125
```
@@ -119,7 +135,7 @@ This Dockerfile is inspired by the [tiangolo/uwsgi-nginx-docker][10] repository.
0 commit comments