Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +6 -199
Dockerfile
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
FROM ghcr.io/danny-avila/librechat-dev:latest
|
| 2 |
|
| 3 |
# Install dependencies
|
|
@@ -39,210 +40,16 @@ ENV HOST=0.0.0.0 \
|
|
| 39 |
NODE_ENV=production
|
| 40 |
|
| 41 |
# HTML Admin Panel
|
| 42 |
-
COPY
|
| 43 |
-
<!DOCTYPE html>
|
| 44 |
-
<html>
|
| 45 |
-
<head>
|
| 46 |
-
<title>LibreChat Admin</title>
|
| 47 |
-
<style>
|
| 48 |
-
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; }
|
| 49 |
-
.container { max-width: 1000px; margin: 0 auto; }
|
| 50 |
-
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
|
| 51 |
-
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
|
| 52 |
-
button { padding: 6px 12px; cursor: pointer; }
|
| 53 |
-
.login-form { max-width: 400px; margin: 50px auto; }
|
| 54 |
-
</style>
|
| 55 |
-
</head>
|
| 56 |
-
<body>
|
| 57 |
-
<div id="login" class="login-form" style="display: block;">
|
| 58 |
-
<h2>Admin Login</h2>
|
| 59 |
-
<input type="password" id="password" placeholder="Admin Password">
|
| 60 |
-
<button onclick="login()">Login</button>
|
| 61 |
-
</div>
|
| 62 |
-
|
| 63 |
-
<div id="admin-panel" class="container" style="display: none;">
|
| 64 |
-
<h1>User Management</h1>
|
| 65 |
-
<div>
|
| 66 |
-
<input type="text" id="new-username" placeholder="Username">
|
| 67 |
-
<input type="password" id="new-password" placeholder="Password">
|
| 68 |
-
<button onclick="addUser()">Add User</button>
|
| 69 |
-
</div>
|
| 70 |
-
<table id="users-table">
|
| 71 |
-
<thead>
|
| 72 |
-
<tr>
|
| 73 |
-
<th>Username</th>
|
| 74 |
-
<th>Actions</th>
|
| 75 |
-
</tr>
|
| 76 |
-
</thead>
|
| 77 |
-
<tbody></tbody>
|
| 78 |
-
</table>
|
| 79 |
-
</div>
|
| 80 |
-
|
| 81 |
-
<script>
|
| 82 |
-
let authToken = '';
|
| 83 |
-
|
| 84 |
-
async function login() {
|
| 85 |
-
const password = document.getElementById('password').value;
|
| 86 |
-
const response = await fetch('/sudo/login', {
|
| 87 |
-
method: 'POST',
|
| 88 |
-
headers: { 'Content-Type': 'application/json' },
|
| 89 |
-
body: JSON.stringify({ password })
|
| 90 |
-
});
|
| 91 |
-
|
| 92 |
-
if (response.ok) {
|
| 93 |
-
const data = await response.json();
|
| 94 |
-
authToken = data.token;
|
| 95 |
-
document.getElementById('login').style.display = 'none';
|
| 96 |
-
document.getElementById('admin-panel').style.display = 'block';
|
| 97 |
-
loadUsers();
|
| 98 |
-
} else {
|
| 99 |
-
alert('Login failed!');
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
async function loadUsers() {
|
| 104 |
-
const response = await fetch('/sudo/users', {
|
| 105 |
-
headers: { 'X-Auth-Token': authToken }
|
| 106 |
-
});
|
| 107 |
-
const users = await response.json();
|
| 108 |
-
|
| 109 |
-
const tbody = document.querySelector('#users-table tbody');
|
| 110 |
-
tbody.innerHTML = users.map(user => `
|
| 111 |
-
<tr>
|
| 112 |
-
<td>${user.username}</td>
|
| 113 |
-
<td>
|
| 114 |
-
<button onclick="deleteUser('${user.username}')">Delete</button>
|
| 115 |
-
</td>
|
| 116 |
-
</tr>
|
| 117 |
-
`).join('');
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
async function addUser() {
|
| 121 |
-
const username = document.getElementById('new-username').value;
|
| 122 |
-
const password = document.getElementById('new-password').value;
|
| 123 |
-
|
| 124 |
-
const response = await fetch('/sudo/users', {
|
| 125 |
-
method: 'POST',
|
| 126 |
-
headers: {
|
| 127 |
-
'Content-Type': 'application/json',
|
| 128 |
-
'X-Auth-Token': authToken
|
| 129 |
-
},
|
| 130 |
-
body: JSON.stringify({ username, password })
|
| 131 |
-
});
|
| 132 |
-
|
| 133 |
-
if (response.ok) {
|
| 134 |
-
loadUsers();
|
| 135 |
-
document.getElementById('new-username').value = '';
|
| 136 |
-
document.getElementById('new-password').value = '';
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
async function deleteUser(username) {
|
| 141 |
-
if (confirm(`Delete ${username}?`)) {
|
| 142 |
-
await fetch(`/sudo/users/${username}`, {
|
| 143 |
-
method: 'DELETE',
|
| 144 |
-
headers: { 'X-Auth-Token': authToken }
|
| 145 |
-
});
|
| 146 |
-
loadUsers();
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
-
</script>
|
| 150 |
-
</body>
|
| 151 |
-
</html>
|
| 152 |
-
EOF
|
| 153 |
-
|
| 154 |
# Admin Backend
|
| 155 |
-
COPY
|
| 156 |
-
from flask import Flask, request, jsonify, render_template
|
| 157 |
-
from pymongo.mongo_client import MongoClient
|
| 158 |
-
from pymongo.server_api import ServerApi
|
| 159 |
-
from werkzeug.security import generate_password_hash
|
| 160 |
-
import os
|
| 161 |
-
import hmac
|
| 162 |
-
from functools import wraps
|
| 163 |
-
|
| 164 |
-
app = Flask(__name__, template_folder='/app/sudo/templates')
|
| 165 |
-
app.secret_key = os.getenv("FLASK_SECRET")
|
| 166 |
-
|
| 167 |
-
# MongoDB connection
|
| 168 |
-
uri = os.getenv("MONGO_URI")
|
| 169 |
-
client = MongoClient(uri, server_api=ServerApi('1'))
|
| 170 |
-
db = client['librechat']
|
| 171 |
-
|
| 172 |
-
ADMIN_SECRET = os.getenv("ADMIN_SECRET")
|
| 173 |
-
|
| 174 |
-
# Authentication decorator
|
| 175 |
-
def require_auth(f):
|
| 176 |
-
@wraps(f)
|
| 177 |
-
def wrapper(*args, **kwargs):
|
| 178 |
-
auth_token = request.headers.get('X-Auth-Token')
|
| 179 |
-
if not auth_token or not hmac.compare_digest(auth_token, ADMIN_SECRET):
|
| 180 |
-
return jsonify({"error": "Unauthorized"}), 403
|
| 181 |
-
return f(*args, **kwargs)
|
| 182 |
-
return wrapper
|
| 183 |
-
|
| 184 |
-
# Routes
|
| 185 |
-
@app.route('/sudo')
|
| 186 |
-
def admin_panel():
|
| 187 |
-
return render_template('index.html')
|
| 188 |
-
|
| 189 |
-
@app.route('/sudo/login', methods=['POST'])
|
| 190 |
-
def login():
|
| 191 |
-
if not hmac.compare_digest(request.json.get('password') or '', ADMIN_SECRET):
|
| 192 |
-
return jsonify({"error": "Invalid credentials"}), 401
|
| 193 |
-
return jsonify({"token": ADMIN_SECRET})
|
| 194 |
-
|
| 195 |
-
@app.route('/sudo/users', methods=['GET'])
|
| 196 |
-
@require_auth
|
| 197 |
-
def list_users():
|
| 198 |
-
users = list(db.users.find({}, {"_id": 0, "username": 1}))
|
| 199 |
-
return jsonify(users)
|
| 200 |
-
|
| 201 |
-
@app.route('/sudo/users', methods=['POST'])
|
| 202 |
-
@require_auth
|
| 203 |
-
def add_user():
|
| 204 |
-
user_data = {
|
| 205 |
-
"username": request.json["username"],
|
| 206 |
-
"password": generate_password_hash(request.json["password"]),
|
| 207 |
-
"role": "user"
|
| 208 |
-
}
|
| 209 |
-
db.users.insert_one(user_data)
|
| 210 |
-
return jsonify({"status": "User added"})
|
| 211 |
-
|
| 212 |
-
@app.route('/sudo/users/<username>', methods=['DELETE'])
|
| 213 |
-
@require_auth
|
| 214 |
-
def delete_user(username):
|
| 215 |
-
result = db.users.delete_one({"username": username})
|
| 216 |
-
if result.deleted_count == 0:
|
| 217 |
-
return jsonify({"error": "User not found"}), 404
|
| 218 |
-
return jsonify({"status": "User deleted"})
|
| 219 |
-
@app.route('/sudo/debug')
|
| 220 |
-
def debug():
|
| 221 |
-
return jsonify({
|
| 222 |
-
"expected_password": os.getenv("ADMIN_SECRET", "NOT_SET!"),
|
| 223 |
-
"flask_secret_set": bool(os.getenv("FLASK_SECRET")),
|
| 224 |
-
"mongo_connected": bool(client)
|
| 225 |
-
})
|
| 226 |
-
|
| 227 |
-
if __name__ == "__main__":
|
| 228 |
-
app.run(host='0.0.0.0', port=5000)
|
| 229 |
-
EOF
|
| 230 |
-
|
| 231 |
# Caddy Configuration
|
| 232 |
RUN mkdir -p /app/caddy/
|
| 233 |
COPY Caddyfile /app/caddy/Caddyfile
|
| 234 |
-
|
| 235 |
# Startup script
|
| 236 |
-
COPY
|
| 237 |
-
#!/bin/sh
|
| 238 |
-
# Start the combined server
|
| 239 |
-
cd /app && npm run backend &
|
| 240 |
-
python3 /app/sudo/app.py &
|
| 241 |
-
caddy run --config /app/caddy/Caddyfile &
|
| 242 |
-
wait
|
| 243 |
-
EOF
|
| 244 |
-
|
| 245 |
RUN chmod +x /app/start.sh
|
| 246 |
-
|
| 247 |
EXPOSE 7860
|
|
|
|
| 248 |
CMD ["/app/start.sh"]
|
|
|
|
| 1 |
+
#original repo
|
| 2 |
FROM ghcr.io/danny-avila/librechat-dev:latest
|
| 3 |
|
| 4 |
# Install dependencies
|
|
|
|
| 40 |
NODE_ENV=production
|
| 41 |
|
| 42 |
# HTML Admin Panel
|
| 43 |
+
COPY index-temp.html /app/sudo/templates/index.html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# Admin Backend
|
| 45 |
+
COPY app-temp.py /app/sudo/app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Caddy Configuration
|
| 47 |
RUN mkdir -p /app/caddy/
|
| 48 |
COPY Caddyfile /app/caddy/Caddyfile
|
|
|
|
| 49 |
# Startup script
|
| 50 |
+
COPY start-temp.sh /app/start.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
RUN chmod +x /app/start.sh
|
| 52 |
+
# port
|
| 53 |
EXPOSE 7860
|
| 54 |
+
#endpoint
|
| 55 |
CMD ["/app/start.sh"]
|