File size: 1,584 Bytes
5315033
 
 
d9731b9
3f847af
 
d9731b9
3f847af
5315033
d9731b9
5315033
 
 
d9731b9
 
 
 
 
3f847af
d9731b9
3f847af
d9731b9
5315033
d9731b9
 
 
5315033
d9731b9
 
 
 
5315033
 
 
d9731b9
9a2bbb2
d9731b9
 
 
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
# 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"]