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
+
|
| 9 |
+
# ---- TẠO USER ----
|
| 10 |
+
ARG USER_ID=1000
|
| 11 |
+
ARG GROUP_ID=1000
|
| 12 |
+
# Tạo group và user, useradd -m sẽ tự tạo thư mục home
|
| 13 |
+
RUN groupadd -g ${GROUP_ID} appgroup && \
|
| 14 |
+
useradd -u ${USER_ID} -g ${GROUP_ID} --create-home --shell /bin/bash --home-dir /home/appuser appuser && \
|
| 15 |
+
chown appuser:appgroup /home/appuser
|
| 16 |
+
|
| 17 |
+
# Cài đặt dependencies hệ thống (chạy bằng root)
|
| 18 |
+
# Chạy apt-get update trước
|
| 19 |
+
RUN apt-get update
|
| 20 |
+
# Cài các gói cần thiết, BAO GỒM gnupg
|
| 21 |
+
RUN apt-get install -y --no-install-recommends \
|
| 22 |
+
software-properties-common \
|
| 23 |
+
git \
|
| 24 |
+
curl \
|
| 25 |
+
sudo \
|
| 26 |
+
ffmpeg \
|
| 27 |
+
fonts-noto \
|
| 28 |
+
wget \
|
| 29 |
+
ca-certificates \
|
| 30 |
+
gnupg
|
| 31 |
+
|
| 32 |
+
# Thêm PPA - Bây giờ gnupg/gpg-agent đã có sẵn
|
| 33 |
+
RUN add-apt-repository ppa:deadsnakes/ppa
|
| 34 |
+
|
| 35 |
+
# Chạy apt-get update lại sau khi thêm PPA
|
| 36 |
+
RUN apt-get update -y
|
| 37 |
+
|
| 38 |
+
# Cài đặt Python từ PPA mới thêm
|
| 39 |
+
RUN apt-get install -y \
|
| 40 |
+
python${PYTHON_VERSION} \
|
| 41 |
+
python${PYTHON_VERSION}-dev \
|
| 42 |
+
python${PYTHON_VERSION}-venv
|
| 43 |
+
|
| 44 |
+
# Cấu hình Python alternatives
|
| 45 |
+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1
|
| 46 |
+
RUN update-alternatives --set python3 /usr/bin/python${PYTHON_VERSION}
|
| 47 |
+
RUN ln -sf /usr/bin/python${PYTHON_VERSION}-config /usr/bin/python3-config
|
| 48 |
+
|
| 49 |
+
# Cài đặt pip
|
| 50 |
+
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION}
|
| 51 |
+
|
| 52 |
+
# Kiểm tra phiên bản
|
| 53 |
+
RUN python3 --version && python3 -m pip --version
|
| 54 |
+
|
| 55 |
+
# Dọn dẹp cache apt
|
| 56 |
+
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 57 |
+
|
| 58 |
+
# Đặt thư mục làm việc và cấp quyền cho user mới
|
| 59 |
+
WORKDIR /app
|
| 60 |
+
RUN chown appuser:appgroup /app
|
| 61 |
+
|
| 62 |
+
# ---- CHUYỂN SANG USER MỚI ----
|
| 63 |
+
USER appuser
|
| 64 |
+
# Thêm local bin vào PATH
|
| 65 |
+
ENV PATH="/home/appuser/.local/bin:${PATH}"
|
| 66 |
+
# Đặt HOME rõ ràng
|
| 67 |
+
ENV HOME=/home/appuser
|
| 68 |
+
|
| 69 |
+
RUN echo "Forcing re-clone 1"
|
| 70 |
+
RUN rm -rf /app/VideoLingo
|
| 71 |
+
# Clone repository (chạy bằng appuser)
|
| 72 |
+
RUN git clone https://github.com/hoangquocvietbro/VideoLingo.git .
|
| 73 |
+
|
| 74 |
+
# ---- Cấu hình Pip VÀ Cài đặt Dependencies (chạy bằng appuser) ----
|
| 75 |
+
|
| 76 |
+
# Tạo thư mục config pip trước
|
| 77 |
+
RUN mkdir -p ${HOME}/.config/pip
|
| 78 |
+
# Cấu hình pip mirror CHO USER NÀY
|
| 79 |
+
RUN python3 -m pip config --user set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
| 80 |
+
|
| 81 |
+
# Kiểm tra xem file config đã được tạo đúng chưa (DEBUG)
|
| 82 |
+
RUN echo "Checking pip config..."
|
| 83 |
+
RUN ls -la ${HOME}/.config/pip/ || echo "Pip config dir not found."
|
| 84 |
+
RUN cat ${HOME}/.config/pip/pip.conf || echo "Pip config file not found or empty."
|
| 85 |
+
|
| 86 |
+
# Kiểm tra kết nối đến mirror (DEBUG)
|
| 87 |
+
RUN echo "Attempting to connect to mirror..."
|
| 88 |
+
RUN curl -v https://pypi.tuna.tsinghua.edu.cn/simple || echo "Curl connection failed!"
|
| 89 |
+
|
| 90 |
+
# Cài đặt PyTorch CPU (sẽ sử dụng mirror đã cấu hình)
|
| 91 |
+
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
|
| 92 |
+
|
| 93 |
+
# Xóa .git (nếu muốn)
|
| 94 |
+
RUN rm -rf .git
|
| 95 |
+
|
| 96 |
+
# Cài đặt requirements từ file (sẽ sử dụng mirror đã cấu hình)
|
| 97 |
+
RUN python3 -m pip install --user --no-cache-dir -r requirements.txt -v
|
| 98 |
+
|
| 99 |
+
# --- Xử lý dữ liệu NLTK và Thư mục Cache (chạy bằng appuser) ---
|
| 100 |
+
ENV NLTK_DATA=${HOME}/.nltk_data
|
| 101 |
+
ENV MPLCONFIGDIR=${HOME}/.cache/matplotlib
|
| 102 |
+
ENV TRANSFORMERS_CACHE=/app/.cache/transformers
|
| 103 |
+
ENV HF_HOME=/app/.cache/huggingface
|
| 104 |
+
ENV XDG_CACHE_HOME=/app/.cache
|
| 105 |
+
ENV XDG_CONFIG_HOME=/app/.config
|
| 106 |
+
|
| 107 |
+
# Tạo các thư mục cache (appuser có quyền ghi trong $HOME và /app)
|
| 108 |
+
RUN mkdir -p ${NLTK_DATA} \
|
| 109 |
+
${MPLCONFIGDIR} \
|
| 110 |
+
${TRANSFORMERS_CACHE} \
|
| 111 |
+
${HF_HOME} \
|
| 112 |
+
${XDG_CACHE_HOME} \
|
| 113 |
+
${XDG_CONFIG_HOME}
|
| 114 |
+
|
| 115 |
+
# Tải dữ liệu NLTK (chạy bằng appuser)
|
| 116 |
+
RUN python3 -m nltk.downloader -d ${NLTK_DATA} averaged_perceptron_tagger cmudict
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
#initially. Adjust if needed.
|
| 120 |
+
RUN mkdir -p /app/output
|
| 121 |
+
|
| 122 |
+
# Create a symbolic link named 'static' pointing to the 'output' directory
|
| 123 |
+
# Streamlit should serve files from '/static/<filename>' relative to the base URL
|
| 124 |
+
RUN ln -s /app/output /app/static
|
| 125 |
+
# ---- END NEW SECTION ---
|
| 126 |
+
# Mở cổng
|
| 127 |
+
EXPOSE 7860
|
| 128 |
+
|
| 129 |
+
# Chạy ứng dụng (sẽ chạy bằng appuser)
|
| 130 |
+
CMD ["streamlit", "run", "st.py", "--server.port", "7860"]
|