From ba8ad9cd5cf230bae6ee44592835d5da2bc7248e Mon Sep 17 00:00:00 2001 From: Samiya Date: Fri, 8 Mar 2024 22:59:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=95=9C=E5=83=8F=E6=89=93?= =?UTF-8?q?=E5=8C=85=E5=B1=82=E6=95=B0=20=E5=8E=BB=E6=8E=89=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=9A=84=E6=97=B6=E5=8C=BA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 15 ++++----------- Dockerfile-Alpine | 16 ++++++---------- docker-swarm.yaml | 1 + 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 777eebd..558a7c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,6 @@ FROM python:3.10 AS builder # 合并命令以减少层数,并安装时区数据,同时清理缓存和不再需要的文件 RUN apt-get update && \ apt-get install -y --no-install-recommends tzdata && \ - ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - echo Asia/Shanghai > /etc/timezone && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -21,16 +19,15 @@ RUN pip install --no-cache-dir -r requirements.txt --target /root/dependencies # 将代码复制到容器内 COPY . . +# 确保启动脚本具有执行权限 +RUN chmod +x /root/VintageVigil/start.sh + # 阶段二:运行阶段 FROM python:3.10-slim AS runner -# 复制时区设置 -COPY --from=builder /etc/localtime /etc/localtime -COPY --from=builder /etc/timezone /etc/timezone - # 安装运行时依赖,并清理APT缓存 RUN apt-get update && \ - apt-get install -y --no-install-recommends jq curl && \ + apt-get install -y --no-install-recommends jq curl tzdata && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -43,10 +40,6 @@ COPY --from=builder /root/dependencies /usr/local/lib/python3.10/site-packages # 从构建阶段复制项目文件 COPY --from=builder /root/VintageVigil . -# 确保启动脚本具有执行权限 -RUN chmod +x /root/VintageVigil/start.sh - - # 设置容器启动时执行的命令(根据你的需要选择一个) # 自动监控 # CMD ["bash", "./run_checker.sh"] diff --git a/Dockerfile-Alpine b/Dockerfile-Alpine index 6edacef..c169f68 100644 --- a/Dockerfile-Alpine +++ b/Dockerfile-Alpine @@ -1,5 +1,5 @@ # 阶段一:构建阶段 -FROM python:3.10-alpine AS builder +FROM python:3.13.0a4-alpine3.18 AS builder # 设置工作目录 WORKDIR /root/VintageVigil @@ -7,8 +7,6 @@ WORKDIR /root/VintageVigil # 安装时区数据和依赖,同时清理缓存 RUN apk update && \ apk add --no-cache tzdata build-base libffi-dev openssl-dev && \ - cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - echo "Asia/Shanghai" > /etc/timezone && \ rm -rf /var/cache/apk/* # 将依赖文件单独复制,以利用 Docker 缓存 @@ -21,16 +19,17 @@ RUN pip install --no-cache-dir -r requirements.txt --target /root/dependencies & # 将代码复制到容器内 COPY . . +# 确保启动脚本具有执行权限 +RUN chmod +x /root/VintageVigil/start.sh + # 阶段二:运行阶段 -FROM python:3.10-alpine AS runner +FROM python:3.13.0a4-alpine3.18 AS runner # 复制时区设置和已安装的依赖 -COPY --from=builder /etc/localtime /etc/localtime -COPY --from=builder /etc/timezone /etc/timezone COPY --from=builder /root/dependencies /usr/local/lib/python3.10/site-packages # 安装运行时依赖 -RUN apk add --no-cache jq curl +RUN apk add --no-cache jq curl tzdata # 设置工作目录 WORKDIR /root/VintageVigil @@ -38,9 +37,6 @@ WORKDIR /root/VintageVigil # 从构建阶段复制项目文件 COPY --from=builder /root/VintageVigil . -# 确保启动脚本具有执行权限 -RUN chmod +x /root/VintageVigil/start.sh - # 设置容器启动时执行的命令 # CMD ["python", "./main.py"] CMD ["sh", "-c", "./start.sh"] \ No newline at end of file diff --git a/docker-swarm.yaml b/docker-swarm.yaml index 8067b24..577b8b6 100644 --- a/docker-swarm.yaml +++ b/docker-swarm.yaml @@ -10,6 +10,7 @@ services: # - CHECK_INTERVAL=60 # 是否使用内置的Github Token来进行请求,否则每分钟只能请求60次/单个IP(默认是) # - USE_TOKEN=true + - TZ=Asia/Shanghai deploy: mode: replicated replicas: 1