File size: 1,767 Bytes
2a09f27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
# Stage 1: Build Stage (for dependencies)
FROM python:3.11-slim as builder

# Install build dependencies for qBittorrent client library
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    libssl-dev \
    libffi-dev \
    python3-dev \
    && rm -rf /var/lib/apt/lists/*

# Set up working directory
WORKDIR /app

# Copy only the requirements file to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Stage 2: Final Image
# Use a base image that includes a modern Linux distribution for qBittorrent
FROM ubuntu:22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV QB_WEBUI_PORT=8080
ENV APP_PORT=8000

# Install qBittorrent-nox (daemon) and other necessary packages
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    qbittorrent-nox \
    python3 \
    python3-pip \
    # Install tini for proper signal handling and process management
    tini \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user for security
RUN useradd -ms /bin/bash qbuser

# Copy the installed Python packages from the builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3/dist-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Set up the application directory and copy files
WORKDIR /home/qbuser/app
COPY app/ ./app/
COPY run.sh .
RUN chmod +x run.sh && \
    chown -R qbuser:qbuser /home/qbuser/app

# Set the non-root user
USER qbuser

# Expose the FastAPI port and the qBittorrent Web UI port
EXPOSE 8000
EXPOSE 8080

# Use tini as the entrypoint to manage the main process
ENTRYPOINT ["/usr/bin/tini", "--"]

# Run the startup script
CMD ["./run.sh"]