|
1 | 1 | = How-To start a local `model-server`
|
2 | 2 | :navtitle: Start a `model-server`
|
3 | 3 |
|
4 |
| - |
5 | 4 | 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^]
|
6 | 5 |
|
| 6 | +NOTE: To run a light version of the `model-sever`, check out xref:core:howto/mps-model-server-plugin.adoc[] |
| 7 | + |
| 8 | +== Backends: In Memory vs. Database |
| 9 | + |
| 10 | +The `model-server` will by default require a database backend. |
| 11 | +The `-jdbcconf` flag allows you to provide a custom JDBC configuration file. |
| 12 | +While this setup is ideal for deployment, it might not what you need in the beginning. |
| 13 | +During development or to perform tests, it is recommended to start the `model-server` with in-memory storage. |
| 14 | +This can be achieved by adding the `-inmemory` flag to the executable. |
| 15 | + |
| 16 | + |
| 17 | +== Running a `model-server` |
| 18 | + |
| 19 | +The following list gives an overview of the many ways to run a `model-server`: |
| 20 | + |
| 21 | + |
| 22 | +=== 1. Docker |
| 23 | + |
| 24 | +We publish a Docker container of the `model-server` over on https://hub.docker.com/r/modelix/model-server/tags[Docker Hub^]. |
| 25 | +To run the model-server container with the in-memory backend, simply call the following. |
| 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 | +If you use `docker-compose`, use the following. |
| 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 xref:core:howto/metrics.adoc[metrics and monitoring] capabilities, which shows how to start the `model-server` using `docker-compose`. |
| 57 | + |
| 58 | +For more complex setups, which require a database backend, you can use the following: |
| 59 | + |
| 60 | +.Content of `docker-compose.yml` |
| 61 | +[source, yaml] |
| 62 | +-- |
| 63 | +name: model-server-run-database |
| 64 | + |
| 65 | +services: |
| 66 | + model-server: |
| 67 | + image: modelix/model-server:4.5.0 |
| 68 | + restart: always |
| 69 | + healthcheck: |
| 70 | + test: ["CMD-SHELL", "curl http://localhost:28101/health"] |
| 71 | + interval: 2s |
| 72 | + timeout: 3s |
| 73 | + retries: 10 |
| 74 | + depends_on: |
| 75 | + model-server-db: |
| 76 | + condition: service_healthy |
| 77 | + environment: |
| 78 | + jdbc_url: jdbc:postgresql://model-server-db:5432/modelix?currentSchema=modelix |
| 79 | + ports: |
| 80 | + - 28101:28101 |
| 81 | + |
| 82 | + model-server-db: |
| 83 | + image: postgres:16 |
| 84 | + environment: |
| 85 | + POSTGRES_PASSWORD: modelix |
| 86 | + POSTGRES_DB: modelix |
| 87 | + POSTGRES_USER: modelix |
| 88 | + PGDATA: /var/lib/postgresql/data/pgdata |
| 89 | + healthcheck: |
| 90 | + test: ["CMD-SHELL", "pg_isready -U modelix -d modelix"] |
| 91 | + interval: 10s |
| 92 | + timeout: 3s |
| 93 | + retries: 10 |
| 94 | + volumes: |
| 95 | + - model-server-db:/var/lib/postgresql/data |
| 96 | + - ./init-database.sql:/docker-entrypoint-initdb.d/init-database.sql:z |
| 97 | + |
| 98 | +volumes: |
| 99 | + model-server-db: {} |
| 100 | +-- |
| 101 | + |
| 102 | +.Content of `init-database.sql` |
| 103 | +[source, SQL] |
| 104 | +-- |
| 105 | +CREATE SCHEMA modelix; |
| 106 | +GRANT ALL ON SCHEMA modelix TO modelix; |
| 107 | + |
| 108 | +CREATE TABLE modelix.model |
| 109 | +( |
| 110 | + key character varying NOT NULL, |
| 111 | + value character varying, |
| 112 | + reachable boolean, |
| 113 | + CONSTRAINT kv_pkey PRIMARY KEY (key) |
| 114 | +); |
| 115 | +GRANT ALL ON TABLE modelix.model TO modelix; |
| 116 | +-- |
| 117 | + |
| 118 | +Run using `docker-compose` via: |
| 119 | + |
| 120 | +[source, shell] |
| 121 | +-- |
| 122 | +$ docker-compose up |
| 123 | +-- |
| 124 | + |
| 125 | + |
| 126 | +=== 3. Gradle via Dependency |
| 127 | + |
| 128 | +When using Gradle, you can run a `model-server` by adding a dependency to `org.modelix:model-server`, as shown in the following minimal working example. |
| 129 | + |
| 130 | +.Content of minimal `build.gradle.kts` to run a `model-server` in memory |
| 131 | +[source, kotlin] |
| 132 | +-- |
| 133 | +plugins { |
| 134 | + application |
| 135 | +} |
| 136 | + |
| 137 | +repositories { |
| 138 | + mavenCentral() |
| 139 | + maven { url = uri("https://artifacts.itemis.cloud/repository/maven-mps/") } |
| 140 | +} |
| 141 | + |
| 142 | +dependencies { |
| 143 | + implementation("org.modelix:model-server:4.6.0") |
| 144 | +} |
| 145 | + |
| 146 | +application { |
| 147 | + mainClass.set("org.modelix.model.server.Main") |
| 148 | +} |
| 149 | + |
| 150 | +tasks.run.configure { |
| 151 | + args("-inmemory") |
| 152 | + // note: you can add other arguments here, e.g. |
| 153 | + // args("-inmemory", "-dumpin", "/path/to/dump/file.dump") |
| 154 | +} |
| 155 | +-- |
| 156 | + |
| 157 | +You can start the model-server simply by running |
| 158 | + |
| 159 | +[source, bash] |
| 160 | +-- |
| 161 | +./gradlew run |
| 162 | +-- |
| 163 | + |
| 164 | +=== 4. Gradle via Source |
| 165 | + |
| 166 | +Use `git` to check out the modelix core repository from |
7 | 167 |
|
8 |
| -- To run the model-server with default configuration run: |
9 |
| -+ |
10 | 168 | [source,bash]
|
11 | 169 | --
|
12 |
| -[modelix.core] $ ./gradlew model-server:run |
| 170 | +https://github.com/modelix/modelix.core |
13 | 171 | --
|
14 | 172 |
|
15 |
| -- To specify a different jdbc configuration, you can add the `-jdbcconf` arguement: |
16 |
| -+ |
| 173 | +To run the model-server with default configuration run: |
| 174 | + |
17 | 175 | [source,bash]
|
18 | 176 | --
|
19 |
| -[modelix.core] $ ./gradlew model-server:run --args='-jdbcconf path-to-my-database.properties' |
| 177 | +[modelix.core] $ ./gradlew model-server:run |
20 | 178 | --
|
21 | 179 |
|
22 |
| -- During development or to perform tests it is recommended to start the `model-server` with in-memory storage: |
23 |
| -+ |
| 180 | +NOTE: You will have to build the project first, which might take some time depending on your hardware. |
| 181 | + |
| 182 | + |
| 183 | +[NOTE] |
| 184 | +==== |
| 185 | +To give arguments to the gradle run command, you have to add them via the `--args` flag: |
| 186 | +
|
24 | 187 | [source,bash]
|
25 | 188 | --
|
26 |
| -[modelix.core] $ ./gradlew model-server:run --args='-inmemory' |
| 189 | +./gradlew model-server:run --args='-jdbcconf path-to-my-database.properties -dumpout' |
27 | 190 | --
|
| 191 | +==== |
| 192 | + |
| 193 | + |
| 194 | +=== 5. *In Process* (Kotlin) |
| 195 | + |
| 196 | +This rather advanced version allows you to run the `model-server` inside your own application. |
| 197 | +We primarily use this approach for testing, but theoretically it could be applied elsewhere. |
| 198 | +You can find an examples of this in the following code fragment: |
| 199 | + |
| 200 | +* https://github.com/modelix/modelix.core/blob/main/model-server/src/test/kotlin/org/modelix/model/server/ModelClientV2Test.kt#L48[ModelClientV2Test (modelix core tests)] |
0 commit comments