Hashii1729 commited on
Commit
a923a38
·
1 Parent(s): 82ec91b

Refactor Dockerfile to streamline user creation, add FastAPI startup script, and enhance directory structure for Ollama integration

Browse files
Files changed (1) hide show
  1. Dockerfile.fastapi +15 -7
Dockerfile.fastapi CHANGED
@@ -7,8 +7,11 @@ RUN apt-get update && apt-get install -y \
7
  && apt-get clean \
8
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
9
 
 
 
 
10
  # Create non-root user for security
11
- RUN groupadd -r appuser && useradd -r -g appuser appuser
12
 
13
  # Set working directory
14
  WORKDIR /app
@@ -18,14 +21,19 @@ COPY requirements.txt .
18
  RUN pip3 install --no-cache-dir --upgrade pip && \
19
  pip3 install --no-cache-dir -r requirements.txt
20
 
21
- # Copy FastAPI application
22
  COPY fast.py .
 
 
23
 
24
- # Create logs directory
25
- RUN mkdir -p /app/logs
 
 
26
 
27
  # Change ownership to non-root user
28
- RUN chown -R appuser:appuser /app
 
29
 
30
  # Switch to non-root user
31
  USER appuser
@@ -37,5 +45,5 @@ EXPOSE 7860
37
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
38
  CMD curl -f http://localhost:7860/health || exit 1
39
 
40
- # Start FastAPI
41
- CMD ["python3", "-m", "uvicorn", "fast:app", "--host", "0.0.0.0", "--port", "7860"]
 
7
  && apt-get clean \
8
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
9
 
10
+ # Install Ollama
11
+ RUN curl -fsSL https://ollama.com/install.sh | sh
12
+
13
  # Create non-root user for security
14
+ RUN groupadd -r appuser && useradd -r -g appuser -m appuser
15
 
16
  # Set working directory
17
  WORKDIR /app
 
21
  RUN pip3 install --no-cache-dir --upgrade pip && \
22
  pip3 install --no-cache-dir -r requirements.txt
23
 
24
+ # Copy FastAPI application and startup script
25
  COPY fast.py .
26
+ COPY fastapi_startup_script.sh .
27
+ RUN chmod +x fastapi_startup_script.sh
28
 
29
+ # Create logs directory and Ollama directories
30
+ RUN mkdir -p /app/logs && \
31
+ mkdir -p /home/appuser/.ollama && \
32
+ mkdir -p /home/appuser/.ollama/models
33
 
34
  # Change ownership to non-root user
35
+ RUN chown -R appuser:appuser /app && \
36
+ chown -R appuser:appuser /home/appuser/.ollama
37
 
38
  # Switch to non-root user
39
  USER appuser
 
45
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
46
  CMD curl -f http://localhost:7860/health || exit 1
47
 
48
+ # Start Ollama and FastAPI
49
+ CMD ["./fastapi_startup_script.sh"]