T-K-O-H commited on
Commit
ce67515
·
1 Parent(s): 65c8966

Update code to use environment variables and improve error handling

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -0
Dockerfile CHANGED
@@ -9,6 +9,9 @@ RUN apt-get update && apt-get install -y \
9
  software-properties-common \
10
  && rm -rf /var/lib/apt/lists/*
11
 
 
 
 
12
  # Copy requirements first for better caching
13
  COPY requirements.txt /code/requirements.txt
14
  RUN pip install --no-cache-dir -r requirements.txt
@@ -16,10 +19,23 @@ RUN pip install --no-cache-dir -r requirements.txt
16
  # Copy the rest of the application
17
  COPY . /code/
18
 
 
 
 
 
 
 
 
 
19
  # Set environment variables
20
  ENV HOST=0.0.0.0
21
  ENV PORT=7860
22
  ENV PYTHONPATH=/code
 
 
 
 
 
23
 
24
  # Command to run the application
25
  CMD chainlit run app.py --host $HOST --port $PORT
 
9
  software-properties-common \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # Create a non-root user
13
+ RUN useradd -m -u 1000 chainlit_user
14
+
15
  # Copy requirements first for better caching
16
  COPY requirements.txt /code/requirements.txt
17
  RUN pip install --no-cache-dir -r requirements.txt
 
19
  # Copy the rest of the application
20
  COPY . /code/
21
 
22
+ # Create necessary directories and set permissions
23
+ RUN mkdir -p /code/.files && \
24
+ mkdir -p /code/.chainlit && \
25
+ chown -R chainlit_user:chainlit_user /code && \
26
+ chmod -R 755 /code && \
27
+ chmod -R 777 /code/.files && \
28
+ chmod -R 777 /code/.chainlit
29
+
30
  # Set environment variables
31
  ENV HOST=0.0.0.0
32
  ENV PORT=7860
33
  ENV PYTHONPATH=/code
34
+ ENV OPENAI_API_KEY=${OPENAI_API_KEY}
35
+ ENV PYTHONUNBUFFERED=1
36
+
37
+ # Switch to non-root user
38
+ USER chainlit_user
39
 
40
  # Command to run the application
41
  CMD chainlit run app.py --host $HOST --port $PORT