-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (41 loc) · 1.27 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (41 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Build stage
FROM python:3.13-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Set working directory
WORKDIR /app
# Copy only requirements files first to leverage Docker cache
COPY pyproject.toml uv.lock LICENSE README.md ./
# Create virtual environment and install dependencies
RUN uv venv /app/.venv && \
. /app/.venv/bin/activate && \
uv sync --locked --all-extras
# Final stage
FROM python:3.13-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH" \
SERVER_PORT=8000
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
WORKDIR /app
# Copy virtual environment from builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy application code
COPY . .
# Create a non-root user to run the app and set permissions
RUN groupadd -r appuser && \
useradd -r -g appuser -d /app appuser && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port from environment variable
EXPOSE ${SERVER_PORT}
# Set the entry point
CMD ["bash", "./scripts/docker/run-server.sh"]