File size: 2,187 Bytes
3a99b13
5008683
 
 
 
 
 
 
 
 
 
 
f0525d6
 
64bc443
f0525d6
5008683
 
 
 
 
 
f0525d6
 
 
 
 
 
157dac3
 
 
 
 
 
 
 
 
 
 
 
 
f0525d6
 
 
 
 
 
 
5008683
 
 
 
 
 
 
 
 
f0525d6
 
 
 
 
 
5008683
 
 
 
 
 
 
 
 
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
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set environment variables for Hugging Face and Matplotlib cache
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
ENV HF_HOME=/app/.cache/huggingface
ENV MPLCONFIGDIR=/app/.cache/matplotlib

# Create cache directories and assign permissions
RUN mkdir -p /app/.cache/huggingface /app/.cache/matplotlib

# Install system dependencies
RUN apt-get update && apt-get install -y \
    libgl1-mesa-glx \
    libgomp1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user and group
RUN groupadd -r appgroup && useradd -r -g appgroup appuser

# Create necessary directories
RUN mkdir -p /app/flask_sessions /app/uploads /app/data /app/JSON /app/Models /app/logs /tmp/matplotlib /tmp/transformers_cache

# Create directories for uploads and set permissions
RUN mkdir -p /app/uploads && chmod -R 777 /app/uploads

# Create directories for data and set permissions
RUN mkdir -p /app/data && chmod -R 777 /app/data

# Create directories for JSON and set permissions
RUN mkdir -p /app/JSON && chmod -R 777 /app/JSON

# Create directories for Models and set permissions
RUN mkdir -p /app/Models && chmod -R 777 /app/Models


# Set permissions for app directories
RUN chown -R appuser:appgroup /app /tmp/matplotlib /tmp/transformers_cache \
    && chmod -R 755 /app /tmp/matplotlib /tmp/transformers_cache

# Set working directory
WORKDIR /app

# Copy the requirements file into the container at /app
COPY requirements.txt /app/

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy the rest of the application code to /app
COPY . /app/

# Ensure app user owns the app directory
RUN chown -R appuser:appgroup /app

# Switch to non-root user
USER appuser

# Expose the port that the app runs on
EXPOSE 7860

# Set environment variables for Flask
ENV FLASK_APP=app.py
ENV FLASK_ENV=production

# Command to run the Flask app using Gunicorn with 1 worker
CMD ["gunicorn", "--workers=1", "--bind=0.0.0.0:7860", "--timeout=120", "app:app"]