Skip to content

Commit fe9a30e

Browse files
committed
docs(model-server): properly document how to start a model-server
1 parent 5748db2 commit fe9a30e

File tree

1 file changed

+186
-10
lines changed

1 file changed

+186
-10
lines changed
Lines changed: 186 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,203 @@
11
= How-To start a local `model-server`
22
:navtitle: Start a `model-server`
33

4-
54
NOTE: If you are interested in a more practical usage of what is presented here, check out the https://github.com/modelix/modelix.samples[samples project^]
65

6+
== Backends: In Memory vs. Database
7+
8+
The `model-server` will by default require a database backend.
9+
While this setup is ideal for deployment, it might not what you need in the beginning.
10+
The `-jdbcconf` flag allows you to provide a custom jdbc configuration file.
11+
12+
However, during development or to perform tests, it is recommended to start the `model-server` with in-memory storage.
13+
This can be achieved by adding the `-inmemory` flag to the executable.
14+
15+
16+
== Running a `model-server`
17+
18+
The following list gives an overview of the many ways to run a `model-server`:
19+
20+
21+
=== 1. Docker
22+
23+
We publish a docker container of the `model-server` over on https://hub.docker.com/r/modelix/model-server/tags[docker hub].
24+
To run the container, simply call the following:
25+
26+
[source, shell]
27+
--
28+
$ docker run --rm -p 28101:28101 modelix/modelix-model:latest -inmemory
29+
--
30+
31+
32+
=== 2. `docker-compose`
33+
34+
To run the `model-server` in memory, you can use:
35+
36+
.Content of `docker-compose.yml`
37+
[source, yaml]
38+
--
39+
name: model-server-run-in-memory
40+
41+
services:
42+
model-server:
43+
image: modelix/model-server:latest0
44+
ports:
45+
- 28101:28101
46+
command: [ "-inmemory" ]
47+
--
48+
49+
Run using `docker-compose` via:
50+
51+
[source, shell]
52+
--
53+
$ docker-compose up
54+
--
55+
56+
NOTE: For more integrated examples, have a look at the
57+
xref:samples:monitoring.adoc[model server]
58+
monitoring setup in the samples, which starts the `model-server` using `docker-compose`.
59+
60+
For more complex setups, which require a database backend, you can use the following:
61+
62+
.Content of `docker-compose.yml`
63+
[source, yaml]
64+
--
65+
name: model-server-run-database
66+
67+
services:
68+
model-server:
69+
image: modelix/model-server:4.5.0
70+
restart: always
71+
healthcheck:
72+
test: ["CMD-SHELL", "curl http://localhost:28101/health"]
73+
interval: 2s
74+
timeout: 3s
75+
retries: 10
76+
depends_on:
77+
model-server-db:
78+
condition: service_healthy
79+
environment:
80+
jdbc_url: jdbc:postgresql://model-server-db:5432/modelix?currentSchema=modelix
81+
ports:
82+
- 28101:28101
83+
84+
model-server-db:
85+
image: postgres:16
86+
environment:
87+
POSTGRES_PASSWORD: modelix
88+
POSTGRES_DB: modelix
89+
POSTGRES_USER: modelix
90+
PGDATA: /var/lib/postgresql/data/pgdata
91+
healthcheck:
92+
test: ["CMD-SHELL", "pg_isready -U modelix -d modelix"]
93+
interval: 10s
94+
timeout: 3s
95+
retries: 10
96+
volumes:
97+
- model-server-db:/var/lib/postgresql/data
98+
- ./init-database.sql:/docker-entrypoint-initdb.d/init-database.sql:z
99+
100+
volumes:
101+
model-server-db: {}
102+
dashboard-db: {}
103+
--
104+
105+
.Content of `init-database.sql`
106+
[source, SQL]
107+
--
108+
CREATE SCHEMA modelix;
109+
GRANT ALL ON SCHEMA modelix TO modelix;
110+
111+
CREATE TABLE modelix.model
112+
(
113+
key character varying NOT NULL,
114+
value character varying,
115+
reachable boolean,
116+
CONSTRAINT kv_pkey PRIMARY KEY (key)
117+
);
118+
GRANT ALL ON TABLE modelix.model TO modelix;
119+
--
120+
121+
Run using `docker-compose` via:
122+
123+
[source, shell]
124+
--
125+
$ docker-compose up
126+
--
127+
128+
129+
=== 3. Gradle via Dependency
130+
131+
When using Gradle, you run a `model-server` as in the following minimal working example:
132+
133+
.Content of minimal `build.gradle.kts` to run a `model-server` in memory
134+
[source, kotlin]
135+
--
136+
plugins {
137+
application
138+
}
139+
140+
repositories {
141+
mavenCentral()
142+
maven { url = uri("https://artifacts.itemis.cloud/repository/maven-mps/") }
143+
}
144+
145+
dependencies {
146+
implementation("org.modelix:model-server:4.6.0")
147+
}
148+
149+
application {
150+
mainClass.set("org.modelix.model.server.Main")
151+
}
152+
153+
tasks.run.configure {
154+
args("-inmemory")
155+
// note: you can add other arguments here, e.g.
156+
// args("-inmemory", "-dumpin", "/path/to/dump/file.dump")
157+
}
158+
--
159+
160+
You can run it simply by running
161+
162+
[source, bash]
163+
--
164+
./gradlew run
165+
--
166+
167+
=== 4. Gradle via Source
168+
169+
Use `git` to check out the modelix core repository from
7170

8-
- To run the model-server with default configuration run:
9-
+
10171
[source,bash]
11172
--
12-
[modelix.core] $ ./gradlew model-server:run
173+
https://github.com/modelix/modelix.core
13174
--
14175

15-
- To specify a different jdbc configuration, you can add the `-jdbcconf` arguement:
16-
+
176+
To run the model-server with default configuration run:
177+
17178
[source,bash]
18179
--
19-
[modelix.core] $ ./gradlew model-server:run --args='-jdbcconf path-to-my-database.properties'
180+
[modelix.core] $ ./gradlew model-server:run
20181
--
21182

22-
- During development or to perform tests it is recommended to start the `model-server` with in-memory storage:
23-
+
183+
NOTE: You will have to build the project first, which might take some time depending on your hardware.
184+
185+
186+
[NOTE]
187+
====
188+
To give arguments to the gradle run command, you have to add them via the `--args` flag:
189+
24190
[source,bash]
25191
--
26-
[modelix.core] $ ./gradlew model-server:run --args='-inmemory'
192+
./gradlew model-server:run --args='-jdbcconf path-to-my-database.properties -dumpout'
27193
--
194+
====
195+
196+
197+
=== 5. *In Process* (Kotlin)
198+
199+
This rather advanced version allows you to run the model-server inside your own application.
200+
You can find an examples of this in these code fragments:
201+
202+
* https://github.com/modelix/modelix.core/blob/main/model-server/src/test/kotlin/org/modelix/model/server/ModelClientV2Test.kt#L48[ModelClientV2Test (modelix core tests)]
203+
* https://github.com/modelix/modelix.core/blob/main/mps-model-server-plugin/src/main/kotlin/org/modelix/model/server/mps/MPSModelServer.kt#L77C22-L77C38[`MPSModelServer.kt` (Implementation of the 'MPS as Modelix Model Server' plugin)]

0 commit comments

Comments
 (0)