Add Docker packaging for production deployment with uWSGI.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
38ec52abf5
commit
9f9c5f814f
54
Dockerfile
Normal file
54
Dockerfile
Normal file
@ -0,0 +1,54 @@
|
||||
# 使用官方的Python基础镜像
|
||||
FROM python:3.10-slim
|
||||
|
||||
# 替换 sources.list 中的源为 USTC 镜像
|
||||
# RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
|
||||
RUN sed -i "s@http://deb.debian.org/debian@http://mirrors.tencent.com/debian@g" /etc/apt/sources.list.d/debian.sources
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
git \
|
||||
gcc \
|
||||
autoconf \
|
||||
automake \
|
||||
pkg-config \
|
||||
libtool \
|
||||
locales
|
||||
|
||||
# 生成 en_US.UTF-8 locale
|
||||
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
|
||||
locale-gen en_US.UTF-8
|
||||
|
||||
# Set environment variables
|
||||
ENV LANG=en_US.UTF-8
|
||||
ENV LANGUAGE=en_US:en
|
||||
ENV LC_ALL=en_US.UTF-8
|
||||
# Verify that the locale is correctly set (optional)
|
||||
RUN locale
|
||||
|
||||
RUN pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/simple
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制依赖文件并安装依赖
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# 安装uWSGI
|
||||
RUN pip install uwsgi
|
||||
|
||||
# 复制项目文件
|
||||
COPY . .
|
||||
|
||||
# 暴露uWSGI的默认端口
|
||||
EXPOSE 8000
|
||||
|
||||
COPY ./entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# 使用uWSGI运行Django应用
|
||||
CMD ["uwsgi", "--ini", "uwsgi.prod.ini"]
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
3
entrypoint.sh
Executable file
3
entrypoint.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
./manage.py migrate
|
||||
exec "$@"
|
||||
16
uwsgi.prod.ini
Normal file
16
uwsgi.prod.ini
Normal file
@ -0,0 +1,16 @@
|
||||
[uwsgi]
|
||||
env = LANG=en_US.UTF-8
|
||||
env = LC_ALL=en_US.UTF-8
|
||||
http = :8000
|
||||
chdir = /app
|
||||
wsgi_file = config/wsgi.py
|
||||
module = config.wsgi:application
|
||||
master = True
|
||||
socket = /tmp/uwsgi.sock
|
||||
chmod-socket = 666
|
||||
vacuum = true
|
||||
workers = 2
|
||||
threads = 4
|
||||
http-timeout = 1800 # 或更大的值
|
||||
socket-timeout = 1800
|
||||
harakiri = 1800 # 进程超时时间(秒),建议是API最大可能执行时间的2倍
|
||||
Loading…
x
Reference in New Issue
Block a user