Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (45 loc) · 1.46 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (45 loc) · 1.46 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
# AI Voice Detection API - Dockerfile
# Multi-stage build for optimized image size
# Stage 1: Builder
FROM python:3.11-slim as builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY requirements.txt ./
# Create virtual environment and install dependencies
RUN python -m venv /app/.venv && \
/app/.venv/bin/pip install --no-cache-dir --upgrade pip && \
/app/.venv/bin/pip install --no-cache-dir -r requirements.txt
# Stage 2: Runtime
FROM python:3.11-slim as runtime
WORKDIR /app
# Install FFmpeg for audio processing
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
RUN useradd --create-home --shell /bin/bash appuser
# Copy virtual environment from builder
COPY --from=builder /app/.venv /app/.venv
# Set PATH to use virtual environment
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app"
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PORT=8080
# Copy application code
COPY app/ ./app/
COPY static/ ./static/
COPY run.py ./
# Change ownership to non-root user
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8080
# Run the application - uses $PORT env variable for Cloud Run compatibility
CMD uvicorn app.main:app --host 0.0.0.0 --port $PORT