carpelan commited on
Commit
3e4dbea
·
1 Parent(s): c3d2674

fixes to dockerfile, in particular correct premissions for appuser

Browse files
Files changed (2) hide show
  1. .docker/dockerfile +18 -24
  2. dockerfile +0 -64
.docker/dockerfile CHANGED
@@ -4,7 +4,7 @@ FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu22.04
4
  # Set environment variables
5
  ARG DEBIAN_FRONTEND=noninteractive
6
  ENV PYTHONUNBUFFERED=1 \
7
- GRADIO_ALLOW_FLAGGING=never \
8
  GRADIO_NUM_PORTS=1 \
9
  GRADIO_SERVER_NAME=0.0.0.0 \
10
  GRADIO_THEME=huggingface \
@@ -13,10 +13,12 @@ ENV PYTHONUNBUFFERED=1 \
13
  PYTHONPATH=/home/appuser/app \
14
  HF_HOME=/home/appuser/.cache \
15
  TORCH_HOME=/home/appuser/.cache \
 
 
16
  NVIDIA_VISIBLE_DEVICES=all \
17
  NVIDIA_DRIVER_CAPABILITIES=compute,utility
18
 
19
- # Install system dependencies
20
  RUN apt-get update && apt-get install --no-install-recommends -y \
21
  build-essential \
22
  python3.10 \
@@ -26,12 +28,10 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
26
  libsm6 \
27
  libxext6 \
28
  libgl1 \
 
 
29
  && apt-get clean && rm -rf /var/lib/apt/lists/*
30
 
31
- # Set Python 3.10 as the default python3 and pip
32
- RUN ln -sf /usr/bin/python3.10 /usr/bin/python \
33
- && ln -sf /usr/bin/pip3 /usr/bin/pip
34
-
35
  # Install `uv`
36
  RUN pip install --upgrade pip \
37
  && pip install uv
@@ -39,33 +39,27 @@ RUN pip install --upgrade pip \
39
  # Create a non-root user
40
  RUN useradd -m -u 1000 appuser
41
 
42
- # Set working directory to the user's home directory
43
  WORKDIR /home/appuser/app
44
 
45
- # Copy dependency files, including LICENSE and README.md
46
- COPY --chown=appuser pyproject.toml uv.lock LICENSE README.md ./
 
 
 
47
 
48
- # Install dependencies using `uv`
49
- RUN uv sync --frozen
50
 
51
- # Copy the application code
52
  COPY --chown=appuser app app
53
 
54
- # Ensure non-root user has write access to the cache directory
55
- RUN mkdir -p /home/appuser/.cache && chown -R appuser:appuser /home/appuser/.cache
56
-
57
- # Set ownership for all files to the app user
58
- # Avoid unnecessary `chown` for better performance since `COPY --chown` already sets ownership
59
 
60
- # Switch to the non-root user
61
  USER appuser
62
 
63
- # Set the cache directory for Hugging Face and other tools
64
- ENV HF_HOME=$CACHE_DIR \
65
- TRANSFORMERS_CACHE=$CACHE_DIR \
66
- TORCH_HOME=$CACHE_DIR
67
-
68
- # Expose the port for Gradio
69
  EXPOSE 7862
70
 
71
  # Command to run the application
 
4
  # Set environment variables
5
  ARG DEBIAN_FRONTEND=noninteractive
6
  ENV PYTHONUNBUFFERED=1 \
7
+ GRADIO_FLAGGING_MODE=never \
8
  GRADIO_NUM_PORTS=1 \
9
  GRADIO_SERVER_NAME=0.0.0.0 \
10
  GRADIO_THEME=huggingface \
 
13
  PYTHONPATH=/home/appuser/app \
14
  HF_HOME=/home/appuser/.cache \
15
  TORCH_HOME=/home/appuser/.cache \
16
+ TMP_DIR=/home/appuser/tmp \
17
+ TRANSFORMERS_CACHE=/home/appuser/.cache/transformers \
18
  NVIDIA_VISIBLE_DEVICES=all \
19
  NVIDIA_DRIVER_CAPABILITIES=compute,utility
20
 
21
+ # Install system dependencies and set Python 3.10 as default
22
  RUN apt-get update && apt-get install --no-install-recommends -y \
23
  build-essential \
24
  python3.10 \
 
28
  libsm6 \
29
  libxext6 \
30
  libgl1 \
31
+ && ln -sf /usr/bin/python3.10 /usr/bin/python \
32
+ && ln -sf /usr/bin/pip3 /usr/bin/pip \
33
  && apt-get clean && rm -rf /var/lib/apt/lists/*
34
 
 
 
 
 
35
  # Install `uv`
36
  RUN pip install --upgrade pip \
37
  && pip install uv
 
39
  # Create a non-root user
40
  RUN useradd -m -u 1000 appuser
41
 
42
+ # Set working directory
43
  WORKDIR /home/appuser/app
44
 
45
+ # Copy dependency files and install dependencies
46
+ COPY --chown=appuser pyproject.toml uv.lock LICENSE README.md ./
47
+ RUN uv sync --frozen --no-cache \
48
+ && chown -R appuser:appuser /home/appuser/app/.venv \
49
+ && rm -rf /root/.cache /home/appuser/.cache
50
 
 
 
51
 
52
+ # Copy application code
53
  COPY --chown=appuser app app
54
 
55
+ # Ensure non-root user has write access to cache and tmp directories
56
+ RUN mkdir -p /home/appuser/.cache/transformers /home/appuser/tmp /home/appuser/.cache \
57
+ && chown -R appuser:appuser /home/appuser/.cache /home/appuser/tmp/ /home/appuser/app/
 
 
58
 
59
+ # Switch to non-root user
60
  USER appuser
61
 
62
+ # Expose port for Gradio
 
 
 
 
 
63
  EXPOSE 7862
64
 
65
  # Command to run the application
dockerfile DELETED
@@ -1,64 +0,0 @@
1
- # Base image with CUDA 12.6.3 and cuDNN
2
- FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu22.04
3
-
4
- # Set environment variables
5
- ARG DEBIAN_FRONTEND=noninteractive
6
- ENV PYTHONUNBUFFERED=1 \
7
- GRADIO_FLAGGING_MODE=never \
8
- GRADIO_NUM_PORTS=1 \
9
- GRADIO_SERVER_NAME=0.0.0.0 \
10
- GRADIO_THEME=huggingface \
11
- SYSTEM=spaces \
12
- AM_I_IN_A_DOCKER_CONTAINER=Yes \
13
- PYTHONPATH=/home/appuser/app \
14
- HF_HOME=/home/appuser/.cache \
15
- TORCH_HOME=/home/appuser/.cache \
16
- TMP_DIR=/home/appuser/tmp \
17
- TRANSFORMERS_CACHE=/home/appuser/.cache/transformers \
18
- NVIDIA_VISIBLE_DEVICES=all \
19
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
20
-
21
- # Install system dependencies and set Python 3.10 as default
22
- RUN apt-get update && apt-get install --no-install-recommends -y \
23
- build-essential \
24
- python3.10 \
25
- python3.10-distutils \
26
- python3-pip \
27
- ffmpeg \
28
- libsm6 \
29
- libxext6 \
30
- libgl1 \
31
- && ln -sf /usr/bin/python3.10 /usr/bin/python \
32
- && ln -sf /usr/bin/pip3 /usr/bin/pip \
33
- && apt-get clean && rm -rf /var/lib/apt/lists/*
34
-
35
- # Install `uv`
36
- RUN pip install --upgrade pip \
37
- && pip install uv
38
-
39
- # Create a non-root user
40
- RUN useradd -m -u 1000 appuser
41
-
42
- # Set working directory
43
- WORKDIR /home/appuser/app
44
-
45
- # Copy dependency files and install dependencies
46
- COPY --chown=appuser pyproject.toml uv.lock LICENSE README.md ./
47
- RUN uv sync --frozen --no-cache \
48
- && rm -rf /root/.cache /home/appuser/.cache
49
-
50
- # Copy application code
51
- COPY --chown=appuser app app
52
-
53
- # Ensure non-root user has write access to cache and tmp directories
54
- RUN mkdir -p /home/appuser/.cache/transformers /home/appuser/tmp \
55
- && chown -R appuser:appuser /home/appuser/.cache /home/appuser/tmp
56
-
57
- # Switch to non-root user
58
- USER appuser
59
-
60
- # Expose port for Gradio
61
- EXPOSE 7862
62
-
63
- # Command to run the application
64
- CMD ["uv", "run", "python", "app/main.py"]