Spaces:
Running
Running
File size: 1,973 Bytes
0187d9a cf4eb3c 79d472e cf4eb3c 79d472e cf4eb3c 79d472e cf4eb3c 0187d9a 04afa0e 0665c6f 04afa0e 0187d9a 04afa0e 0187d9a 79d472e 04afa0e 0187d9a 79d472e 04afa0e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
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"] |