Spaces:
Running
Running
FROM python:3.9-slim | |
WORKDIR /app | |
# Cài đặt các dependencies cần thiết | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
git \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Tạo các thư mục cần thiết và cấp quyền | |
RUN mkdir -p /app/data /app/uploads /app/outputs /tmp/matplotlib-cache /tmp/huggingface-cache && \ | |
chmod 777 /app/data /app/uploads /app/outputs /tmp/matplotlib-cache /tmp/huggingface-cache | |
# Thiết lập biến môi trường cho Matplotlib và Hugging Face | |
ENV MPLCONFIGDIR=/tmp/matplotlib-cache | |
ENV TRANSFORMERS_CACHE=/tmp/huggingface-cache | |
ENV HF_HOME=/tmp/huggingface-cache | |
ENV HF_DATASETS_CACHE=/tmp/huggingface-cache | |
# Copy requirements từ project hiện tại | |
COPY requirements.txt . | |
# Clone repository meisai-check-ai từ Bitbucket sử dụng secret, checkout nhánh chien_develop và đảm bảo lấy code mới nhất | |
RUN --mount=type=secret,id=BITBUCKET_APP_PW,mode=0444,required=true \ | |
git clone https://vumichien:$(cat /run/secrets/BITBUCKET_APP_PW)@bitbucket.org/dtm-partners/meisai-check-ai.git && \ | |
cd meisai-check-ai && \ | |
git checkout main && \ | |
git pull origin main && \ | |
cd .. | |
# Cài đặt dependencies | |
RUN pip install --no-cache-dir -r requirements.txt | |
RUN pip install --no-cache-dir -r meisai-check-ai/requirements.txt | |
# Copy code của API vào container | |
COPY . . | |
# Sao chép các file dữ liệu mẫu vào thư mục data | |
RUN mkdir -p /app/data | |
COPY ./data/* /app/data/ | |
# Thêm đường dẫn meisai-check-ai vào PYTHONPATH | |
ENV PYTHONPATH="${PYTHONPATH}:/app/meisai-check-ai" | |
# Expose port | |
EXPOSE 7860 | |
# Chạy với user không phải root để tránh vấn đề quyền truy cập | |
RUN useradd -m appuser | |
RUN chown -R appuser:appuser /app /tmp/matplotlib-cache /tmp/huggingface-cache | |
USER appuser | |
# Chạy ứng dụng với Uvicorn | |
# Lưu ý: Hugging Face Spaces sử dụng port 7860 | |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] |