1+ FROM python:3.12-slim AS builder
2+
3+ # Install uv
4+ RUN pip install uv
5+
6+ # Set work directory
7+ WORKDIR /app
8+
9+ # Copy only what's needed for installation
10+ COPY pyproject.toml uv.lock ./
11+ COPY src/ ./src/
12+
13+ # Install dependencies using uv with --system flag
14+ RUN uv pip install --system --no-cache-dir .
15+
16+ # Create a lightweight runtime image
17+ FROM python:3.12-slim AS runtime
18+
19+ # Set work directory
20+ WORKDIR /app
21+
22+ # Copy only the installed packages and application code
23+ COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
24+ COPY --from=builder /usr/local/bin /usr/local/bin
25+ COPY --from=builder /app/src /app/src
26+
27+ # Create log directory
28+ RUN mkdir -p /app/log
29+
30+ # Define build arguments with default values
31+ ARG OPENAI_BASE_URL_INTERNAL=http://localhost:8000
32+ ARG OPENAI_BASE_URL=http://localhost:8080
33+ ARG OPENAI_API_KEY=sk-fakekey
34+ ARG API_ADAPTER_HOST=0.0.0.0
35+ ARG API_ADAPTER_PORT=8080
36+ ARG LOG_LEVEL=INFO
37+ ARG LOG_FILE_PATH=/app/log/api_adapter.log
38+
39+ # Set environment variables from build arguments
40+ ENV PYTHONUNBUFFERED=1 \
41+ PYTHONDONTWRITEBYTECODE=1 \
42+ # OpenAI API Configuration
43+ OPENAI_BASE_URL_INTERNAL=${OPENAI_BASE_URL_INTERNAL} \
44+ OPENAI_BASE_URL=${OPENAI_BASE_URL} \
45+ OPENAI_API_KEY=${OPENAI_API_KEY} \
46+ # Server Configuration
47+ API_ADAPTER_HOST=${API_ADAPTER_HOST} \
48+ API_ADAPTER_PORT=${API_ADAPTER_PORT} \
49+ # Logging Configuration
50+ LOG_LEVEL=${LOG_LEVEL} \
51+ LOG_FILE_PATH=${LOG_FILE_PATH}
52+
53+ # Create entrypoint script for proper environment variable handling
54+ RUN echo '#!/bin/sh\n exec uvicorn openai_responses_server.server:app --host $API_ADAPTER_HOST --port $API_ADAPTER_PORT "$@"' > /app/entrypoint.sh && \
55+ chmod +x /app/entrypoint.sh
56+
57+ # Create non-root user for security and set permissions
58+ RUN adduser --disabled-password --gecos "" appuser && \
59+ chown -R appuser:appuser /app/log && \
60+ chown appuser:appuser /app/entrypoint.sh
61+ USER appuser
62+
63+ # Use JSON array format for CMD with entrypoint script
64+ CMD ["sh" , "/app/entrypoint.sh" ]
0 commit comments