Skip to content

Commit c30e9c7

Browse files
committed
Run Daphne along with uwsgi
1 parent f10ebc5 commit c30e9c7

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

ansible_ai_connect/main/settings/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
"csp.middleware.CSPMiddleware",
9595
]
9696

97+
if os.environ.get("CSRF_TRUSTED_ORIGINS"):
98+
CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS").split(",")
99+
else:
100+
CSRF_TRUSTED_ORIGINS = ["http://localhost:8000"]
101+
97102
# Allow Prometheus to scrape metrics
98103
ALLOWED_CIDR_NETS = [os.environ.get("ALLOWED_CIDR_NETS", "10.0.0.0/8")]
99104

tools/configs/nginx-wisdom.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ upstream uwsgi {
22
server unix:///var/run/uwsgi/ansible_wisdom.sock;
33
}
44

5+
upstream daphne {
6+
server unix:///var/run/daphne/ansible_wisdom.sock;
7+
}
8+
9+
510
server {
611
listen 8000 default_server;
712
server_name _;
@@ -14,4 +19,12 @@ server {
1419
uwsgi_pass uwsgi;
1520
include /etc/nginx/uwsgi_params;
1621
}
22+
23+
location /api/v1/ai/streaming_chat/ {
24+
proxy_pass http://daphne;
25+
proxy_http_version 1.1;
26+
proxy_set_header Upgrade $http_upgrade;
27+
proxy_set_header Connection "upgrade";
28+
proxy_redirect off;
29+
}
1730
}

tools/configs/supervisord.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ stdout_logfile_maxbytes = 0
2828
stderr_logfile = /dev/stderr
2929
stderr_logfile_maxbytes = 0
3030

31+
[fcgi-program:daphne]
32+
# TCP socket used by Nginx backend upstream
33+
socket=tcp://localhost:9000
34+
35+
# When daphne is running in multiple processes, each needs to have a different socket.
36+
# In such a case, it is recommended to include process # in the name of socket, but
37+
# then those generated socket names cannot be specified in nginx config file...
38+
# So use this with numprocs=1 for now. See https://github.com/django/daphne/issues/287
39+
# for more details.
40+
numprocs=1
41+
command = /var/www/venv/bin/daphne -u /var/run/daphne/ansible_wisdom.sock --fd 0 --access-log - --proxy-headers ansible_ai_connect.main.asgi:application
42+
43+
autostart = true
44+
autorestart = true
45+
stopwaitsecs = 1
46+
stopsignal = KILL
47+
stopasgroup = true
48+
killasgroup = true
49+
stdout_logfile = /dev/stdout
50+
stdout_logfile_maxbytes = 0
51+
stderr_logfile = /dev/stderr
52+
stderr_logfile_maxbytes = 0
53+
3154
; [program:test]
3255
; command = sleep infinity
3356

wisdom-service.Containerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ RUN /var/www/venv/bin/python3.11 -m pip --no-cache-dir install --no-binary=all c
5050

5151
RUN /var/www/venv/bin/python3.11 -m pip --no-cache-dir install -r/var/www/ansible-ai-connect-service/requirements.txt
5252
RUN /var/www/venv/bin/python3.11 -m pip --no-cache-dir install -e/var/www/ansible-ai-connect-service/
53-
RUN mkdir /var/run/uwsgi
53+
RUN mkdir /var/run/uwsgi /var/run/daphne
5454

5555
RUN echo -e "\
5656
{\n\
@@ -99,6 +99,7 @@ RUN for dir in \
9999
/var/log/supervisor \
100100
/var/run/supervisor \
101101
/var/run/uwsgi \
102+
/var/run/daphne \
102103
/var/www/wisdom \
103104
/var/log/nginx \
104105
/etc/ari \

0 commit comments

Comments
 (0)