peihsin0715 commited on
Commit ·
e8997ce
1
Parent(s): 7c447a5
Update Dockerfile configuration
Browse files5 unmodified lines67891011121314151617181920212223242526272829303132333435363738394011 unmodified lines525354555 unmodified linesCOPY frontend/ ./RUN npm run build# ---------- Backend build ----------FROM python:3.11-slim AS beENV PIP_NO_CACHE_DIR=1 PYTHONUNBUFFERED=1 PIP_PREFER_BINARY=1WORKDIR /appRUN apt-get update && apt-get install -y --no-install-recommends \build-essential gcc g++ gfortran make pkg-config \libopenblas-dev liblapack-dev git \&& rm -rf /var/lib/apt/lists/*RUN python -m pip install --upgrade pip setuptools wheelRUN pip install --index-url https://download.pytorch.org/whl/cpu "torch==2.3.1"COPY backend/requirements.txt ./backend/requirements.txtRUN sed -i 's/^[Tt]orch[[:space:]=<>!].*/# torch pinned separately (CPU)/' backend/requirements.txt || trueRUN pip install --only-binary=:all: blis || echo "Precompiled blis not available"RUN pip install -r backend/requirements.txt || pip install -r backend/requirements.txt --no-depsCOPY backend/ ./backend/# ---------- Runtime ----------FROM python:3.11-slim AS runtimeENV PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1 PORT=7860WORKDIR /appRUN apt-get update && apt-get install -y --no-install-recommends \nginx supervisor ca-certificates \libgomp1 libopenblas0 \&& rm -rf /var/lib/apt/lists/*COPY --from=fe /app/frontend/dist /usr/share/nginx/htmlCOPY --from=be /usr/local /usr/localCOPY --from=be /app/backend /app/backendRUN python -m pip install --no-cache-dir gunicornCOPY nginx.conf.template /etc/nginx/nginx.confRUN mkdir -p /etc/supervisor/conf.d && \11 unmodified lines> /etc/supervisor/conf.d/app.confEXPOSE 7860CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/app.conf"]5 unmodified lines678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686911 unmodified lines818283845 unmodified linesCOPY frontend/ ./RUN npm run build# ---------- Backend build (build venv only) ----------FROM python:3.11-slim AS beENV PIP_NO_CACHE_DIR=1 PYTHONUNBUFFERED=1 PIP_PREFER_BINARY=1WORKDIR /app# 系統相依(供一些科學套件編譯/連結)RUN apt-get update && apt-get install -y --no-install-recommends \build-essential gcc g++ gfortran make pkg-config \libopenblas-dev liblapack-dev git \&& rm -rf /var/lib/apt/lists/*# 建立虛擬環境並啟用RUN python -m venv /opt/venvENV PATH="/opt/venv/bin:${PATH}"# 升級 pip/工具RUN python -m pip install --upgrade pip setuptools wheel# 先裝 CPU 版 torch(避免跟 requirements 衝突)RUN pip install --index-url https://download.pytorch.org/whl/cpu "torch==2.3.1"# 安裝你的後端依賴(移除/忽略裡面的 torch)COPY backend/requirements.txt ./backend/requirements.txtRUN sed -i 's/^[Tt]orch[[:space:]=<>!].*/# torch pinned separately (CPU)/' backend/requirements.txt || true# 盡量吃 wheels;若失敗再退而求其次RUN pip install --only-binary=:all: blis || echo "Precompiled blis not available"RUN pip install -r backend/requirements.txt || pip install -r backend/requirements.txt --no-deps# 也把 gunicorn 裝進 venv(改用這個,避免 runtime 再裝)RUN pip install --no-cache-dir gunicorn# 可選:把後端程式先帶進來做可用性檢查(不一定需要)COPY backend/ ./backend/# ---------- Runtime ----------FROM python:3.11-slim AS runtimeENV PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1 PORT=7860 \PATH="/opt/venv/bin:${PATH}"WORKDIR /app# 輕量執行期相依RUN apt-get update && apt-get install -y --no-install-recommends \nginx supervisor ca-certificates \libgomp1 libopenblas0 \&& rm -rf /var/lib/apt/lists/*# 前端靜態檔COPY --from=fe /app/frontend/dist /usr/share/nginx/html# 只拷「虛擬環境」,不要整個 /usr/localCOPY --from=be /opt/venv /opt/venv# 後端程式碼COPY --from=be /app/backend /app/backend# nginx 設定與 supervisorCOPY nginx.conf.template /etc/nginx/nginx.confRUN mkdir -p /etc/supervisor/conf.d && \11 unmodified lines> /etc/supervisor/conf.d/app.confEXPOSE 7860CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/app.conf"]
Dockerfile+40-11