File size: 1,509 Bytes
5907aab
 
 
1efa748
5907aab
 
 
 
 
 
 
 
 
407cb31
c9875bd
5907aab
 
 
 
 
 
 
7c578b1
 
 
 
5907aab
7c578b1
1efa748
 
5907aab
407cb31
5907aab
c9875bd
5907aab
 
df0419a
7c578b1
1efa748
c9875bd
1efa748
c9875bd
 
1efa748
 
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
# Use official Python slim image
FROM python:3.9-slim

# Install Java Runtime Environment and build essentials
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    default-jre \
    gcc \
    python3-dev \
    && apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/home/user/app \
    JAVA_HOME=/usr/lib/jvm/default-java \
    _JAVA_OPTIONS="-Xmx4g"

# Create the application directory and set permissions BEFORE switching users
# This ensures the 'user' has full write access to their own app folder
RUN mkdir -p /home/user/app && chown user:user /home/user/app
WORKDIR /home/user/app

# Switch to the "user"
USER user

# Copy the requirements file and install dependencies as the "user"
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

# Copy the rest of the application and set ownership
COPY --chown=user . .

# Create necessary data directories as the user
RUN mkdir -p data/input data/output data/save_pdf data/raw_csv_temp data/output_process_data data/strictly_cleaned_data logs

# Expose port 7860
EXPOSE 7860

# Use 'python -m uvicorn' to ensure the user-installed package is found and executable
CMD ["python", "-m", "uvicorn", "telecom_anomaly.api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "60"]