Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +20 -17
Dockerfile
CHANGED
@@ -8,10 +8,12 @@ RUN apk update && apk add --no-cache \
|
|
8 |
py3-pip \
|
9 |
py3-dotenv \
|
10 |
&& pip install flask pymongo[srv] --break-system-packages
|
11 |
-
|
|
|
12 |
# Create admin structure
|
13 |
RUN mkdir -p /app/sudo/{templates,static} \
|
14 |
&& chown -R 1000:1000 /app
|
|
|
15 |
# Environment variables
|
16 |
ENV HOST=0.0.0.0 \
|
17 |
PORT=3080 \
|
@@ -25,10 +27,10 @@ ENV HOST=0.0.0.0 \
|
|
25 |
MONGO_URI="$MONGO_URI" \
|
26 |
SUDO_SECRET="$SUDO_SECRET" \
|
27 |
ADMIN_SECRET="$SUDO_SECRET" \
|
28 |
-
FLASK_SECRET="$
|
29 |
NODE_ENV=production
|
30 |
-
|
31 |
-
#
|
32 |
COPY <<"EOF" /app/sudo/templates/index.html
|
33 |
<!DOCTYPE html>
|
34 |
<html>
|
@@ -140,35 +142,37 @@ COPY <<"EOF" /app/sudo/templates/index.html
|
|
140 |
</body>
|
141 |
</html>
|
142 |
EOF
|
143 |
-
|
|
|
144 |
COPY <<"EOF" /app/sudo/app.py
|
145 |
-
from flask import Flask, request, jsonify
|
146 |
from pymongo.mongo_client import MongoClient
|
147 |
from pymongo.server_api import ServerApi
|
148 |
from werkzeug.security import generate_password_hash
|
149 |
import os
|
150 |
import hmac
|
151 |
-
from datetime import datetime
|
152 |
from functools import wraps
|
153 |
|
154 |
app = Flask(__name__, template_folder='/app/sudo/templates')
|
155 |
app.secret_key = os.getenv("FLASK_SECRET")
|
156 |
|
157 |
# MongoDB connection
|
158 |
-
|
159 |
-
client = MongoClient(
|
|
|
|
|
|
|
160 |
|
161 |
# Authentication decorator
|
162 |
-
def
|
163 |
@wraps(f)
|
164 |
def wrapper(*args, **kwargs):
|
165 |
-
auth_token = request.headers.get('X-
|
166 |
-
if auth_token
|
167 |
return jsonify({"error": "Unauthorized"}), 403
|
168 |
return f(*args, **kwargs)
|
169 |
return wrapper
|
170 |
|
171 |
-
|
172 |
# Routes
|
173 |
@app.route('/sudo')
|
174 |
def admin_panel():
|
@@ -209,11 +213,9 @@ if __name__ == "__main__":
|
|
209 |
app.run(host='0.0.0.0', port=5000)
|
210 |
EOF
|
211 |
|
212 |
-
#
|
213 |
RUN mkdir -p /app/caddy/
|
214 |
-
|
215 |
-
##################################
|
216 |
-
|
217 |
|
218 |
# Startup script
|
219 |
COPY <<"EOF" /app/start.sh
|
@@ -224,6 +226,7 @@ python3 /app/sudo/app.py &
|
|
224 |
caddy run --config /app/caddy/Caddyfile &
|
225 |
wait
|
226 |
EOF
|
|
|
227 |
RUN chmod +x /app/start.sh
|
228 |
|
229 |
EXPOSE 7860
|
|
|
8 |
py3-pip \
|
9 |
py3-dotenv \
|
10 |
&& pip install flask pymongo[srv] --break-system-packages
|
11 |
+
COPY config.yaml /app/librechat.yaml
|
12 |
+
|
13 |
# Create admin structure
|
14 |
RUN mkdir -p /app/sudo/{templates,static} \
|
15 |
&& chown -R 1000:1000 /app
|
16 |
+
|
17 |
# Environment variables
|
18 |
ENV HOST=0.0.0.0 \
|
19 |
PORT=3080 \
|
|
|
27 |
MONGO_URI="$MONGO_URI" \
|
28 |
SUDO_SECRET="$SUDO_SECRET" \
|
29 |
ADMIN_SECRET="$SUDO_SECRET" \
|
30 |
+
FLASK_SECRET="$SUDO_SECRET" \
|
31 |
NODE_ENV=production
|
32 |
+
|
33 |
+
# HTML Admin Panel
|
34 |
COPY <<"EOF" /app/sudo/templates/index.html
|
35 |
<!DOCTYPE html>
|
36 |
<html>
|
|
|
142 |
</body>
|
143 |
</html>
|
144 |
EOF
|
145 |
+
|
146 |
+
# Admin Backend
|
147 |
COPY <<"EOF" /app/sudo/app.py
|
148 |
+
from flask import Flask, request, jsonify, render_template
|
149 |
from pymongo.mongo_client import MongoClient
|
150 |
from pymongo.server_api import ServerApi
|
151 |
from werkzeug.security import generate_password_hash
|
152 |
import os
|
153 |
import hmac
|
|
|
154 |
from functools import wraps
|
155 |
|
156 |
app = Flask(__name__, template_folder='/app/sudo/templates')
|
157 |
app.secret_key = os.getenv("FLASK_SECRET")
|
158 |
|
159 |
# MongoDB connection
|
160 |
+
uri = os.getenv("MONGO_URI")
|
161 |
+
client = MongoClient(uri, server_api=ServerApi('1'))
|
162 |
+
db = client['librechat']
|
163 |
+
|
164 |
+
ADMIN_SECRET = os.getenv("ADMIN_SECRET")
|
165 |
|
166 |
# Authentication decorator
|
167 |
+
def require_auth(f):
|
168 |
@wraps(f)
|
169 |
def wrapper(*args, **kwargs):
|
170 |
+
auth_token = request.headers.get('X-Auth-Token')
|
171 |
+
if not auth_token or not hmac.compare_digest(auth_token, ADMIN_SECRET):
|
172 |
return jsonify({"error": "Unauthorized"}), 403
|
173 |
return f(*args, **kwargs)
|
174 |
return wrapper
|
175 |
|
|
|
176 |
# Routes
|
177 |
@app.route('/sudo')
|
178 |
def admin_panel():
|
|
|
213 |
app.run(host='0.0.0.0', port=5000)
|
214 |
EOF
|
215 |
|
216 |
+
# Caddy Configuration
|
217 |
RUN mkdir -p /app/caddy/
|
218 |
+
COPY Caddyfile /app/caddy/Caddyfile
|
|
|
|
|
219 |
|
220 |
# Startup script
|
221 |
COPY <<"EOF" /app/start.sh
|
|
|
226 |
caddy run --config /app/caddy/Caddyfile &
|
227 |
wait
|
228 |
EOF
|
229 |
+
|
230 |
RUN chmod +x /app/start.sh
|
231 |
|
232 |
EXPOSE 7860
|