From 733c35c360fb6b106623bbc199c831580ad66d4d Mon Sep 17 00:00:00 2001 From: shouchih_chen Date: Wed, 25 Jun 2025 21:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ app.py | 5 +++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5ddcd14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# 基於官方 Ubuntu 映像 +FROM ubuntu:22.04 + +# 設定工作目錄 +WORKDIR /app + +# 安裝 Python3、pip 及 PySide6/Qt 相關依賴 +RUN apt-get update && \ + apt-get install -y \ + python3 python3-pip \ + libglib2.0-0 \ + libgl1 \ + libegl1 \ + libxkbcommon-x11-0 \ + libxcb-xinerama0 \ + libxcb-cursor0 \ + libxcb-randr0 \ + libxcb-icccm4 \ + libxcb-image0 \ + libxcb-keysyms1 \ + libxcb-render-util0 \ + libxcb-shm0 \ + libxcb-sync1 \ + libxcb-util1 \ + libxcb1 \ + libx11-xcb1 \ + libxcb-render0 \ + libxcb-shape0 \ + xkb-data \ + fontconfig libfontconfig1 \ + libdbus-1-3 \ + # 清理 apt 快取,減少映像大小 + && rm -rf /var/lib/apt/lists/* + +# 將 python3 設為預設 python +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 + +# Copy requirements.txt and install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# 複製你的應用程式到容器中 +COPY . . + +# 設定環境變數,讓 Qt 在無頭模式下運行 +ENV QT_QPA_PLATFORM=offscreen + +# 預設執行指令,請將 app.py 替換為你的主程式 +CMD ["python", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py index 31605a2..e82314c 100644 --- a/app.py +++ b/app.py @@ -50,7 +50,8 @@ def upload_csv(): print(f"CSV file saved to {csv_path}") try: - subprocess.run([os.path.join(os.getcwd(), '.venv', 'Scripts', 'python'), 'generate_images.py', csv_path, unique_filename ], check=True) + #subprocess.run([os.path.join(os.getcwd(), '.venv', 'Scripts', 'python'), 'generate_images.py', csv_path, unique_filename ], check=True) + subprocess.run(['python', 'generate_images.py', csv_path, unique_filename ], check=True) folder = app.config['GENERATED_IMAGES_FOLDER'] matched_files = [f for f in os.listdir(folder) if uuid_str in f and f.endswith('.png')] print(f"Matched files: {matched_files}") @@ -95,4 +96,4 @@ def upload_csv(): if __name__ == '__main__': # 當在生產環境部署時,不建議使用 debug=True # 可以指定 host='0.0.0.0' 讓外部可訪問 (在防火牆允許的情況下) - app.run(debug=True, host='127.0.0.1', port=5000) \ No newline at end of file + app.run(debug=True, host='0.0.0.0', port=5000) \ No newline at end of file