File size: 993 Bytes
0aa8937
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Define environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    HF_HOME=/home/user/hf_home  

# Set the working directory in the container
WORKDIR $HOME/main

# Create the user, home directory, and HF_HOME directory
RUN useradd -m user && mkdir -p $HOME/main $HF_HOME && chown -R user:user $HOME

# Copy the current directory contents into the container
COPY --chown=user:user . $HOME/main

# Install FastAPI, Uvicorn, Transformers, and PyTorch
RUN pip install --no-cache-dir \
    fastapi \
    uvicorn \
    transformers \
    torch --extra-index-url https://download.pytorch.org/whl/cpu

# Switch to the non-root user
USER user

# Expose the port that FastAPI will run on
EXPOSE 8000

# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

HEALTHCHECK --interval=30s --timeout=30s --retries=3 \
  CMD curl --fail http://localhost:8000/ || exit 1