324-version-0180-always-timeout (#329)

* Refactor list component layout to use flex-wrap for improved responsiveness

* increase workers and timeout

* add nginx
This commit is contained in:
Xila Cai
2025-02-04 20:47:49 +01:00
committed by GitHub
parent 94f87c0497
commit c5bf935280
6 changed files with 93 additions and 25 deletions

View File

@@ -6,23 +6,28 @@ ENV PYTHONUNBUFFERED=1
COPY ./requirements.txt /requirements.txt
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& pip install --no-cache-dir -r /requirements.txt \
&& pip install --upgrade --no-cache-dir supervisor==4.2.5 \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# https://stackoverflow.com/questions/58701233/docker-logs-erroneously-appears-empty-until-container-stops
ENV PYTHONUNBUFFERED=1
&& apt-get install -y --no-install-recommends \
curl \
nginx \
&& pip install --no-cache-dir -r /requirements.txt \
&& pip install --upgrade --no-cache-dir supervisor==4.2.5 \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /yamtrack
COPY ./entrypoint.sh /entrypoint.sh
COPY ./supervisord.conf /etc/supervisord.conf
COPY ./nginx.conf /etc/nginx/nginx.conf
RUN chmod +x /entrypoint.sh \
# create user abc for later PUID/PGID mapping
&& useradd -U -M -s /bin/bash abc
&& useradd -U -M -s /bin/bash abc \
# Create required nginx directories and set permissions
&& mkdir -p /var/log/nginx \
&& mkdir -p /var/lib/nginx/body \
&& chown -R abc:abc /var/log/nginx \
&& chown -R abc:abc /var/lib/nginx
# Django app
COPY src ./
@@ -32,4 +37,4 @@ EXPOSE 8000
CMD ["/entrypoint.sh"]
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD [ "curl", "-fs", "-S", "--max-time", "2", "http://localhost:8000" ]
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD [ "curl", "-fs", "-S", "--max-time", "2", "http://localhost:80" ]

63
nginx.conf Normal file
View File

@@ -0,0 +1,63 @@
user abc;
worker_processes auto;
pid /tmp/nginx.pid;
error_log /dev/stderr warn;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout combined;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 20M;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
upstream app_server {
server localhost:8001;
}
server {
listen 8000;
server_name _;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
# Static files
location /static/ {
alias /yamtrack/staticfiles/;
expires 30d;
add_header Cache-Control "public, no-transform";
}
# Proxy to Gunicorn
location / {
proxy_pass http://app_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_buffering off;
}
}
}

View File

@@ -18,4 +18,3 @@ redis[hiredis]==5.2.1
requests==2.32.3
requests-ratelimiter==0.7.0
unidecode==1.3.8
whitenoise[brotli]==6.8.2

View File

@@ -42,7 +42,6 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# Application definition
INSTALLED_APPS = [
"whitenoise.runserver_nostatic",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
@@ -61,12 +60,6 @@ INSTALLED_APPS = [
"simple_history",
]
STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedStaticFilesStorage",
},
}
MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.security.SecurityMiddleware",
@@ -76,7 +69,6 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.auth.middleware.LoginRequiredMiddleware",
"simple_history.middleware.HistoryRequestMiddleware",
]

View File

@@ -11,7 +11,7 @@
</div>
<div class="modal-body">
<div class="d-flex column-gap-2">
<div class="d-flex gap-2 flex-wrap">
{% for custom_list in custom_lists %}
<button class="btn btn-secondary"
hx-post="{% url 'list_item_toggle' %}"

View File

@@ -2,21 +2,30 @@
nodaemon=true
user=root
[program:gunicorn]
command=gunicorn --bind :8000 --preload config.wsgi:application
user=abc
[program:nginx]
command=nginx -g 'daemon off;'
user=root
priority=1
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:gunicorn]
command=gunicorn --bind localhost:8001 --preload config.wsgi:application --timeout 200 --max-requests 500 --max-requests-jitter 10
user=abc
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:celery]
command=bash -c 'if [ "${ENV_DEBUG:-False}" = "True" ]; then LOGLEVEL=DEBUG; else LOGLEVEL=INFO; fi; celery --app config worker --loglevel $LOGLEVEL --without-mingle --without-gossip'
user=abc
stopasgroup=true
stopwaitsecs=60
priority=5
priority=10
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
@@ -26,7 +35,7 @@ stderr_logfile_maxbytes=0
command=bash -c 'if [ "${ENV_DEBUG:-False}" = "True" ]; then LOGLEVEL=DEBUG; else LOGLEVEL=INFO; fi; celery --app config beat -s ./db/celerybeat-schedule --loglevel $LOGLEVEL'
user=abc
stopasgroup=true
priority=10
priority=15
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr