chore: 优化 dockerfile,缩小镜像体积

This commit is contained in:
amtoaer
2024-01-06 02:13:00 +08:00
parent 345c764463
commit 641cc3f48b
+17 -5
View File
@@ -1,4 +1,4 @@
FROM python:3.11.7-alpine3.19 FROM python:3.11.7-alpine3.19 as base
WORKDIR /app WORKDIR /app
@@ -6,17 +6,19 @@ ENV LANG=zh_CN.UTF-8 \
TZ=Asia/Shanghai \ TZ=Asia/Shanghai \
BILI_IN_DOCKER=true BILI_IN_DOCKER=true
COPY poetry.lock pyproject.toml ./
RUN apk add --no-cache ffmpeg tini \ RUN apk add --no-cache ffmpeg tini \
&& apk add --no-cache --virtual .build-deps \ && apk add --no-cache --virtual .build-deps \
gcc \ gcc \
musl-dev \ musl-dev \
libffi-dev \ libffi-dev \
openssl-dev \ openssl-dev \
&& pip install poetry \ && pip install poetry==1.7.1 pip3-autoremove==1.2.0
&& poetry config virtualenvs.create false \
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false \
&& poetry install --only main --no-root \ && poetry install --only main --no-root \
&& pip3-autoremove -y poetry pip3-autoremove \
&& apk del .build-deps \ && apk del .build-deps \
&& rm -rf \ && rm -rf \
/root/.cache \ /root/.cache \
@@ -24,6 +26,16 @@ RUN apk add --no-cache ffmpeg tini \
COPY . . COPY . .
FROM scratch
WORKDIR /app
ENV LANG=zh_CN.UTF-8 \
TZ=Asia/Shanghai \
BILI_IN_DOCKER=true
COPY --from=base / /
ENTRYPOINT [ "tini", "python", "entry.py" ] ENTRYPOINT [ "tini", "python", "entry.py" ]
VOLUME [ "/app/config", "/app/data", "/app/thumb", "/Videos/Bilibilis" ] VOLUME [ "/app/config", "/app/data", "/app/thumb", "/Videos/Bilibilis" ]