snake / Dockerfile
thecuong's picture
Update Dockerfile
d9731b9 verified
# Sử dụng Python 3.10 làm base image
FROM python:3.10-slim
# Tạo user "user" và thiết lập môi trường làm việc
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# Nhận giá trị của GitHub Token thông qua ARG và ENV
ARG GITHUB_TOKEN
ENV GITHUB_TOKEN=${GITHUB_TOKEN}
# Cài đặt các gói cần thiết (git và build-essential) và dọn dẹp cache apt
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Clone repository từ GitHub sử dụng BuildKit secret (yêu cầu BuildKit bật)
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
git clone -b spaceHF/cuong1 https://$(cat /run/secrets/GITHUB_TOKEN):x-oauth-basic@github.com/TheCuongt65/snake.git .
# Cài đặt pipenv và các thư viện từ Pipfile.lock (với --deploy và --system)
RUN pip install --no-cache-dir pipenv \
&& pipenv install --deploy --system
# Cài đặt uvicorn nếu chưa có (hoặc đảm bảo uvicorn có trong Pipfile)
RUN pip install --no-cache-dir uvicorn
# Expose cổng 7860 (theo yêu cầu của Spaces)
EXPOSE 7860
# Chạy API bằng uvicorn
# Cách 1: Nếu uvicorn được cài đặt và nằm trong PATH
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
# Cách 2: Sử dụng Python module để chạy uvicorn (khuyến nghị nếu gặp lỗi PATH)
#CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]