-
Notifications
You must be signed in to change notification settings - Fork 144
/
Dockerfile
66 lines (51 loc) · 2.72 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 使用 python:3.11-buster 作为基础镜像
FROM python:3.11-buster as Base
# 安装 Poetry
RUN pip install poetry
# 复制 pyproject.toml 和 poetry.lock 文件
COPY pyproject.toml poetry.lock ./
# 使用 Poetry 生成 requirements.txt 文件
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
# 安装依赖
ARG DEBIAN_REPO="deb.debian.org"
ARG PIP_INDEX_URL="https://pypi.org/simple"
RUN echo "deb http://$DEBIAN_REPO/debian/ buster main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://$DEBIAN_REPO/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://$DEBIAN_REPO/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://$DEBIAN_REPO/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://$DEBIAN_REPO/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://$DEBIAN_REPO/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list
RUN apt-get update && \
apt-get install -y python3-dev build-essential netcat-openbsd libpcre3-dev libldap2-dev libsasl2-dev && \
pip install -r requirements.txt -i ${PIP_INDEX_URL} && \
apt-get remove -y python3-dev build-essential libpcre3-dev && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
# 使用 python:3.11-buster 作为基础镜像
FROM python:3.11-buster
ENV TZ=Asia/Shanghai
# 设置时区
ARG DEBIAN_REPO="deb.debian.org"
RUN echo "deb http://$DEBIAN_REPO/debian/ buster main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://$DEBIAN_REPO/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://$DEBIAN_REPO/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://$DEBIAN_REPO/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://$DEBIAN_REPO/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://$DEBIAN_REPO/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list
RUN apt-get update && \
apt-get install -y tzdata && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
rm -rf /var/lib/apt/lists/*
# 复制依赖
COPY --from=Base /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
# 设置工作目录
WORKDIR /app
# 复制项目文件
COPY . /app
# 设置权限
RUN chmod +x /app/start.sh
# 收集静态文件
RUN python manage.py collectstatic --settings=FasterRunner.settings.docker --no-input
# 设置入口点
ENTRYPOINT ["/app/start.sh"]