thecuong commited on
Commit
d9731b9
·
verified ·
1 Parent(s): 0e6302a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -12
Dockerfile CHANGED
@@ -1,30 +1,39 @@
1
  # Sử dụng Python 3.10 làm base image
2
  FROM python:3.10-slim
3
 
4
- # Set up a new user named "user" with user ID 1000
5
  RUN useradd -m -u 1000 user
6
  ENV HOME=/home/user \
7
- PATH=/home/user/.local/bin:$PATH
8
  WORKDIR $HOME/app
9
 
10
- # Tạo biến môi trường để truyền GitHub token
11
  ARG GITHUB_TOKEN
12
  ENV GITHUB_TOKEN=${GITHUB_TOKEN}
13
 
14
- # Sao chépclone repository từ GitHub
15
- RUN apt-get update && apt-get install -y git
16
- # Expose the secret SECRET_EXAMPLE at buildtime and use its value as git remote URL
 
 
17
 
 
18
  RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
19
- git clone -b spaceHF/cuong1 https://$(cat /run/secrets/GITHUB_TOKEN):x-oauth-basic@github.com/TheCuongt65/snake.git .
20
 
21
- # Cài đặt thư viện Python từ Pipfile.lock
22
- RUN pip install --no-cache-dir pipenv
23
- RUN apt-get update && apt-get install -y git build-essential
24
- RUN pipenv install
25
 
26
- # Mở cổng 7860 (Spaces yêu cầu)
 
 
 
27
  EXPOSE 7860
28
 
29
  # Chạy API bằng uvicorn
 
30
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
 
 
 
 
1
  # Sử dụng Python 3.10 làm base image
2
  FROM python:3.10-slim
3
 
4
+ # Tạo user "user" thiết lập môi trường làm việc
5
  RUN useradd -m -u 1000 user
6
  ENV HOME=/home/user \
7
+ PATH=/home/user/.local/bin:$PATH
8
  WORKDIR $HOME/app
9
 
10
+ # Nhận giá trị của GitHub Token thông qua ARG và ENV
11
  ARG GITHUB_TOKEN
12
  ENV GITHUB_TOKEN=${GITHUB_TOKEN}
13
 
14
+ # Cài đặt các gói cần thiết (git build-essential) dọn dẹp cache apt
15
+ RUN apt-get update && apt-get install -y --no-install-recommends \
16
+ git \
17
+ build-essential \
18
+ && rm -rf /var/lib/apt/lists/*
19
 
20
+ # Clone repository từ GitHub sử dụng BuildKit secret (yêu cầu BuildKit bật)
21
  RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
22
+ git clone -b spaceHF/cuong1 https://$(cat /run/secrets/GITHUB_TOKEN):x-oauth-basic@github.com/TheCuongt65/snake.git .
23
 
24
+ # Cài đặt pipenv và các thư viện từ Pipfile.lock (với --deploy và --system)
25
+ RUN pip install --no-cache-dir pipenv \
26
+ && pipenv install --deploy --system
 
27
 
28
+ # Cài đặt uvicorn nếu chưa có (hoặc đảm bảo uvicorn có trong Pipfile)
29
+ RUN pip install --no-cache-dir uvicorn
30
+
31
+ # Expose cổng 7860 (theo yêu cầu của Spaces)
32
  EXPOSE 7860
33
 
34
  # Chạy API bằng uvicorn
35
+ # Cách 1: Nếu uvicorn được cài đặt và nằm trong PATH
36
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
37
+
38
+ # Cách 2: Sử dụng Python module để chạy uvicorn (khuyến nghị nếu gặp lỗi PATH)
39
+ #CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]