AurelioAguirre commited on
Commit
df73b1b
·
1 Parent(s): a4c773d

Fixing Dockerfile v13

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -18
Dockerfile CHANGED
@@ -1,44 +1,46 @@
1
-
2
  # Use Python 3.12 slim image as base
3
  FROM python:3.12-slim
4
 
5
- # Set up a new user named "user" with user ID 1000
6
- RUN useradd -m -u 1000 user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- # Set home to the user's home directory and add local bin to PATH
9
  ENV HOME=/home/user \
10
  PATH=/home/user/.local/bin:$PATH
11
 
12
- # Create necessary directories first
13
- RUN mkdir -p /app/logs /app/.cache /app/models \
14
- && chmod 777 /app/logs /app/.cache /app/models
15
-
16
- # Set working directory to the user's app directory
17
  WORKDIR $HOME/app
18
 
19
- # Copy requirements first to leverage Docker cache
20
  COPY --chown=user requirements.txt .
21
 
22
- # Install dependencies as the user
23
- USER user
24
  RUN pip install --no-cache-dir --upgrade pip && \
25
  pip install --no-cache-dir -r requirements.txt
26
 
27
- # Copy the application code with correct ownership
28
  COPY --chown=user main $HOME/app/main
29
  COPY --chown=user utils $HOME/app/utils
30
 
31
- # Set environment variables
32
  ENV PYTHONPATH=$HOME/app/main
33
  ENV PYTHONUNBUFFERED=1
34
  ENV HF_HOME=$HOME/app/.cache
35
 
36
- # Expose secret at buildtime if needed
37
  RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
38
  export HF_TOKEN=$(cat /run/secrets/HF_TOKEN)
39
 
40
- # Expose the port (Hugging Face API runs on 7680)
41
  EXPOSE 7680
42
 
43
- # Command to run the application
44
- CMD ["python", "-m", "main.app"]
 
 
1
  # Use Python 3.12 slim image as base
2
  FROM python:3.12-slim
3
 
4
+ # First: System-level operations that require root
5
+ RUN apt-get update && apt-get install -y \
6
+ bash \
7
+ wget \
8
+ git \
9
+ git-lfs \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Second: Create user and set up directories
13
+ RUN useradd -m -u 1000 user && \
14
+ mkdir -p /app/logs /app/.cache /app/models && \
15
+ chmod 777 /app/logs /app/.cache /app/models && \
16
+ chown -R user:user /app
17
+
18
+ # Third: Switch context to user
19
+ USER user
20
 
21
+ # Fourth: Set up environment for user
22
  ENV HOME=/home/user \
23
  PATH=/home/user/.local/bin:$PATH
24
 
25
+ # Fifth: Set working directory
 
 
 
 
26
  WORKDIR $HOME/app
27
 
28
+ # Rest of the Dockerfile continues with user-level operations
29
  COPY --chown=user requirements.txt .
30
 
 
 
31
  RUN pip install --no-cache-dir --upgrade pip && \
32
  pip install --no-cache-dir -r requirements.txt
33
 
 
34
  COPY --chown=user main $HOME/app/main
35
  COPY --chown=user utils $HOME/app/utils
36
 
 
37
  ENV PYTHONPATH=$HOME/app/main
38
  ENV PYTHONUNBUFFERED=1
39
  ENV HF_HOME=$HOME/app/.cache
40
 
 
41
  RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
42
  export HF_TOKEN=$(cat /run/secrets/HF_TOKEN)
43
 
 
44
  EXPOSE 7680
45
 
46
+ CMD ["python", "-m", "main.app"]