meyosaj406 commited on
Commit
7453020
·
verified ·
1 Parent(s): 6592541

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -23
Dockerfile CHANGED
@@ -1,48 +1,45 @@
1
- # ====================================================================
2
- # Dockerfile for notion-2api (HF Spaces, port 7860)
3
- # ====================================================================
4
-
5
  FROM python:3.10-slim
6
 
7
- # 基础环境
8
  ENV PYTHONDONTWRITEBYTECODE=1 \
9
  PYTHONUNBUFFERED=1 \
10
  PIP_NO_CACHE_DIR=1
11
 
12
- # 安装系统依赖(nginx + build 基础)
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
- nginx ca-certificates bash curl tini \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
  WORKDIR /app
18
 
19
- # 安装 Python 依赖
20
- COPY requirements.txt .
 
 
 
 
 
 
21
  RUN pip install --no-cache-dir --upgrade pip && \
22
  pip install --no-cache-dir -r requirements.txt
23
 
24
- # 复制应用代码
25
- COPY . .
26
 
27
- # 创建非 root 用户并授予目录权限(含 nginx 运行需要的目录
28
  RUN useradd --create-home --shell /bin/bash appuser && \
29
- mkdir -p /var/lib/nginx /var/cache/nginx /tmp/nginx && \
30
- chown -R appuser:appuser /app /var/lib/nginx /var/cache/nginx /var/log/nginx /tmp/nginx
31
 
32
- # 拷贝 Nginx 配置(见下面的 nginx.conf)
33
- COPY nginx.conf /etc/nginx/nginx.conf
34
-
35
- # 运行端口统一到 7860(对外端口),后端 Uvicorn 仍用 8000
36
- ENV NGINX_PORT=7860
37
  ENV PORT=7860
38
  EXPOSE 7860
39
 
40
- # 用 tini 做 init,避免僵尸进程;两个进程:nginx(前)+ uvicorn(后)
41
  USER appuser
42
-
43
  ENTRYPOINT ["/usr/bin/tini","--"]
44
 
 
 
45
  CMD bash -lc "\
46
- nginx -g 'daemon off;' & \
47
- uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4 \
48
  "
 
1
+ # Wrapper Dockerfile that clones upstream repo without modifying it
 
 
 
2
  FROM python:3.10-slim
3
 
 
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
  PIP_NO_CACHE_DIR=1
7
 
8
+ # tools: git + nginx + tini
9
  RUN apt-get update && apt-get install -y --no-install-recommends \
10
+ git nginx ca-certificates bash curl tini \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
  WORKDIR /app
14
 
15
+ # 1) clone 上游仓库(不改它)
16
+ # 如需固定版本,可把 GIT_REF 换成具体 commit
17
+ ARG GIT_URL=https://github.com/lzA6/notion-2api.git
18
+ ARG GIT_REF=main
19
+ RUN git clone --depth=1 -b ${GIT_REF} ${GIT_URL} src
20
+
21
+ # 2) 安装 Python 依赖(用上游的 requirements.txt)
22
+ WORKDIR /app/src
23
  RUN pip install --no-cache-dir --upgrade pip && \
24
  pip install --no-cache-dir -r requirements.txt
25
 
26
+ # 3) 放入我们自己的 nginx.conf(只影响容器,不影响上游仓库)
27
+ COPY nginx.conf /etc/nginx/nginx.conf
28
 
29
+ # 4) 非 root 运行 + 目录权限
30
  RUN useradd --create-home --shell /bin/bash appuser && \
31
+ mkdir -p /var/lib/nginx /var/cache/nginx /run/nginx /tmp/nginx && \
32
+ chown -R appuser:appuser /app /var/lib/nginx /var/cache/nginx /var/log/nginx /run/nginx /tmp/nginx
33
 
 
 
 
 
 
34
  ENV PORT=7860
35
  EXPOSE 7860
36
 
 
37
  USER appuser
 
38
  ENTRYPOINT ["/usr/bin/tini","--"]
39
 
40
+ # 5) 启动:先起 Uvicorn(8000),Nginx 前台守护(7860)
41
+ # * 不需要碰上游代码;main.py 在上游根目录
42
  CMD bash -lc "\
43
+ uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4 & \
44
+ exec nginx -g 'daemon off;' \
45
  "