abdibrahem commited on
Commit
fd37d3e
·
1 Parent(s): 7918532
Files changed (2) hide show
  1. Dockerfile +47 -104
  2. main.py +3 -3
Dockerfile CHANGED
@@ -1,118 +1,64 @@
1
- # # Use Ubuntu as base image for better compatibility
2
- # FROM ubuntu:22.04
3
 
4
- # # Set environment variables
5
- # ENV DEBIAN_FRONTEND=noninteractive
6
- # ENV PYTHONUNBUFFERED=1
7
- # ENV PYTHONPATH=/app
8
- # ENV OLLAMA_HOST=0.0.0.0
9
- # ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
10
- # ENV HF_HOME=/app/.cache/huggingface
11
-
12
- # # Install system dependencies
13
- # RUN apt-get update && apt-get install -y \
14
- # curl \
15
- # wget \
16
- # git \
17
- # python3.10 \
18
- # python3-pip \
19
- # python3.10-venv \
20
- # && rm -rf /var/lib/apt/lists/*
21
-
22
- # # Create symbolic link for python3
23
- # RUN ln -sf /usr/bin/python3.10 /usr/bin/python3
24
 
25
  # # Create a non-root user
26
- # RUN useradd -m -s /bin/bash appuser
27
-
28
- # # Create necessary directories with proper permissions
29
- # RUN mkdir -p /app/.cache/huggingface \
30
- # && mkdir -p /app/.ollama \
31
- # && chown -R appuser:appuser /app \
32
- # && chown -R appuser:appuser /app/.cache \
33
- # && chown -R appuser:appuser /app/.ollama
34
 
35
- # # Install Ollama
36
- # RUN curl -fsSL https://ollama.com/install.sh | sh
37
-
38
- # # Set working directory
39
- # WORKDIR /app
40
 
41
- # # Copy requirements first to leverage Docker cache
42
- # COPY requirements.txt .
 
43
 
44
  # # Install Python dependencies
45
- # RUN pip3 install --no-cache-dir -r requirements.txt
 
46
 
47
- # # Copy the application code
48
  # COPY . .
49
 
50
- # # Set proper ownership of all files
51
- # RUN chown -R appuser:appuser /app
52
-
53
- # # Create a startup script with better logging and error handling
54
  # RUN echo '#!/bin/bash\n\
55
- # set -e\n\
56
- # \n\
57
- # echo "Starting Healthcare AI Assistant..."\n\
58
- # \n\
59
- # # Function to check if Ollama is running\n\
60
- # check_ollama() {\n\
61
- # curl -s http://localhost:11434/api/tags > /dev/null\n\
62
- # return $?\n\
63
- # }\n\
64
- # \n\
65
- # # Start Ollama in the background\n\
66
  # echo "Starting Ollama server..."\n\
67
  # ollama serve &\n\
68
- # OLLAMA_PID=$!\n\
69
  # \n\
70
- # # Wait for Ollama to start\n\
71
- # echo "Waiting for Ollama to start..."\n\
72
- # for i in {1..30}; do\n\
73
- # if check_ollama; then\n\
74
- # echo "Ollama server is running"\n\
75
- # break\n\
76
- # fi\n\
77
- # if [ $i -eq 30 ]; then\n\
78
- # echo "Error: Ollama server failed to start"\n\
79
- # exit 1\n\
80
- # fi\n\
81
- # sleep 1\n\
82
  # done\n\
83
  # \n\
84
- # # Pull Mistral model\n\
85
  # echo "Pulling Mistral model..."\n\
86
  # ollama pull mistral\n\
87
  # \n\
88
- # # Start FastAPI application\n\
89
  # echo "Starting FastAPI application..."\n\
90
- # cd /app\n\
91
- # \n\
92
- # # Keep the container running and show logs\n\
93
- # exec uvicorn main:app --host 0.0.0.0 --port 8000 --log-level info\n\
94
- # ' > /app/start.sh && chmod +x /app/start.sh
95
 
96
- # # Expose ports
97
- # # EXPOSE 8000 11434
98
 
99
  # # Switch to non-root user
100
  # USER appuser
101
 
102
- # # Set the entrypoint
103
- # ENTRYPOINT ["/app/start.sh"]
 
 
 
 
 
 
 
104
 
105
  # Use a base image with Python
106
  FROM python:3.10
107
 
108
- # Set environment variables
109
- ENV PYTHONUNBUFFERED=1
110
- ENV PYTHONPATH=/app
111
- ENV OLLAMA_HOST=0.0.0.0
112
- ENV TRANSFORMERS_CACHE=/home/appuser/.cache/huggingface
113
- ENV HF_HOME=/home/appuser/.cache/huggingface
114
- ENV API_BASE_URL=http://localhost:8000
115
-
116
  # Set the working directory
117
  WORKDIR /app
118
 
@@ -120,37 +66,32 @@ WORKDIR /app
120
  RUN useradd -m -u 1000 appuser
121
 
122
  # Install system dependencies
123
- RUN apt update && apt install -y curl && \
124
- curl -fsSL https://ollama.ai/install.sh | sh
 
125
 
126
- # Create necessary directories and set permissions
127
  RUN mkdir -p /home/appuser/.ollama && \
128
- mkdir -p /home/appuser/.cache/huggingface && \
129
- chown -R appuser:appuser /home/appuser/.ollama && \
130
- chown -R appuser:appuser /home/appuser/.cache
131
 
132
  # Install Python dependencies
133
- COPY requirements.txt requirements.txt
134
  RUN pip install --no-cache-dir -r requirements.txt
135
 
136
  # Copy application files
137
- COPY . .
138
 
139
  # Create a more robust startup script
140
  RUN echo '#!/bin/bash\n\
141
  set -e\n\
142
  \n\
143
- echo "Starting Healthcare AI Assistant..."\n\
144
- \n\
145
- # Start Ollama server\n\
146
  echo "Starting Ollama server..."\n\
147
  ollama serve &\n\
148
- OLLAMA_PID=$!\n\
149
  \n\
150
  # Wait for Ollama server to be ready\n\
151
  echo "Waiting for Ollama server to be ready..."\n\
152
- until curl -s http://localhost:11434/api/tags >/dev/null; do\n\
153
- echo "Waiting for Ollama server..."\n\
154
  sleep 2\n\
155
  done\n\
156
  \n\
@@ -158,8 +99,8 @@ echo "Pulling Mistral model..."\n\
158
  ollama pull mistral\n\
159
  \n\
160
  echo "Starting FastAPI application..."\n\
161
- exec uvicorn main:app --host 0.0.0.0 --port 7860 --log-level info\n\
162
- ' > start.sh && chmod +x start.sh
163
 
164
  # Set ownership of the application files
165
  RUN chown -R appuser:appuser /app
@@ -167,11 +108,13 @@ RUN chown -R appuser:appuser /app
167
  # Switch to non-root user
168
  USER appuser
169
 
170
- # Expose both ports
171
  EXPOSE 7860 11434
172
 
173
- # Set the HOME environment variable
174
  ENV HOME=/home/appuser
 
 
175
 
176
  # Run the startup script
177
  CMD ["./start.sh"]
 
1
+ # # Use a base image with Python
2
+ # FROM python:3.10
3
 
4
+ # # Set the working directory
5
+ # WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # # Create a non-root user
8
+ # RUN useradd -m -u 1000 appuser
 
 
 
 
 
 
 
9
 
10
+ # # Install system dependencies
11
+ # RUN apt update && apt install -y curl && \
12
+ # curl -fsSL https://ollama.ai/install.sh | sh
 
 
13
 
14
+ # # Create .ollama directory and set permissions
15
+ # RUN mkdir -p /home/appuser/.ollama && \
16
+ # chown -R appuser:appuser /home/appuser/.ollama
17
 
18
  # # Install Python dependencies
19
+ # COPY requirements.txt requirements.txt
20
+ # RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # # Copy application files
23
  # COPY . .
24
 
25
+ # # Create a more robust startup script
 
 
 
26
  # RUN echo '#!/bin/bash\n\
 
 
 
 
 
 
 
 
 
 
 
27
  # echo "Starting Ollama server..."\n\
28
  # ollama serve &\n\
 
29
  # \n\
30
+ # # Wait for Ollama server to be ready\n\
31
+ # until curl -s http://localhost:11434/api/tags >/dev/null; do\n\
32
+ # echo "Waiting for Ollama server to be ready..."\n\
33
+ # sleep 2\n\
 
 
 
 
 
 
 
 
34
  # done\n\
35
  # \n\
 
36
  # echo "Pulling Mistral model..."\n\
37
  # ollama pull mistral\n\
38
  # \n\
 
39
  # echo "Starting FastAPI application..."\n\
40
+ # uvicorn main:app --host 0.0.0.0 --port 7860' > start.sh && \
41
+ # chmod +x start.sh
 
 
 
42
 
43
+ # # Set ownership of the application files
44
+ # RUN chown -R appuser:appuser /app
45
 
46
  # # Switch to non-root user
47
  # USER appuser
48
 
49
+ # # Expose the port FastAPI will run on
50
+ # EXPOSE 7860
51
+
52
+ # # Set the HOME environment variable
53
+ # ENV HOME=/home/appuser
54
+
55
+ # # Run the startup script
56
+ # CMD ["./start.sh"]
57
+
58
 
59
  # Use a base image with Python
60
  FROM python:3.10
61
 
 
 
 
 
 
 
 
 
62
  # Set the working directory
63
  WORKDIR /app
64
 
 
66
  RUN useradd -m -u 1000 appuser
67
 
68
  # Install system dependencies
69
+ RUN apt-get update && apt-get install -y --no-install-recommends curl && \
70
+ curl -fsSL https://ollama.ai/install.sh | sh && \
71
+ rm -rf /var/lib/apt/lists/*
72
 
73
+ # Create .ollama directory and set permissions
74
  RUN mkdir -p /home/appuser/.ollama && \
75
+ chown -R appuser:appuser /home/appuser/.ollama
 
 
76
 
77
  # Install Python dependencies
78
+ COPY requirements.txt .
79
  RUN pip install --no-cache-dir -r requirements.txt
80
 
81
  # Copy application files
82
+ COPY --chown=appuser:appuser . .
83
 
84
  # Create a more robust startup script
85
  RUN echo '#!/bin/bash\n\
86
  set -e\n\
87
  \n\
88
+ # Start Ollama server in background\n\
 
 
89
  echo "Starting Ollama server..."\n\
90
  ollama serve &\n\
 
91
  \n\
92
  # Wait for Ollama server to be ready\n\
93
  echo "Waiting for Ollama server to be ready..."\n\
94
+ while ! curl -s http://localhost:11434 >/dev/null; do\n\
 
95
  sleep 2\n\
96
  done\n\
97
  \n\
 
99
  ollama pull mistral\n\
100
  \n\
101
  echo "Starting FastAPI application..."\n\
102
+ exec uvicorn main:app --host 0.0.0.0 --port 7860' > start.sh && \
103
+ chmod +x start.sh
104
 
105
  # Set ownership of the application files
106
  RUN chown -R appuser:appuser /app
 
108
  # Switch to non-root user
109
  USER appuser
110
 
111
+ # Expose both Ollama and FastAPI ports
112
  EXPOSE 7860 11434
113
 
114
+ # Set environment variables
115
  ENV HOME=/home/appuser
116
+ ENV OLLAMA_HOST=0.0.0.0
117
+ ENV PYTHONUNBUFFERED=1
118
 
119
  # Run the startup script
120
  CMD ["./start.sh"]
main.py CHANGED
@@ -750,6 +750,6 @@ async def health_check():
750
  async def root():
751
  return {"message": "Hello World"}
752
 
753
- if __name__ == "__main__":
754
- import uvicorn
755
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
750
  async def root():
751
  return {"message": "Hello World"}
752
 
753
+ # if __name__ == "__main__":
754
+ # import uvicorn
755
+ # uvicorn.run(app, host="0.0.0.0", port=8000)