Spaces:
Sleeping
Sleeping
| # Sử dụng base image Ubuntu 22.04 | |
| FROM ubuntu:22.04 | |
| # Đặt biến môi trường | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| ARG PYTHON_VERSION=3.10 | |
| ENV PYTHONUNBUFFERED=1 | |
| # ---- TẠO USER ---- | |
| ARG USER_ID=1000 | |
| ARG GROUP_ID=1000 | |
| # Tạo group và user, useradd -m sẽ tự tạo thư mục home | |
| RUN groupadd -g ${GROUP_ID} appgroup && \ | |
| useradd -u ${USER_ID} -g ${GROUP_ID} --create-home --shell /bin/bash --home-dir /home/appuser appuser && \ | |
| chown appuser:appgroup /home/appuser | |
| # Cài đặt dependencies hệ thống (chạy bằng root) | |
| # Chạy apt-get update trước | |
| RUN apt-get update | |
| # Cài các gói cần thiết, BAO GỒM gnupg | |
| RUN apt-get install -y --no-install-recommends \ | |
| software-properties-common \ | |
| git \ | |
| curl \ | |
| sudo \ | |
| ffmpeg \ | |
| fonts-noto \ | |
| wget \ | |
| ca-certificates \ | |
| gnupg | |
| # Thêm PPA - Bây giờ gnupg/gpg-agent đã có sẵn | |
| RUN add-apt-repository ppa:deadsnakes/ppa | |
| # Chạy apt-get update lại sau khi thêm PPA | |
| RUN apt-get update -y | |
| # Cài đặt Python từ PPA mới thêm | |
| RUN apt-get install -y \ | |
| python${PYTHON_VERSION} \ | |
| python${PYTHON_VERSION}-dev \ | |
| python${PYTHON_VERSION}-venv | |
| # Cấu hình Python alternatives | |
| RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 | |
| RUN update-alternatives --set python3 /usr/bin/python${PYTHON_VERSION} | |
| RUN ln -sf /usr/bin/python${PYTHON_VERSION}-config /usr/bin/python3-config | |
| # Cài đặt pip | |
| RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} | |
| # Kiểm tra phiên bản | |
| RUN python3 --version && python3 -m pip --version | |
| # Dọn dẹp cache apt | |
| RUN apt-get clean && rm -rf /var/lib/apt/lists/* | |
| # Đặt thư mục làm việc và cấp quyền cho user mới | |
| WORKDIR /app | |
| RUN chown appuser:appgroup /app | |
| # ---- CHUYỂN SANG USER MỚI ---- | |
| USER appuser | |
| # Thêm local bin vào PATH | |
| ENV PATH="/home/appuser/.local/bin:${PATH}" | |
| # Đặt HOME rõ ràng | |
| ENV HOME=/home/appuser | |
| RUN echo "Forcing re-clone 1" | |
| RUN rm -rf /app/VideoLingo | |
| # Clone repository (chạy bằng appuser) | |
| RUN git clone https://github.com/hoangquocvietbro/VideoLingo.git . | |
| # ---- Cấu hình Pip VÀ Cài đặt Dependencies (chạy bằng appuser) ---- | |
| # Tạo thư mục config pip trước | |
| RUN mkdir -p ${HOME}/.config/pip | |
| # Cấu hình pip mirror CHO USER NÀY | |
| RUN python3 -m pip config --user set global.index-url https://mirrors.aliyun.com/pypi/simple/ | |
| # Kiểm tra xem file config đã được tạo đúng chưa (DEBUG) | |
| RUN echo "Checking pip config..." | |
| RUN ls -la ${HOME}/.config/pip/ || echo "Pip config dir not found." | |
| RUN cat ${HOME}/.config/pip/pip.conf || echo "Pip config file not found or empty." | |
| # Kiểm tra kết nối đến mirror (DEBUG) | |
| RUN echo "Attempting to connect to mirror..." | |
| RUN curl -v https://mirrors.aliyun.com/pypi/simple/ || echo "Curl connection failed!" | |
| # Cài đặt PyTorch CPU (sẽ sử dụng mirror đã cấu hình) | |
| RUN python3 -m pip install --user --no-cache-dir torch==2.0.0+cpu torchaudio==2.0.0+cpu --index-url https://download.pytorch.org/whl/cpu | |
| # Xóa .git (nếu muốn) | |
| RUN rm -rf .git | |
| # Cài đặt requirements từ file (sẽ sử dụng mirror đã cấu hình) | |
| RUN python3 -m pip install --user --no-cache-dir -r requirements.txt -v | |
| # --- Xử lý dữ liệu NLTK và Thư mục Cache (chạy bằng appuser) --- | |
| ENV NLTK_DATA=${HOME}/.nltk_data | |
| ENV MPLCONFIGDIR=${HOME}/.cache/matplotlib | |
| ENV TRANSFORMERS_CACHE=/app/.cache/transformers | |
| ENV HF_HOME=/app/.cache/huggingface | |
| ENV XDG_CACHE_HOME=/app/.cache | |
| ENV XDG_CONFIG_HOME=/app/.config | |
| # Tạo các thư mục cache (appuser có quyền ghi trong $HOME và /app) | |
| RUN mkdir -p ${NLTK_DATA} \ | |
| ${MPLCONFIGDIR} \ | |
| ${TRANSFORMERS_CACHE} \ | |
| ${HF_HOME} \ | |
| ${XDG_CACHE_HOME} \ | |
| ${XDG_CONFIG_HOME} | |
| # Tải dữ liệu NLTK (chạy bằng appuser) | |
| RUN python3 -m nltk.downloader -d ${NLTK_DATA} averaged_perceptron_tagger cmudict | |
| #initially. Adjust if needed. | |
| RUN mkdir -p /app/output | |
| # Create a symbolic link named 'static' pointing to the 'output' directory | |
| # Streamlit should serve files from '/static/<filename>' relative to the base URL | |
| RUN ln -s /app/output /app/static | |
| # ---- END NEW SECTION --- | |
| # Mở cổng | |
| EXPOSE 7860 | |
| # Chạy ứng dụng (sẽ chạy bằng appuser) | |
| CMD ["streamlit", "run", "st.py", "--server.port", "7860"] |