martynka commited on
Commit
8ac3c5c
·
verified ·
1 Parent(s): 4ae47b1

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +186 -41
Dockerfile CHANGED
@@ -1,45 +1,190 @@
1
- # Pull the base image
2
- #FROM ghcr.io/danny-avila/librechat-dev:650e9b4f6c7e1ea063638ce10f95fbd53631f4bd
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  FROM ghcr.io/danny-avila/librechat-dev:latest
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Set environment variables
8
- ENV HOST=0.0.0.0
9
- ENV PORT=7860
10
- ENV SESSION_EXPIRY=900000
11
- ENV REFRESH_TOKEN_EXPIRY=604800000
12
- ENV SEARCH=true
13
- ENV MEILI_NO_ANALYTICS=true
14
- ENV MEILI_HOST=https://martynka-meilisearch.hf.space
15
- ENV CONFIG_PATH=/app/librechat.yaml
16
- ENV CUSTOM_FOOTER=EasierIT
17
- # Create necessary directories
18
- RUN mkdir -p /app/uploads/temp
19
- RUN mkdir -p /app/client/public/images/temp
20
- RUN mkdir -p /app/api/logs/
21
- RUN mkdir -p /app/data
22
-
23
- # Give write permission to the directory
24
- RUN chmod -R 777 /app/uploads/temp
25
- RUN chmod -R 777 /app/client/public/images
26
- RUN chmod -R 777 /app/api/logs/
27
- RUN chmod -R 777 /app/data
28
-
29
- user root
30
- RUN apk update
31
- RUN apk add git
32
- copy logo-pp.svg /app/client/public/assets/logo.svg
33
- copy logo-pp.svg /app/client/dist/assets/logo.svg
34
- copy logo-pp.svg /app/node_modules/date-fns/docs/logo.svg
35
- copy logo-pp.svg /app/node_modules/ldapjs/docs/branding/public/media/img/logo.svg
36
- copy logo-pp.svg /app/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg
37
- copy logo-pp.svg /app/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg
38
- copy logo-pp.svg /app/node_modules/psl/browserstack-logo.svg
39
- # Copy Custom Endpoints Config
40
- copy config.yaml /app/librechat.yaml
41
-
42
- # Install dependencies
43
- RUN cd /app/api && npm install
44
- # Command to run on container start
45
- CMD ["npm", "run", "backend"]
 
1
+ # Stage 1: Base LibreChat Image
2
+ FROM ghcr.io/danny-avila/librechat-dev:latest AS librechat-base
3
 
4
+ # Your existing customizations
5
+ USER root
6
+ RUN apk update && apk add git
7
+ COPY logo-pp.svg /app/client/public/assets/logo.svg
8
+ COPY logo-pp.svg /app/client/dist/assets/logo.svg
9
+ COPY logo-pp.svg /app/node_modules/date-fns/docs/logo.svg
10
+ COPY logo-pp.svg /app/node_modules/ldapjs/docs/branding/public/media/img/logo.svg
11
+ COPY logo-pp.svg /app/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg
12
+ COPY logo-pp.svg /app/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg
13
+ COPY logo-pp.svg /app/node_modules/psl/browserstack-logo.svg
14
+ COPY config.yaml /app/librechat.yaml
15
+
16
+ # Stage 2: Admin Panel Builder
17
+ FROM python:3.9-alpine AS admin-builder
18
+ WORKDIR /admin
19
+ RUN pip install flask pymongo werkzeug
20
+ COPY admin/ /admin/
21
+
22
+ # Stage 3: Final Image
23
  FROM ghcr.io/danny-avila/librechat-dev:latest
24
 
25
+ # Install additional dependencies
26
+ USER root
27
+ RUN apk add --no-cache \
28
+ nginx \
29
+ python3 \
30
+ py3-pip \
31
+ && pip3 install flask pymongo werkzeug
32
+
33
+ # Copy LibreChat with your customizations from base
34
+ COPY --from=librechat-base /app /app
35
+
36
+ # Setup directories
37
+ RUN mkdir -p /admin/templates /admin/static/css /admin/static/js
38
+ RUN chmod -R 777 /app/uploads/temp \
39
+ && chmod -R 777 /app/client/public/images \
40
+ && chmod -R 777 /app/api/logs/ \
41
+ && chmod -R 777 /app/data
42
+
43
+ # Copy admin panel from builder
44
+ COPY --from=admin-builder /admin /admin
45
+
46
+ # NGINX Configuration
47
+ COPY <<EOF /etc/nginx/nginx.conf
48
+ events { worker_connections 1024; }
49
+ http {
50
+ server {
51
+ listen 7860;
52
+ client_max_body_size 20M;
53
+
54
+ # LibreChat
55
+ location / {
56
+ proxy_pass http://localhost:3080;
57
+ proxy_set_header Host \$host;
58
+ proxy_set_header X-Real-IP \$remote_addr;
59
+ proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
60
+ }
61
+
62
+ # Admin Panel
63
+ location /sudo {
64
+ proxy_pass http://localhost:5000;
65
+ proxy_set_header Host \$host;
66
+ proxy_set_header X-Sudo-Secret \$http_x_sudo_secret;
67
+ }
68
+
69
+ # Static files
70
+ location /static {
71
+ proxy_pass http://localhost:5000/static;
72
+ }
73
+ }
74
+ }
75
+ EOF
76
+
77
+ # Admin Panel Files
78
+ COPY <<EOF /admin/templates/login.html
79
+ <!DOCTYPE html>
80
+ <html>
81
+ <head>
82
+ <title>Admin Login</title>
83
+ <link rel="stylesheet" href="/static/css/admin.css">
84
+ </head>
85
+ <body>
86
+ <div class="login-box">
87
+ <h2>Admin Portal</h2>
88
+ <form id="loginForm">
89
+ <input type="password" name="sudo_secret" placeholder="Sudo Secret" required>
90
+ <button type="submit">Login</button>
91
+ </form>
92
+ </div>
93
+ <script src="/static/js/login.js"></script>
94
+ </body>
95
+ </html>
96
+ EOF
97
+
98
+ COPY <<EOF /admin/app.py
99
+ from flask import Flask, request, jsonify, render_template
100
+ import os
101
+ from pymongo import MongoClient
102
+ from werkzeug.security import generate_password_hash
103
+
104
+ app = Flask(__name__, template_folder='templates', static_folder='static')
105
+ app.secret_key = os.getenv("FLASK_SECRET")
106
+
107
+ # MongoDB connection (using LibreChat's DB)
108
+ def get_db():
109
+ client = MongoClient(os.getenv("MONGO_URI"))
110
+ return client.get_database()
111
+
112
+ # Authentication
113
+ def is_authenticated(req):
114
+ return req.headers.get('X-Sudo-Secret') == os.getenv("SUDO_SECRET")
115
+
116
+ @app.route('/sudo')
117
+ def home():
118
+ return render_template('login.html')
119
+
120
+ @app.route('/sudo/login', methods=['POST'])
121
+ def login():
122
+ if request.json.get('sudo_secret') == os.getenv("SUDO_SECRET"):
123
+ return jsonify({"status": "success"})
124
+ return jsonify({"error": "Invalid secret"}), 403
125
+
126
+ @app.route('/sudo/dashboard')
127
+ def dashboard():
128
+ return render_template('dashboard.html')
129
+
130
+ @app.route('/sudo/add_user', methods=['POST'])
131
+ def add_user():
132
+ if not is_authenticated(request):
133
+ return jsonify({"error": "Unauthorized"}), 403
134
+
135
+ db = get_db()
136
+ db.users.insert_one({
137
+ "username": request.json["username"],
138
+ "password": generate_password_hash(request.json["password"]),
139
+ "role": "user"
140
+ })
141
+ return jsonify({"status": "User added"})
142
+
143
+ @app.route('/sudo/list_users', methods=['GET'])
144
+ def list_users():
145
+ if not is_authenticated(request):
146
+ return jsonify({"error": "Unauthorized"}), 403
147
+
148
+ db = get_db()
149
+ return jsonify([
150
+ {"username": u["username"]} for u in db.users.find({}, {"username": 1})
151
+ ])
152
+
153
+ if __name__ == "__main__":
154
+ app.run(host="0.0.0.0", port=5000)
155
+ EOF
156
+
157
+ # Startup Script
158
+ COPY <<EOF /start.sh
159
+ #!/bin/sh
160
+
161
+ # Start LibreChat (using your existing backend command)
162
+ cd /app/api && npm run backend &
163
+
164
+ # Start Admin Panel
165
+ cd /admin && python3 app.py &
166
+
167
+ # Start NGINX
168
+ nginx -g "daemon off;"
169
+
170
+ # Keep container running
171
+ wait
172
+ EOF
173
+ RUN chmod +x /start.sh
174
+
175
+ # Environment Variables
176
+ ENV HOST=0.0.0.0 \
177
+ PORT=3080 \
178
+ SESSION_EXPIRY=900000 \
179
+ REFRESH_TOKEN_EXPIRY=604800000 \
180
+ SEARCH=true \
181
+ MEILI_NO_ANALYTICS=true \
182
+ MEILI_HOST=https://martynka-meilisearch.hf.space \
183
+ CONFIG_PATH=/app/librechat.yaml \
184
+ CUSTOM_FOOTER=EasierIT \
185
+ MONGO_URI="$MONGO_URI" \
186
+ SUDO_SECRET="$SUDO_SECRET" \
187
+ FLASK_SECRET="$FLASK_SECRET"
188
 
189
+ EXPOSE 7860
190
+ CMD ["/start.sh"]