mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-17 05:45:09 +00:00
feat: configure gunicorn with env variables
This commit is contained in:
parent
e31bcceac1
commit
2c44349a0f
7 changed files with 57 additions and 36 deletions
|
|
@ -46,6 +46,10 @@ services:
|
||||||
backend:
|
backend:
|
||||||
<<: *backend_defaults
|
<<: *backend_defaults
|
||||||
platform: linux/amd64
|
platform: linux/amd64
|
||||||
|
environment:
|
||||||
|
GUNICORN_THREADS: ${GUNICORN_THREADS:-4}
|
||||||
|
GUNICORN_WORKERS: ${GUNICORN_WORKERS:-2}
|
||||||
|
GUNICORN_TIMEOUT: ${GUNICORN_TIMEOUT:-120}
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
<<: *customizable_image
|
<<: *customizable_image
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,16 @@ If your site is named `example.com` and you access it via that domain, no need t
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Backend (Gunicorn) Configuration
|
||||||
|
|
||||||
|
| Variable | Purpose | Default | When to Set / Allowed Values |
|
||||||
|
| :----------------- | :------------------------------------------------------------- | :------ | :------------------------------------------------------------------------------- |
|
||||||
|
| `GUNICORN_WORKERS` | Number of worker processes handling web requests | `2` | Scale up for multi-core CPUs. Formula: `(2 x Cores) + 1` |
|
||||||
|
| `GUNICORN_THREADS` | Number of concurrent threads per worker process | `4` | Increase to handle more simultaneous I/O-bound requests without high memory cost |
|
||||||
|
| `GUNICORN_TIMEOUT` | Max time a worker can spend on a single request before restart | `120` | Increase if long-running reports or data imports time out |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Frontend Nginx Configuration (inside the frontend container)
|
## Frontend Nginx Configuration (inside the frontend container)
|
||||||
|
|
||||||
| Variable | Purpose | Default | Allowed Values |
|
| Variable | Purpose | Default | Allowed Values |
|
||||||
|
|
|
||||||
11
example.env
11
example.env
|
|
@ -15,6 +15,17 @@ DB_PORT=
|
||||||
REDIS_CACHE=
|
REDIS_CACHE=
|
||||||
REDIS_QUEUE=
|
REDIS_QUEUE=
|
||||||
|
|
||||||
|
|
||||||
|
# The number of threads per Gunicorn worker process for handling concurrent requests.
|
||||||
|
GUNICORN_THREADS=4
|
||||||
|
|
||||||
|
# The number of worker processes for handling requests.
|
||||||
|
# A typical formula is (2 x number of CPU cores) + 1.
|
||||||
|
GUNICORN_WORKERS=2
|
||||||
|
|
||||||
|
# Workers exceeding this timeout (in seconds) will be killed and restarted.
|
||||||
|
GUNICORN_TIMEOUT=120
|
||||||
|
|
||||||
# Only with HTTPS override
|
# Only with HTTPS override
|
||||||
LETSENCRYPT_EMAIL=mail@example.com
|
LETSENCRYPT_EMAIL=mail@example.com
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,18 +165,10 @@ USER root
|
||||||
COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
|
COPY resources/core/start.sh /usr/local/bin/start.sh
|
||||||
|
RUN chmod 755 /usr/local/bin/start.sh
|
||||||
|
|
||||||
USER frappe
|
USER frappe
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|
||||||
CMD [ \
|
CMD ["start.sh"]
|
||||||
"/home/frappe/frappe-bench/env/bin/gunicorn", \
|
|
||||||
"--chdir=/home/frappe/frappe-bench/sites", \
|
|
||||||
"--bind=0.0.0.0:8000", \
|
|
||||||
"--threads=4", \
|
|
||||||
"--workers=2", \
|
|
||||||
"--worker-class=gthread", \
|
|
||||||
"--worker-tmp-dir=/dev/shm", \
|
|
||||||
"--timeout=120", \
|
|
||||||
"--preload", \
|
|
||||||
"frappe.app:application" \
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -49,18 +49,10 @@ USER root
|
||||||
COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
|
COPY resources/core/start.sh /usr/local/bin/start.sh
|
||||||
|
RUN chmod 755 /usr/local/bin/start.sh
|
||||||
|
|
||||||
USER frappe
|
USER frappe
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|
||||||
CMD [ \
|
CMD ["start.sh"]
|
||||||
"/home/frappe/frappe-bench/env/bin/gunicorn", \
|
|
||||||
"--chdir=/home/frappe/frappe-bench/sites", \
|
|
||||||
"--bind=0.0.0.0:8000", \
|
|
||||||
"--threads=4", \
|
|
||||||
"--workers=2", \
|
|
||||||
"--worker-class=gthread", \
|
|
||||||
"--worker-tmp-dir=/dev/shm", \
|
|
||||||
"--timeout=120", \
|
|
||||||
"--preload", \
|
|
||||||
"frappe.app:application" \
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -156,18 +156,10 @@ USER root
|
||||||
COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
|
COPY resources/core/start.sh /usr/local/bin/start.sh
|
||||||
|
RUN chmod 755 /usr/local/bin/start.sh
|
||||||
|
|
||||||
USER frappe
|
USER frappe
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|
||||||
CMD [ \
|
CMD ["start.sh"]
|
||||||
"/home/frappe/frappe-bench/env/bin/gunicorn", \
|
|
||||||
"--chdir=/home/frappe/frappe-bench/sites", \
|
|
||||||
"--bind=0.0.0.0:8000", \
|
|
||||||
"--threads=4", \
|
|
||||||
"--workers=2", \
|
|
||||||
"--worker-class=gthread", \
|
|
||||||
"--worker-tmp-dir=/dev/shm", \
|
|
||||||
"--timeout=120", \
|
|
||||||
"--preload", \
|
|
||||||
"frappe.app:application" \
|
|
||||||
]
|
|
||||||
|
|
|
||||||
20
resources/core/start.sh
Executable file
20
resources/core/start.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#Gunicorn defaults
|
||||||
|
GUNICORN_THREADS=${GUNICORN_THREADS:-4}
|
||||||
|
GUNICORN_WORKERS=${GUNICORN_WORKERS:-2}
|
||||||
|
GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-120}
|
||||||
|
|
||||||
|
echo "Booting Gunicorn with $GUNICORN_WORKERS workers and $GUNICORN_THREADS threads..."
|
||||||
|
|
||||||
|
exec /home/frappe/frappe-bench/env/bin/gunicorn \
|
||||||
|
--chdir=/home/frappe/frappe-bench/sites \
|
||||||
|
--bind=0.0.0.0:8000 \
|
||||||
|
--threads="$GUNICORN_THREADS" \
|
||||||
|
--workers="$GUNICORN_WORKERS" \
|
||||||
|
--worker-class=gthread \
|
||||||
|
--worker-tmp-dir=/dev/shm \
|
||||||
|
--timeout="$GUNICORN_TIMEOUT" \
|
||||||
|
--preload \
|
||||||
|
frappe.app:application
|
||||||
Loading…
Reference in a new issue