MJSHIN0122 commited on
Commit
b7a937b
·
1 Parent(s): 06da17b
Files changed (3) hide show
  1. Dockerfile +22 -7
  2. entrypoint.sh +4 -0
  3. init_app.py +19 -0
Dockerfile CHANGED
@@ -1,14 +1,29 @@
1
- # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.11
 
 
 
5
 
6
- WORKDIR /code
 
7
 
8
- COPY ./requirements.txt /code/requirements.txt
 
9
 
10
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
 
11
 
12
  COPY . .
13
 
14
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
 
2
 
3
+ # 필요한 패키지 설치 (여기서는 git 포함)
4
+ RUN apt-get update \
5
+ && apt-get install -y git \
6
+ && rm -rf /var/lib/apt/lists/*
7
 
8
+ # non-root 사용자 생성
9
+ RUN useradd -m myuser
10
 
11
+ # 작업 디렉토리 설정
12
+ WORKDIR /app
13
 
14
+ COPY requirements.txt .
15
+ RUN pip install --no-cache-dir -r requirements.txt
16
 
17
  COPY . .
18
 
19
+ # 파일 소유권 변경
20
+ RUN chown -R myuser:myuser /app
21
+
22
+
23
+ COPY entrypoint.sh entrypoint.sh
24
+ RUN chmod +x entrypoint.sh
25
+
26
+ # 사용자 변경
27
+ USER myuser
28
+
29
+ CMD ["./entrypoint.sh"]
entrypoint.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/sh
2
+ python init_app.py
3
+ python ./api/main.py
4
+ gunicorn -k uvicorn.workers.UvicornWorker -b 0.0.0.0:7860 api.main:app
init_app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from git import Repo
3
+ import sys
4
+
5
+ access_token = os.environ['AccessTokenToPrivate']
6
+ repo = Repo.clone_from(f"https://MJSHIN0122:{access_token}@huggingface.co/spaces/MJSHIN0122/narrative_api.git", ".")
7
+
8
+ print("Clone Done.")
9
+
10
+ repo.submodule_update(init=True)
11
+
12
+ print("Clone and submodule update done.")
13
+
14
+ sys.path.append(os.path.abspath("."))
15
+ sys.path.append(os.path.abspath("./api"))
16
+ sys.path.append(os.path.abspath("./khala_network"))
17
+ sys.path.append(os.path.abspath("./khala_network/src"))
18
+
19
+ import api.main