File size: 2,546 Bytes
ce1cf1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f010284
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
77
78
79
80
81
82
83
84
85
# Use the official Python 3.9 image as the base image
FROM python:3.9

# Expose the port
EXPOSE 7860

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Set the PYNGROK_CONFIG environment variable
ENV PYNGROK_CONFIG /tmp/pyngrok.yml

# Set the NGROK_PATH environment variable to a writable location
ENV NGROK_PATH /tmp/ngrok

# Copy requirements.txt into the container
COPY requirements.txt .

# Upgrade pip and install the required packages
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

# Install sudo and create the necessary directories before copying the files
RUN apt-get update && \
    apt-get install -y sudo && \
    mkdir -p /code/image

# Creates a non-root user with an explicit UID and adds permission to access the /code folder
RUN adduser -u 5678 --disabled-password --gecos "" appuser && \
    usermod -aG sudo appuser && \
    usermod -aG root appuser && \
    chown -R appuser:appuser /code

# Create the pyngrok bin directory and set the ownership and permissions for appuser
RUN mkdir -p /usr/local/lib/python3.9/site-packages/pyngrok/bin && \
    chown -R appuser:appuser /usr/local/lib/python3.9/site-packages/pyngrok/bin && \
    chmod -R 777 /usr/local/lib/python3.9/site-packages/pyngrok/bin

RUN mkdir -p /.ngrok2 && \
    chown -R appuser:appuser /.ngrok2 && \
    chmod -R 777 /.ngrok2

RUN apt-get update && \
    apt-get install -y curl

# Set the working directory and copy the files
WORKDIR /code

# Set the ownership and permissions for the /code directory and its contents
RUN chown -R appuser:appuser /code && \
    chmod -R 777 /code

RUN mkdir /.cache
RUN chmod -R 777 /.cache

RUN mkdir /nltk_data
RUN chmod -R 777 /nltk_data

COPY . /code

# RUN chown -R appuser:appuser /code/data.csv && \
#     chmod -R 777 /code/data.csv

# Copy the pyngrok.yml configuration file
COPY pyngrok.yml /tmp/pyngrok.yml

# Set the TRANSFORMERS_CACHE environment variable to a cache directory inside /tmp
ENV TRANSFORMERS_CACHE /tmp/transformers_cache
ENV TORCH_HOME /tmp/torch_cache

USER appuser

# Start the application using pyngrok
# CMD python main.py
# Get the public IP address and display it
RUN curl -s https://api.ipify.org | xargs echo "Public IP:"
RUN pip install gunicorn

# Start the Uvicorn server
# ENTRYPOINT ["python", "main.py"]
# CMD ["sh", "-c", "python main.py & sleep infinity"]
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860","--workers","5"]