diff --git a/Dockerfile b/Dockerfile index 4ec18e8..9411787 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,12 @@ # 使用官方 Python 镜像作为基础镜像 FROM python:3.13-alpine +#构建版本 +ARG BUILD_SHA +ARG BUILD_TAG +ENV BUILD_SHA=$BUILD_SHA +ENV BUILD_TAG=$BUILD_TAG + # 设置工作目录 WORKDIR /app @@ -8,17 +14,12 @@ WORKDIR /app COPY . /app # 安装依赖 -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt && \ + echo "{\"BUILD_SHA\":\"$BUILD_SHA\", \"BUILD_TAG\":\"$BUILD_TAG\"}" > build.json # 时区 ENV TZ="Asia/Shanghai" -#构建版本 -ARG BUILD_SHA -ARG BUILD_TAG -ENV BUILD_SHA=$BUILD_SHA -ENV BUILD_TAG=$BUILD_TAG - # 端口 EXPOSE 5005 diff --git a/app/run.py b/app/run.py index 2f0e053..7333f2e 100644 --- a/app/run.py +++ b/app/run.py @@ -34,8 +34,15 @@ from quark_auto_save import Quark, Config, MagicRename def get_app_ver(): - BUILD_SHA = os.environ.get("BUILD_SHA", "") - BUILD_TAG = os.environ.get("BUILD_TAG", "") + """获取应用版本""" + try: + with open("build.json", "r") as f: + build_info = json.loads(f.read()) + BUILD_SHA = build_info["BUILD_SHA"] + BUILD_TAG = build_info["BUILD_TAG"] + except Exception as e: + BUILD_SHA = os.getenv("BUILD_SHA", "") + BUILD_TAG = os.getenv("BUILD_TAG", "") if BUILD_TAG[:1] == "v": return BUILD_TAG elif BUILD_SHA: