File size: 2,602 Bytes
89ba301
613d081
 
89ba301
 
9807b94
 
89ba301
 
9807b94
 
 
89ba301
9807b94
 
 
 
 
 
 
 
 
89ba301
9807b94
 
763249b
9807b94
 
89ba301
 
9807b94
89ba301
6be58f1
 
690cc83
89ba301
6be58f1
 
89ba301
 
 
 
 
9807b94
 
89ba301
a314d2b
613d081
 
 
89ba301
613d081
 
9d8cbc0
 
2a9f9e0
89ba301
9d8cbc0
 
 
 
 
 
 
a314d2b
 
9d8cbc0
 
89ba301
 
a314d2b
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
# Use a slim Python image for smaller size
FROM python:3.10-slim

# --- User Setup for Security and Writable Config Dirs ---
# Define build arguments for a non-root username and user ID
ARG NB_USER=appuser
ARG NB_UID=1000

# Set environment variables for the user and their home directory
ENV USER ${NB_USER}
ENV HOME /home/${NB_USER}

# Create the non-root user, set up their home directory, and grant ownership
RUN adduser --disabled-password --gecos "" --uid ${NB_UID} ${NB_USER} \
    && mkdir -p ${HOME}/.config \
    && chown -R ${NB_USER}:${NB_USER} ${HOME}

# Set environment variables for Matplotlib and Ultralytics
# These direct them to use a writable directory within the user's home
ENV MPLCONFIGDIR=${HOME}/.config/matplotlib
ENV YOLO_CONFIG_DIR=${HOME}/.config/ultralytics

# Ensure the directories exist and are writable by the non-root user
RUN mkdir -p ${MPLCONFIGDIR} \
    && mkdir -p ${YOLO_CONFIG_DIR} \
    && chown -R ${NB_USER}:${NB_USER} ${MPLCONFIGDIR} \
    && chown -R ${NB_USER}:${NB_USER} ${YOLO_CONFIG_DIR}

# --- System Dependencies ---
# Switch to root to install system-level packages
USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    curl \
    # Clean up apt caches to keep image size small
    && rm -rf /var/lib/apt/lists/*

# --- Application Setup ---
# Set the working directory for the application
WORKDIR /app

# Switch back to the non-root user for installing Python packages and copying application code
USER ${NB_USER}

# Copy requirements.txt and install Python packages
# Ensure Flask is in your requirements.txt (and gunicorn is NOT if you're not using it)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of your application's source code
COPY . .

# --- Flask Development Server Configuration ---
# Set Flask application entry point
ENV FLASK_APP=app.py

# Set FLASK_RUN_HOST to listen on all interfaces
ENV FLASK_RUN_HOST=0.0.0.0
# Set FLASK_RUN_PORT (optional, defaults to 5000)
ENV FLASK_RUN_PORT=5000

# Set FLASK_ENV to 'development' if you want auto-reload and debugger.
# For a more "production-like" test without Gunicorn, use 'production'
# but be aware of the limitations mentioned previously (not for real production traffic).
ENV FLASK_ENV=development

# Expose the port Flask will listen on
EXPOSE 5000

# Command to run the Flask application directly
# Using 'python -m flask run' is the recommended way.
CMD ["python", "-m", "flask", "run"]

# Alternative CMD if your app.py contains app.run() directly:
# CMD ["python", "app.py"]