修改Dockerfile

This commit is contained in:
shouchih_chen 2025-06-25 21:17:49 +08:00
parent 6c32236173
commit 733c35c360
2 changed files with 52 additions and 2 deletions

49
Dockerfile Normal file
View File

@ -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"]

5
app.py
View File

@ -50,7 +50,8 @@ def upload_csv():
print(f"CSV file saved to {csv_path}") print(f"CSV file saved to {csv_path}")
try: 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'] folder = app.config['GENERATED_IMAGES_FOLDER']
matched_files = [f for f in os.listdir(folder) if uuid_str in f and f.endswith('.png')] matched_files = [f for f in os.listdir(folder) if uuid_str in f and f.endswith('.png')]
print(f"Matched files: {matched_files}") print(f"Matched files: {matched_files}")
@ -95,4 +96,4 @@ def upload_csv():
if __name__ == '__main__': if __name__ == '__main__':
# 當在生產環境部署時,不建議使用 debug=True # 當在生產環境部署時,不建議使用 debug=True
# 可以指定 host='0.0.0.0' 讓外部可訪問 (在防火牆允許的情況下) # 可以指定 host='0.0.0.0' 讓外部可訪問 (在防火牆允許的情況下)
app.run(debug=True, host='127.0.0.1', port=5000) app.run(debug=True, host='0.0.0.0', port=5000)