Aasher commited on
Commit
b3b04d0
·
1 Parent(s): e2b862d

Fix issues in docker file

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -23
Dockerfile CHANGED
@@ -1,33 +1,40 @@
1
- # Use official slim Python base
2
  FROM python:3.12-slim
3
 
4
- # Install uv package manager
5
- COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
 
 
 
 
 
6
 
7
- # Ensure clean python environment and no stray bytecode
8
- ENV PYTHONUNBUFFERED=1 \
9
- PYTHONDONTWRITEBYTECODE=1
10
 
11
- # Set working directory inside container
12
- WORKDIR /app
 
13
 
14
- # Copy lock and project config first for layer caching
15
- COPY pyproject.toml uv.lock ./.python-version /app/
 
16
 
17
- # Install dependencies only (not installing the app code yet)
18
- RUN --mount=type=cache,target=/root/.cache/uv \
19
- uv sync --frozen --no-install-project
20
 
21
- # Copy the full app source code
22
- COPY . /app
 
 
 
23
 
24
- # Install app code on top of deps (no dev dependencies)
25
- RUN --mount=type=cache,target=/root/.cache/uv \
26
- uv sync --frozen --no-dev
27
 
28
- # Expose port
29
- ENV PORT=8000
30
- EXPOSE $PORT
31
 
32
- # Start FastAPI with uvicorn via uv-managed venv
33
- CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
 
 
 
1
+ # Base image
2
  FROM python:3.12-slim
3
 
4
+ # Install system dependencies and uv as root
5
+ RUN apt-get update && \
6
+ apt-get install -y curl && \
7
+ curl -LsSf https://astral.sh/uv/install.sh | sh && \
8
+ mv /root/.local/bin/uv /usr/local/bin/ && \
9
+ mv /root/.local/bin/uvx /usr/local/bin/ && \
10
+ mkdir -p /.cache/uv
11
 
12
+ # Copy project configuration first
13
+ COPY pyproject.toml .
 
14
 
15
+ # Install Python packages as root using uv sync
16
+ RUN uv sync && \
17
+ rm -rf /.uv
18
 
19
+ # Create and switch to non-root user
20
+ RUN useradd -m -u 1000 user && \
21
+ chown -R user:user /.cache/uv
22
 
23
+ USER user
 
 
24
 
25
+ # Set up environment
26
+ ENV HOME=/home/user \
27
+ PATH=/home/user/.local/bin:/usr/local/bin:$PATH \
28
+ PORT=7860 \
29
+ PYTHONUNBUFFERED=1
30
 
31
+ WORKDIR $HOME/app
 
 
32
 
33
+ # Copy application files with correct ownership
34
+ COPY --chown=user:user . .
 
35
 
36
+ # Expose the port the app runs on
37
+ EXPOSE 7860
38
+
39
+ # Command to run the application using Uvicorn
40
+ CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]