-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend.dockerfile
More file actions
57 lines (43 loc) · 1.39 KB
/
backend.dockerfile
File metadata and controls
57 lines (43 loc) · 1.39 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
# Build stage
FROM python:3.13-slim AS builder
# Install system dependencies including portaudio for pyaudio
RUN apt-get update && apt-get install -y \
gcc \
g++ \
portaudio19-dev \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements first for better layer caching
COPY backend/requirements.txt /tmp/requirements.txt
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r /tmp/requirements.txt
# Production stage
FROM python:3.13-slim AS production
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
curl \
portaudio19-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user for security
RUN useradd --create-home --shell /bin/bash app && \
mkdir -p /app && \
chown app:app /app
# Copy application code
COPY --chown=app:app ./backend /app/backend
WORKDIR /app
# Set environment variables for the container
ENV SERVICE_ACCOUNT_KEY_PATH=/app/backend/serviceAccountKey.json
# Switch to non-root user
USER app
# Expose port
EXPOSE 8000
# Run the application
ENV PYTHONPATH="/app:${PYTHONPATH}"
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000"]