File size: 2,349 Bytes
7832703
37e7cb9
 
79d7ca9
 
 
 
 
7832703
 
37e7cb9
7832703
bcea21a
 
 
 
 
7832703
 
78fbfa8
bcea21a
 
89100e4
bcea21a
37e7cb9
7832703
 
37e7cb9
5ab03c2
 
 
7832703
37e7cb9
 
bfa9638
37e7cb9
 
bfa9638
 
 
7832703
 
 
 
bfa9638
 
 
7832703
 
37e7cb9
79d7ca9
 
 
 
bcea21a
 
 
 
 
 
 
 
 
7832703
bfa9638
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
# Use an official Python runtime as a parent image
FROM python:3.9

# Install system dependencies required by OpenCV
RUN apt-get update && apt-get install -y \
    libgl1-mesa-glx \
 && rm -rf /var/lib/apt/lists/*

# Create a non-root user with a specified user ID
RUN useradd -m -u 1000 user

# Set environment variables for the non-root user
# Name -> Name of the app container
# EC_ADMIN_PWD -> A secret
# HF_MODEL_NAME -> Name of the Hugging Face Hub model
# GGUF_MODEL_URL -> For special loading for GGUF
# MODEL_CLASS -> A switch to load 'gguf' or 'hf'
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    NAME=EduConnect \
    EC_ADMIN_PWD='$2b$12$wGncNhE7OVmsb7TKFuNPKuJfKOIKdGtw302VMDJbAPrHrY73jqID.' \
    HF_MODEL_NAME="BitBasher/llama-2-7b-mini-ibased-GGUF" \
    GGUF_MODEL_URL='https://huggingface.co/BitBasher/llama-2-7b-mini-ibased-GGUF/resolve/main/llama-2-7b-mini-ibased.Q5_K_M.gguf' \
    MODEL_CLASS='gguf'

# Set the non-root user's home directory as the working directory
WORKDIR $HOME

# Create the /home/user/data directory and ensure it has the correct permissions
RUN mkdir -p ./data && chown user:user ./data

# Change to the non-root user
USER user

# Set the working directory to where the application files will be located
WORKDIR $HOME/app

# Copy only the requirements.txt first to leverage Docker cache
COPY --chown=user:user requirements.txt ./

# Install any needed packages specified in requirements.txt
# As the non-root user, ensure packages are installed to the user's home directory
RUN pip install --no-cache-dir --user -r requirements.txt

# Copy the rest of the application files into the container
COPY --chown=user:user . .

# Make port 7860 available to the world outside this container
EXPOSE 7860

# Indicate that a volume is expected at /home/user/data
# This directory is intended for persistent storage
VOLUME /home/user/data

# Copy the entrypoint script into the container and ensure it is executable
COPY --chown=user:user entrypoint.sh $HOME

# Change permission of entrypoint.sh and make sure it is executable
RUN chmod +x $HOME/entrypoint.sh

# Set the entrypoint script to be executed when the container starts
ENTRYPOINT ["./entrypoint.sh"]

# Run the FastAPI application using Uvicorn, binding to port 7860
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]