File size: 1,235 Bytes
8b247b9
07631e1
143ffff
 
11c6d04
143ffff
48d1efa
143ffff
902fb2b
 
48d1efa
 
11c6d04
143ffff
156761e
143ffff
 
 
 
156761e
 
 
 
 
 
143ffff
 
 
902fb2b
 
 
 
 
 
 
 
 
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
FROM python:3.10.9

# Create a non-root user and group with a specified UID and GID
RUN addgroup --gid 1001 appgroup && adduser --uid 1001 --gid 1001 --disabled-password --gecos "" appuser

# Create directories with appropriate permissions and change ownership
RUN mkdir -m 777 /tmp/NUMBA_CACHE_DIR /tmp/MPLCONFIGDIR
RUN chown -R appuser:appgroup /tmp/NUMBA_CACHE_DIR /tmp/MPLCONFIGDIR

# Set environment variables
ENV NUMBA_CACHE_DIR=/tmp/NUMBA_CACHE_DIR/
ENV MPLCONFIGDIR=/tmp/MPLCONFIGDIR/

# Copy all files to the container
COPY . .

# Set the working directory
WORKDIR /

# Install virtualenv and set up the virtual environment as root
RUN python -m venv /opt/venv

# Change ownership of the virtual environment directory to the non-root user
RUN chown -R appuser:appgroup /opt/venv

# Switch to the non-root user
USER appuser

# Activate the virtual environment and install requirements
RUN /opt/venv/bin/pip install --no-cache-dir --upgrade pip && \
    /opt/venv/bin/pip install --no-cache-dir --upgrade -r /requirements.txt

# Ensure the virtual environment is activated for subsequent commands
ENV PATH="/opt/venv/bin:$PATH"

# Command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]