wynai commited on
Commit
43d4cbf
·
verified ·
1 Parent(s): 9e18270

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -36
Dockerfile CHANGED
@@ -1,38 +1,30 @@
1
- # syntax=docker/dockerfile:1
2
- FROM node:22-slim
3
-
4
- # git để clone repo, pnpm qua corepack
5
- RUN apt-get update \
6
- && apt-get install -y --no-install-recommends git ca-certificates \
7
- && rm -rf /var/lib/apt/lists/* \
8
- && corepack enable
9
-
10
- # HF Space chạy container bằng user id 1000 (user "node" trong image này là 1000)
11
- RUN mkdir -p /app && chown node:node /app
12
- USER node
13
- WORKDIR /app
14
-
15
- # Lấy source và cài dependencies (bỏ qua script như husky)
16
- RUN git clone --depth 1 https://github.com/awerks/stremio-double-subtitles.git . \
17
- && pnpm install --prod --ignore-scripts
18
-
19
- # Script khởi động: chạy app ở 53100 và proxy 7860 -> 53100
20
- RUN cat <<'EOF' > /app/hf-start.sh
21
- #!/bin/sh
22
- PORT=53100 pnpm start &
23
- exec node -e "
24
- const net = require('net');
25
- net.createServer((c) => {
26
- const s = net.connect(53100, '127.0.0.1');
27
- c.pipe(s).pipe(c);
28
- s.on('error', () => c.destroy());
29
- c.on('error', () => s.destroy());
30
- }).listen(7860, '0.0.0.0');
31
- "
32
- EOF
33
- RUN chmod +x /app/hf-start.sh
34
-
35
- ENV NODE_ENV=production
36
  EXPOSE 7860
37
 
38
- CMD ["/app/hf-start.sh"]
 
 
1
+ # Sử dụng Python 3.11 slim nhẹ và ổn định
2
+ FROM python:3.11-slim
3
+
4
+ # Thiết lập biến môi trường tối ưu cho Python
5
+ ENV PYTHONDONTWRITEBYTECODE=1 \
6
+ PYTHONUNBUFFERED=1 \
7
+ PORT=7860
8
+
9
+ # Tạo người dùng non-root với UID 1000 theo yêu cầu bắt buộc của Hugging Face Spaces
10
+ RUN useradd -m -u 1000 user
11
+
12
+ # Chuyển sang thư mục làm việc của user
13
+ WORKDIR /home/user/app
14
+
15
+ # Cài đặt các thư viện phụ thuộc trước để tận dụng Docker Layer Cache
16
+ COPY --chown=user:user requirements.txt .
17
+ RUN pip install --no-cache-dir --upgrade pip && \
18
+ pip install --no-cache-dir -r requirements.txt
19
+
20
+ # Sao chép toàn bộ mã nguồn vào container với quyền sở hữu của user (UID 1000)
21
+ COPY --chown=user:user . .
22
+
23
+ # Chuyển sang người dùng non-root
24
+ USER user
25
+
26
+ # Mở cổng 7860 mặc định của Hugging Face Spaces
 
 
 
 
 
 
 
 
 
27
  EXPOSE 7860
28
 
29
+ # Khởi chạy FastAPI Proxy Server bằng Uvicorn trên cổng 7860
30
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]