guydffdsdsfd commited on
Commit
1e5ee5f
·
verified ·
1 Parent(s): c92d564

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -21
Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
  FROM ollama/ollama:latest
2
 
3
- # Install Python and dependencies
4
  RUN apt-get update && apt-get install -y python3 python3-pip && \
5
  pip3 install flask flask-cors requests
6
 
@@ -11,24 +11,30 @@ ENV HOME=/home/ollama
11
 
12
  RUN mkdir -p /home/ollama/.ollama && chmod 777 /home/ollama/.ollama
13
 
14
- # Create the Security Proxy (Cleaner formatting to prevent Exit Code 1)
15
- RUN printf 'from flask import Flask, request, Response\n\
16
- import requests\n\
17
- from flask_cors import CORS\n\
18
- app = Flask(__name__)\n\
19
- CORS(app)\n\
20
- @app.route("/api/generate", methods=["POST"])\n\
21
- def proxy():\n\
22
- key = request.headers.get("x-api-key", "")\n\
23
- if not key.startswith("sk-") or len(key) < 10:\n\
24
- return {"error": "Invalid API Key"}, 401\n\
25
- try:\n\
26
- resp = requests.post("http://127.0.0.1:11434/api/generate", json=request.json)\n\
27
- return Response(resp.content, resp.status_code, resp.headers.items())\n\
28
- except:\n\
29
- return {"error": "Ollama not ready"}, 503\n\
30
- if __name__ == "__main__":\n\
31
- app.run(host="0.0.0.0", port=7860)' > /guard.py
32
-
33
- # Start Ollama and the Proxy together
 
 
 
 
 
 
34
  CMD ["/bin/sh", "-c", "ollama serve & sleep 15 && ollama pull phi3 && python3 /guard.py"]
 
1
  FROM ollama/ollama:latest
2
 
3
+ # Install Python and Gatekeeper dependencies
4
  RUN apt-get update && apt-get install -y python3 python3-pip && \
5
  pip3 install flask flask-cors requests
6
 
 
11
 
12
  RUN mkdir -p /home/ollama/.ollama && chmod 777 /home/ollama/.ollama
13
 
14
+ # Create the Security Proxy using a Here-Doc (Fixes Exit Code 1)
15
+ RUN cat <<EOF > /guard.py
16
+ from flask import Flask, request, Response
17
+ import requests
18
+ from flask_cors import CORS
19
+
20
+ app = Flask(__name__)
21
+ CORS(app)
22
+
23
+ @app.route("/api/generate", methods=["POST"])
24
+ def proxy():
25
+ key = request.headers.get("x-api-key", "")
26
+ # Gatekeeper: Any key starting with sk- and longer than 10 chars is valid
27
+ if not key.startswith("sk-") or len(key) < 10:
28
+ return {"error": "Invalid API Key"}, 401
29
+ try:
30
+ resp = requests.post("http://127.0.0.1:11434/api/generate", json=request.json)
31
+ return Response(resp.content, resp.status_code, resp.headers.items())
32
+ except:
33
+ return {"error": "Ollama server is still starting..."}, 503
34
+
35
+ if __name__ == "__main__":
36
+ app.run(host="0.0.0.0", port=7860)
37
+ EOF
38
+
39
+ # Start Ollama, pull the model, then start the Python Guard
40
  CMD ["/bin/sh", "-c", "ollama serve & sleep 15 && ollama pull phi3 && python3 /guard.py"]