Enoch Jason J commited on
Commit
1425e56
·
1 Parent(s): 0ba11f7

Securely mount HF token during build

Browse files
Files changed (1) hide show
  1. Dockerfile +7 -7
Dockerfile CHANGED
@@ -10,19 +10,19 @@ COPY download_models.py .
10
  RUN pip install --no-cache-dir -r requirements_local.txt
11
 
12
  # --- Pre-download and Cache Models ---
13
- # FIX: This RUN command is now simplified.
14
- # The HUGGING_FACE_HUB_TOKEN is automatically provided as an environment variable
15
- # by the Hugging Face Spaces secrets manager. The python script will read it directly.
16
- # The ARG line is no longer needed.
17
  RUN --mount=type=cache,target=/root/.cache/huggingface \
18
- python download_models.py
 
19
 
20
  # Copy the main application code
21
- COPY app.py .
22
 
23
  # Expose the port the app runs on
24
  EXPOSE 8000
25
 
26
  # Command to run the application
27
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
28
 
 
10
  RUN pip install --no-cache-dir -r requirements_local.txt
11
 
12
  # --- Pre-download and Cache Models ---
13
+ # FIX: The RUN command is now updated to securely access the HF_TOKEN secret.
14
+ # 1. --mount=type=secret... makes the secret available at a temporary path.
15
+ # 2. The environment variable is set by reading from that secret path.
 
16
  RUN --mount=type=cache,target=/root/.cache/huggingface \
17
+ --mount=type=secret,id=HUGGING_FACE_HUB_TOKEN \
18
+ HUGGING_FACE_HUB_TOKEN=$(cat /run/secrets/HUGGING_FACE_HUB_TOKEN) python download_models.py
19
 
20
  # Copy the main application code
21
+ COPY main.py .
22
 
23
  # Expose the port the app runs on
24
  EXPOSE 8000
25
 
26
  # Command to run the application
27
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
28