Skip to content

Commit 821c73f

Browse files
authored
Merge pull request #241 from amirhmoradi/patch-1
Running behind Traefik proxy in Docker Swarm with Postgres
2 parents 6c56ff6 + 9fa71ae commit 821c73f

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# This helps run the project in a docker SWARM, behind Traefik Reverse Proxy (traefik manages ssl, and you can add middlewares to add basic auth, ip limits and other features.)
2+
# To make this work in Single Docker daemon (no swarm); move the 'labels' key to each service's top level and remove the 'deploy' keys in 'clien' and 'backend-web-server' services.
3+
#
4+
# This file contains a Postgres DB service, make sure to set its corresponding env vars in your .env variables, and have the volume mount directory created.
5+
# In this example, we mount into the db, the local directory: /data/EXAMPLE/containers/apps/chatgpt/db/
6+
#
7+
# Here are my example .env file, which works correctly:
8+
# APP_DOMAIN=chatgpt.example.com
9+
# DB_URL=postgresql://username:password@database/appdb?sslmode=disable
10+
# ACCOUNT_EMAIL_VERIFICATION=none
11+
# POSTGRES_USER=username
12+
# POSTGRES_PASSWORD=password
13+
# POSTGRES_DB=appdb
14+
15+
# Note: You need to have the 'proxy_external' network already created and setup correctly in your Traefik configurations (out of scope here)
16+
# Note: The domain example.com shall be updated and setup correctly in you DNS.
17+
# Note: The platform key in each service has been disabled as it creates incompatibility in swarm.
18+
19+
version: '3.9'
20+
21+
services:
22+
23+
client:
24+
# platform: linux/x86_64
25+
image: wongsaang/chatgpt-ui-client:latest
26+
environment:
27+
- SERVER_DOMAIN=http://backend-web-server
28+
- DEFAULT_LOCALE=en
29+
- NUXT_PUBLIC_APP_NAME='Private ChatGPT UI' # The name of the application
30+
# - NUXT_PUBLIC_TYPEWRITER=true # Whether to enable the typewriter effect, default false
31+
# - NUXT_PUBLIC_TYPEWRITER_DELAY=50 # The delay time of the typewriter effect, default 50ms
32+
depends_on:
33+
- backend-web-server
34+
# ports:
35+
# - '${CLIENT_PORT:-80}:80'
36+
deploy:
37+
mode: 'global'
38+
labels:
39+
- "traefik.enable=true"
40+
- "traefik.docker.network=proxy_external"
41+
- "traefik.tags=proxy_external"
42+
# Services
43+
- "traefik.http.services.chatgpt-client-prod.loadbalancer.server.port=80"
44+
- "traefik.port=80"
45+
# Routers
46+
- "traefik.http.routers.chatgpt-client-prod.entrypoints=https"
47+
- "traefik.http.routers.chatgpt-client-prod.rule=Host(`chatgpt.example.com`)"
48+
- "traefik.http.routers.chatgpt-client-prod.service=chatgpt-client-prod"
49+
- "traefik.http.routers.chatgpt-client-prod.tls=true"
50+
- "traefik.http.routers.chatgpt-client-prod.tls.certresolver=http"
51+
networks:
52+
- default
53+
- proxy_external
54+
restart: always
55+
56+
backend-wsgi-server:
57+
# platform: linux/x86_64
58+
image: wongsaang/chatgpt-ui-wsgi-server:latest
59+
environment:
60+
- DEBUG=${DEBUG:-False} # Whether to enable debug mode, default False
61+
- APP_DOMAIN=${APP_DOMAIN:-localhost:9000}
62+
- SERVER_WORKERS=3 # The number of worker processes for handling requests.
63+
- WORKER_TIMEOUT=180 # Workers silent for more than this many seconds are killed and restarted. default 180s
64+
- DB_URL=${DB_URL:-sqlite:///db.sqlite3} # If this parameter is not set, the built-in Sqlite will be used by default. It should be noted that if you do not connect to an external database, the data will be lost after the container is destroyed.
65+
- DJANGO_SUPERUSER_USERNAME=admin # default superuser name
66+
- DJANGO_SUPERUSER_PASSWORD=password # default superuser password
67+
- DJANGO_SUPERUSER_EMAIL=user@example.com # default superuser email
68+
- ACCOUNT_EMAIL_VERIFICATION=${ACCOUNT_EMAIL_VERIFICATION:-none} # Determines the e-mail verification method during signup – choose one of "none", "optional", or "mandatory". Default is "optional". If you don't need to verify the email, you can set it to "none".
69+
# If you want to use the email verification function, you need to configure the following parameters
70+
# - EMAIL_HOST=SMTP server address
71+
# - EMAIL_PORT=SMTP server port
72+
# - EMAIL_HOST_USER=
73+
# - EMAIL_HOST_PASSWORD=
74+
# - EMAIL_USE_TLS=True
75+
# - EMAIL_FROM=no-reply@example.com #Default sender email address
76+
# volumes:
77+
# - ./db_sqlite3:/app/db.sqlite3
78+
# ports:
79+
# - '${WSGI_PORT:-8000}:8000'
80+
depends_on:
81+
- database
82+
networks:
83+
- default
84+
restart: always
85+
86+
87+
backend-web-server:
88+
# platform: linux/x86_64
89+
image: wongsaang/chatgpt-ui-web-server:latest
90+
environment:
91+
- BACKEND_URL=http://backend-wsgi-server:8000
92+
# ports:
93+
# - '${SERVER_PORT:-9000}:80'
94+
depends_on:
95+
- backend-wsgi-server
96+
deploy:
97+
mode: 'global'
98+
labels:
99+
- "traefik.enable=true"
100+
- "traefik.docker.network=proxy_external"
101+
- "traefik.tags=proxy_external"
102+
# Services
103+
- "traefik.http.services.chatgpt-prod.loadbalancer.server.port=80"
104+
- "traefik.port=80"
105+
# Routers
106+
- "traefik.http.routers.chatgpt-prod.entrypoints=https"
107+
- "traefik.http.routers.chatgpt-prod.rule=Host(`chatgpt.example.com`) && PathPrefix(`/admin`)"
108+
- "traefik.http.routers.chatgpt-prod.service=chatgpt-prod"
109+
- "traefik.http.routers.chatgpt-prod.tls=true"
110+
- "traefik.http.routers.chatgpt-prod.tls.certresolver=http"
111+
networks:
112+
- default
113+
- proxy_external
114+
restart: always
115+
116+
database:
117+
image: "postgres:14.2"
118+
# ports:
119+
# - "5432:5432"
120+
environment:
121+
POSTGRES_USER: ${POSTGRES_USER:-username} # The PostgreSQL user (useful to connect to the database)
122+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password} # The PostgreSQL password (useful to connect to the database)
123+
POSTGRES_DB: ${POSTGRES_DB:-appdb} # The PostgreSQL default database (automatically created at first launch)
124+
volumes:
125+
- "/data/EXAMPLE/containers/apps/chatgpt/db/:/var/lib/postgresql/data/"
126+
healthcheck:
127+
test:
128+
[
129+
"CMD-SHELL",
130+
"pg_isready -U ${POSTGRES_USER:-username} -d ${POSTGRES_DB:-appdb}",
131+
]
132+
interval: 5s
133+
timeout: 5s
134+
retries: 5
135+
labels:
136+
- "traefik.enable=false"
137+
networks:
138+
- default
139+
deploy:
140+
labels:
141+
- "traefik.enable=false"
142+
143+
networks:
144+
proxy_external:
145+
external: true
146+
name: "proxy_external"

0 commit comments

Comments
 (0)