11#! /usr/bin/env bash
22set -euo pipefail
33
4- IMAGE=" ${SIMPRINT_SERVER_IMAGE:- ghcr.io/ simprint/ simprint-server: latest} "
4+ SERVER_IMAGE=" ${SIMPRINT_SERVER_IMAGE:- ghcr.io/ simprint/ simprint-server: latest} "
5+ UPDATE_IMAGE=" ${SIMPRINT_UPDATE_IMAGE:- ghcr.io/ simprint/ simprint-update-server: latest} "
6+ CONSOLE_IMAGE=" ${SIMPRINT_CONSOLE_IMAGE:- ghcr.io/ simprint/ simprint-console-server: latest} "
7+
58TARGET_DIR=" $PWD /simprint-self-hosted"
69CONFIG_DIR=" $TARGET_DIR /configs"
710COMPOSE_FILE=" $TARGET_DIR /docker-compose.yml"
8- CONFIG_FILE=" $CONFIG_DIR /config.toml"
11+ SERVER_CONFIG_FILE=" $CONFIG_DIR /server.toml"
12+ UPDATE_CONFIG_FILE=" $CONFIG_DIR /update.toml"
13+ CONSOLE_CONFIG_FILE=" $CONFIG_DIR /console.toml"
914
10- DEFAULT_SERVER_SECRET =" Nuexz9Y2hRc5Z6HK7Atb"
15+ DEFAULT_APP_SECRET =" Nuexz9Y2hRc5Z6HK7Atb"
1116DEFAULT_POSTGRES_PASSWORD=" simprint-postgres-password"
12- PUBLIC_BASE_URL=" https://pub-39307a5e69c74324855a762027cbf9bf.r2.dev"
13- STORAGE_ENDPOINT=" https://example.invalid"
14- REFERRAL_LINK_PREFIX=" https://www.simprint.app/download"
17+ DEFAULT_PUBLIC_BASE_URL=" https://pub-39307a5e69c74324855a762027cbf9bf.r2.dev"
18+ DEFAULT_REFERRAL_LINK_PREFIX=" https://www.simprint.app/download"
19+
20+ PUBLIC_BASE_URL=" ${PUBLIC_BASE_URL:- $DEFAULT_PUBLIC_BASE_URL } "
21+ STORAGE_ENDPOINT=" ${STORAGE_ENDPOINT:- } "
22+ STORAGE_ACCESS_KEY=" ${STORAGE_ACCESS_KEY:- } "
23+ STORAGE_SECRET_ACCESS_KEY=" ${STORAGE_SECRET_ACCESS_KEY:- } "
24+ REFERRAL_LINK_PREFIX=" ${REFERRAL_LINK_PREFIX:- $DEFAULT_REFERRAL_LINK_PREFIX } "
1525SMTP_SERVER=" ${SMTP_SERVER:- } "
1626SMTP_USERNAME=" ${SMTP_USERNAME:- } "
1727SMTP_PASSWORD=" ${SMTP_PASSWORD:- } "
119129mkdir -p " $CONFIG_DIR "
120130
121131require_secret_with_default POSTGRES_PASSWORD " PostgreSQL password" " $DEFAULT_POSTGRES_PASSWORD "
132+ require_value STORAGE_ENDPOINT " Object storage endpoint"
133+ require_value STORAGE_ACCESS_KEY " Object storage access key"
134+ require_value STORAGE_SECRET_ACCESS_KEY " Object storage secret access key" true
122135require_value SMTP_SERVER " SMTP server"
123136require_value SMTP_USERNAME " SMTP username"
124137require_value SMTP_PASSWORD " SMTP password" true
125138
126- cat > " $CONFIG_FILE " << EOF
139+ cat > " $SERVER_CONFIG_FILE " << EOF
127140[app]
128141name = "simprint-server"
129142port = 40041
130- secret = "$DEFAULT_SERVER_SECRET "
143+ secret = "$DEFAULT_APP_SECRET "
131144prefix = "/api/v1"
132145encrypt_secret_location = "./assets/secret"
133146route_whitelists = [
@@ -157,8 +170,8 @@ url = "redis://redis:6379?protocol=resp3"
157170[storage]
158171endpoint = "$STORAGE_ENDPOINT "
159172public_base_url = "$PUBLIC_BASE_URL "
160- access_key = "disabled "
161- secret_access_key = "disabled "
173+ access_key = "$STORAGE_ACCESS_KEY "
174+ secret_access_key = "$STORAGE_SECRET_ACCESS_KEY "
162175bucket = "simprint-client"
163176avatar_root = "avatars"
164177extension_root = "extensions"
@@ -177,6 +190,85 @@ max_proxies = 99999
177190max_rpa_tasks = 99999
178191EOF
179192
193+ cat > " $UPDATE_CONFIG_FILE " << EOF
194+ [app]
195+ name = "simprint-update-server"
196+ port = 40042
197+ secret = "$DEFAULT_APP_SECRET "
198+ prefix = "/api/v1"
199+ route_whitelists = [
200+ "POST+/api/v1/versions/check",
201+ "POST+/api/v1/maintenances/active",
202+ "GET+/api/v1/health"
203+ ]
204+
205+ [database]
206+ url = "postgres://simprint:$POSTGRES_PASSWORD @postgres:5432/simprintdb"
207+ max_connections = 25
208+ min_connections = 5
209+ max_lifetime = 3000
210+ acquire_timeout = 30
211+ idle_timeout = 600
212+
213+ [redis]
214+ url = "redis://redis:6379?protocol=resp3"
215+
216+ [storage]
217+ public_base_url = "$PUBLIC_BASE_URL "
218+ bucket = "simprint-client"
219+ version_root = "versions"
220+ EOF
221+
222+ cat > " $CONSOLE_CONFIG_FILE " << EOF
223+ [app]
224+ name = "simprint-console-server"
225+ port = 40043
226+ secret = "$DEFAULT_APP_SECRET "
227+ prefix = "/api/v1"
228+ route_whitelists = [
229+ "POST+/api/v1/users/login",
230+ "POST+/api/v1/users/reset-password",
231+ "POST+/api/v1/users/reset-password-send-code",
232+ "POST+/api/v1/users/refresh-credentials",
233+ "GET+/api/v1/secret/public/key",
234+ "GET+/api/v1/time/now",
235+ "GET+/api/v1/health",
236+ ]
237+
238+ [database]
239+ url = "postgres://simprint:$POSTGRES_PASSWORD @postgres:5432/simprintdb"
240+ max_connections = 25
241+ min_connections = 5
242+ max_lifetime = 3000
243+ acquire_timeout = 30
244+ idle_timeout = 600
245+
246+ [redis]
247+ url = "redis://redis:6379?protocol=resp3"
248+
249+ [storage]
250+ endpoint = "$STORAGE_ENDPOINT "
251+ public_base_url = "$PUBLIC_BASE_URL "
252+ access_key = "$STORAGE_ACCESS_KEY "
253+ secret_access_key = "$STORAGE_SECRET_ACCESS_KEY "
254+ bucket = "simprint-client"
255+ avatar_root = "avatars"
256+ extension_root = "extensions"
257+ version_root = "versions"
258+
259+ [smtp]
260+ smtp_server = "$SMTP_SERVER "
261+ smtp_username = "$SMTP_USERNAME "
262+ smtp_password = "$SMTP_PASSWORD "
263+
264+ [workspace_quota]
265+ [workspace_quota.default]
266+ max_environments = 8
267+ max_team_members = 1
268+ max_proxies = 99999
269+ max_rpa_tasks = 99999
270+ EOF
271+
180272cat > " $COMPOSE_FILE " << EOF
181273services:
182274 postgres:
@@ -186,6 +278,8 @@ services:
186278 POSTGRES_DB: simprintdb
187279 POSTGRES_USER: simprint
188280 POSTGRES_PASSWORD: $POSTGRES_PASSWORD
281+ ports:
282+ - "5432:5432"
189283 volumes:
190284 - simprint-postgres-data:/var/lib/postgresql/data
191285 healthcheck:
@@ -194,6 +288,8 @@ services:
194288 timeout: 5s
195289 retries: 5
196290 restart: unless-stopped
291+ networks:
292+ - simprint-network
197293
198294 redis:
199295 image: redis:7-alpine
@@ -207,11 +303,13 @@ services:
207303 timeout: 5s
208304 retries: 5
209305 restart: unless-stopped
306+ networks:
307+ - simprint-network
210308
211309 simprint-server:
212- image: $IMAGE
310+ image: $SERVER_IMAGE
213311 container_name: simprint-server
214- command: ["-f=/app/configs/config .toml"]
312+ command: ["-f=/app/configs/server .toml"]
215313 depends_on:
216314 postgres:
217315 condition: service_healthy
@@ -225,6 +323,50 @@ services:
225323 environment:
226324 - RUST_LOG=info
227325 restart: unless-stopped
326+ networks:
327+ - simprint-network
328+
329+ simprint-update-gateway:
330+ image: $UPDATE_IMAGE
331+ container_name: simprint-update-gateway
332+ command: ["-f=/app/configs/update.toml"]
333+ depends_on:
334+ postgres:
335+ condition: service_healthy
336+ redis:
337+ condition: service_healthy
338+ ports:
339+ - "40042:40042"
340+ volumes:
341+ - ./configs:/app/configs:ro
342+ environment:
343+ - RUST_LOG=info
344+ restart: unless-stopped
345+ networks:
346+ - simprint-network
347+
348+ simprint-console-gateway:
349+ image: $CONSOLE_IMAGE
350+ container_name: simprint-console-gateway
351+ command: ["--config", "/app/configs/console.toml", "serve"]
352+ depends_on:
353+ postgres:
354+ condition: service_healthy
355+ redis:
356+ condition: service_healthy
357+ ports:
358+ - "40043:40043"
359+ volumes:
360+ - ./configs:/app/configs:ro
361+ environment:
362+ - RUST_LOG=info
363+ restart: unless-stopped
364+ networks:
365+ - simprint-network
366+
367+ networks:
368+ simprint-network:
369+ name: simprint-network
228370
229371volumes:
230372 simprint-postgres-data:
@@ -234,10 +376,14 @@ EOF
234376
235377echo " Using compose command: ${COMPOSE_CMD[*]} "
236378echo " Working directory: $TARGET_DIR "
237- echo " Server image: $IMAGE "
379+ echo " Server image: $SERVER_IMAGE "
380+ echo " Update image: $UPDATE_IMAGE "
381+ echo " Console image: $CONSOLE_IMAGE "
238382echo " Generated files:"
239383echo " - $COMPOSE_FILE "
240- echo " - $CONFIG_FILE "
384+ echo " - $SERVER_CONFIG_FILE "
385+ echo " - $UPDATE_CONFIG_FILE "
386+ echo " - $CONSOLE_CONFIG_FILE "
241387
242388(
243389 cd " $TARGET_DIR "
0 commit comments