-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (48 loc) · 1.65 KB
/
Copy pathDockerfile
File metadata and controls
65 lines (48 loc) · 1.65 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
57
58
59
60
61
62
63
64
65
# Multi-stage Dockerfile for Anthropic-Bedrock API Proxy
# Using official uv image for faster dependency management
# Stage 1: Builder
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
# Set working directory
WORKDIR /build
# Copy dependency files and source code (needed for package build)
COPY pyproject.toml uv.lock README.md ./
COPY app ./app
COPY main.py ./
# Install dependencies using uv
# uv sync will create a .venv directory with all dependencies
RUN uv sync --frozen --no-dev
# Stage 2: Runtime
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
# Set working directory
WORKDIR /app
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -m -u 1000 -s /bin/bash appuser
# Copy virtual environment from builder
COPY --from=builder /build/.venv /app/.venv
# Copy project files (needed for uv run)
COPY pyproject.toml uv.lock README.md /app/
# Copy application code
COPY app /app/app
COPY main.py /app/
# Set ownership
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
UV_SYSTEM_PYTHON=1
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run application directly from the virtual environment
# Note: Using python -m uvicorn instead of uv run to avoid rebuild issues
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]