AlaBoussoffara commited on
Commit
fd8bd32
·
1 Parent(s): 7c31e8f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -1
Dockerfile CHANGED
@@ -6,6 +6,14 @@ FROM python:3.11-slim
6
  ENV PYTHONUNBUFFERED=1
7
  WORKDIR /home/user/app
8
 
 
 
 
 
 
 
 
 
9
  # Create a non-root user (UID 1000) and home dir, then create .files with correct permissions.
10
  # Using a dedicated non-root user is a good practice for containerized Spaces.
11
  RUN apt-get update \
@@ -32,7 +40,28 @@ RUN if [ -f /home/user/app/requirements.txt ]; then \
32
  pip install -e .[server]; \
33
  fi
34
 
35
- # Switch to non-root user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  USER appuser
37
  ENV HOME=/home/user/app
38
  ENV XDG_CACHE_HOME=/home/user/app/.cache
 
6
  ENV PYTHONUNBUFFERED=1
7
  WORKDIR /home/user/app
8
 
9
+ # Build args to optionally fetch a model from the Hugging Face Hub during image build.
10
+ # WARNING: passing secrets (HF_MODEL_TOKEN) as build-args will leave them in image history.
11
+ ARG HF_MODEL_ID=""
12
+ ARG HF_MODEL_NAME=""
13
+ ARG HF_MODEL_REVISION=""
14
+ ARG HF_MODEL_TOKEN=""
15
+ ARG HF_MODEL_REPO_TYPE="model"
16
+
17
  # Create a non-root user (UID 1000) and home dir, then create .files with correct permissions.
18
  # Using a dedicated non-root user is a good practice for containerized Spaces.
19
  RUN apt-get update \
 
40
  pip install -e .[server]; \
41
  fi
42
 
43
+ # Optionally fetch a model from the Hugging Face Hub at build time. This is only
44
+ # executed when HF_MODEL_ID is provided as a build-arg. The downloaded model will
45
+ # be placed under /home/user/app/trained_models so it's baked into the image.
46
+ RUN mkdir -p /home/user/app/trained_models \
47
+ && if [ -n "${HF_MODEL_ID}" ]; then \
48
+ echo "Fetching model ${HF_MODEL_ID} into /home/user/app/trained_models"; \
49
+ mini-transformer-fetch "${HF_MODEL_ID}" --name "${HF_MODEL_NAME:-}" --revision "${HF_MODEL_REVISION:-}" --token "${HF_MODEL_TOKEN:-}" --repo-type "${HF_MODEL_REPO_TYPE:-model}" --model-root /home/user/app/trained_models --force; \
50
+ else \
51
+ echo "No HF_MODEL_ID provided; skipping model download"; \
52
+ fi
53
+
54
+ # If the project provides Makefile targets to fetch small/test models, run them now
55
+ # so the models are present in the image before switching to the non-root user.
56
+ RUN if [ -f /home/user/app/Makefile ]; then \
57
+ echo "Running make fetch-small and make fetch-test"; \
58
+ cd /home/user/app && make fetch-small && make fetch-test; \
59
+ else \
60
+ echo "No Makefile found; skipping 'make fetch-*'"; \
61
+ fi
62
+
63
+ # Ensure trained_models is owned by appuser, then switch to non-root user
64
+ RUN chown -R appuser:appuser /home/user/app/trained_models || true
65
  USER appuser
66
  ENV HOME=/home/user/app
67
  ENV XDG_CACHE_HOME=/home/user/app/.cache