# 使用官方的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"]
