carpelan commited on
Commit
e176209
·
1 Parent(s): 746831a

added dockerfile to build project, not fully working yet

Browse files
Files changed (4) hide show
  1. .docker/dockerfile +68 -6
  2. dockerfile +64 -0
  3. pyproject.toml +1 -0
  4. uv.lock +0 -0
.docker/dockerfile CHANGED
@@ -1,10 +1,72 @@
1
- FROM python:3.12-slim-bullseye
 
2
 
3
- COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- COPY . /app
 
 
 
 
 
 
 
 
 
 
6
 
7
- WORKDIR /app
8
- RUN uv sync --frozen --no-cache
 
9
 
10
- CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "80"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_ALLOW_FLAGGING=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
+ 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 \
23
+ python3.10-distutils \
24
+ python3-pip \
25
+ ffmpeg \
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
38
+
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
72
+ CMD ["uv", "run", "python", "app/main.py"]
dockerfile ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]
pyproject.toml CHANGED
@@ -23,6 +23,7 @@ dependencies = [
23
  "pandas>=2.2.3",
24
  "jinja2>=3.1.4",
25
  "gradio-modal>=0.0.4",
 
26
  ]
27
 
28
  [project.urls]
 
23
  "pandas>=2.2.3",
24
  "jinja2>=3.1.4",
25
  "gradio-modal>=0.0.4",
26
+ "fastapi[standard]>=0.115.6",
27
  ]
28
 
29
  [project.urls]
uv.lock CHANGED
The diff for this file is too large to render. See raw diff