From 5b2035a4ee50e97d6fd3c6ddb23e721a08d5b831 Mon Sep 17 00:00:00 2001 From: LibraHp_0928 <1941163264@qq.com> Date: Sun, 13 Oct 2024 15:31:38 +0800 Subject: [PATCH] upload Dockerfile --- Dockerfile | 33 +++++++++++++++++++++++++++++++++ main.py | 2 +- nginx.conf | 25 +++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..832438e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# 使用官方 Python 基础镜像 +FROM python:3.9-slim + +# 设置工作目录 +WORKDIR /app + +# 复制本地的依赖文件和应用程序文件到容器中 +COPY requirements.txt ./ +COPY main.py ./ + +# 安装依赖项,并指定 pip 源 +RUN python -m venv /app/.venv && \ + /app/.venv/bin/pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip && \ + /app/.venv/bin/pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt + +RUN apt-get update && apt-get install -y libgtk-3-0 + +# 安装 NGINX +RUN apt-get update && apt-get install -y nginx && \ + rm /etc/nginx/sites-enabled/default + +# 复制 NGINX 配置文件 +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# 设置环境变量 +ENV PATH="/app/.venv/bin:$PATH" +ENV FLET_SERVER_PORT=8000 + +# 开放端口 +EXPOSE 80 + +# 启动 Flet 和 NGINX +CMD service nginx start && python main.py diff --git a/main.py b/main.py index cb2b938..3a6a3ce 100644 --- a/main.py +++ b/main.py @@ -141,7 +141,7 @@ def log(message,type="info"): now = time.strftime("%Y-%m-%d %H:%M:%S") log_info_ref.current.value = f"[{now}] - {message}" # 写入日志到文件 - with open(f"{save_path}/log.txt", "a", encoding="utf-8") as f: + with open(f"log.txt", "a", encoding="utf-8") as f: f.write(f"[{now}] - {message}\n") if type == "success": log_info_ref.current.color = "green" diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..2c4ab2b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + + location / { + proxy_pass http://127.0.0.1:8000/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection keep-alive; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /ws { + proxy_pass http://127.0.0.1:8000/ws; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/requirements.txt b/requirements.txt index fdeb2f6..936b574 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ beautifulsoup4==4.12.2 flet==0.24.1 +pandas==2.2.3 Requests==2.31.0