Skip to content

Commit

Permalink
Run Daphne along with uwsgi
Browse files Browse the repository at this point in the history
  • Loading branch information
TamiTakamiya committed Feb 14, 2025
1 parent f10ebc5 commit c30e9c7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ansible_ai_connect/main/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"csp.middleware.CSPMiddleware",
]

if os.environ.get("CSRF_TRUSTED_ORIGINS"):
CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS").split(",")
else:
CSRF_TRUSTED_ORIGINS = ["http://localhost:8000"]

# Allow Prometheus to scrape metrics
ALLOWED_CIDR_NETS = [os.environ.get("ALLOWED_CIDR_NETS", "10.0.0.0/8")]

Expand Down
13 changes: 13 additions & 0 deletions tools/configs/nginx-wisdom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ upstream uwsgi {
server unix:///var/run/uwsgi/ansible_wisdom.sock;
}

upstream daphne {
server unix:///var/run/daphne/ansible_wisdom.sock;
}


server {
listen 8000 default_server;
server_name _;
Expand All @@ -14,4 +19,12 @@ server {
uwsgi_pass uwsgi;
include /etc/nginx/uwsgi_params;
}

location /api/v1/ai/streaming_chat/ {
proxy_pass http://daphne;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
23 changes: 23 additions & 0 deletions tools/configs/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0

[fcgi-program:daphne]
# TCP socket used by Nginx backend upstream
socket=tcp://localhost:9000

# When daphne is running in multiple processes, each needs to have a different socket.
# In such a case, it is recommended to include process # in the name of socket, but
# then those generated socket names cannot be specified in nginx config file...
# So use this with numprocs=1 for now. See https://github.com/django/daphne/issues/287
# for more details.
numprocs=1
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

autostart = true
autorestart = true
stopwaitsecs = 1
stopsignal = KILL
stopasgroup = true
killasgroup = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0

; [program:test]
; command = sleep infinity

Expand Down
3 changes: 2 additions & 1 deletion wisdom-service.Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RUN /var/www/venv/bin/python3.11 -m pip --no-cache-dir install --no-binary=all c

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

RUN echo -e "\
{\n\
Expand Down Expand Up @@ -99,6 +99,7 @@ RUN for dir in \
/var/log/supervisor \
/var/run/supervisor \
/var/run/uwsgi \
/var/run/daphne \
/var/www/wisdom \
/var/log/nginx \
/etc/ari \
Expand Down

0 comments on commit c30e9c7

Please sign in to comment.