kylsprt commited on
Commit
d41e7ae
·
verified ·
1 Parent(s): 917a965

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +48 -1
Dockerfile CHANGED
@@ -1,7 +1,54 @@
1
  FROM python:3.10-slim
 
 
 
 
 
 
2
  WORKDIR /app
 
3
  COPY requirements.txt .
4
  RUN pip install --no-cache-dir -r requirements.txt
 
 
 
5
  COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  EXPOSE 7860
7
- CMD ["python", "main.py"]
 
1
  FROM python:3.10-slim
2
+
3
+ RUN apt-get update && apt-get install -y curl ca-certificates gnupg && \
4
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
5
+ apt-get install -y nodejs && \
6
+ rm -rf /var/lib/apt/lists/*
7
+
8
  WORKDIR /app
9
+
10
  COPY requirements.txt .
11
  RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ RUN npm install http-proxy
14
+
15
  COPY . .
16
+
17
+ RUN cat > /app/gateway.js << 'GWEOF'
18
+ var http = require('http');
19
+ var httpProxy = require('http-proxy');
20
+ var DOMAIN = process.env.DOMAIN || '';
21
+ var proxy = httpProxy.createProxyServer({ target: 'http://127.0.0.1:3001', ws: true });
22
+ proxy.on('error', function(e, req, res) {
23
+ if (res && res.writeHead) { res.writeHead(502); res.end('502'); }
24
+ });
25
+ function ok(req) {
26
+ if (!DOMAIN) return true;
27
+ var h = (req.headers['x-real-domain'] || '') + '|' + (req.headers['x-forwarded-host'] || '') + '|' + (req.headers['host'] || '');
28
+ return h.indexOf(DOMAIN) !== -1;
29
+ }
30
+ var s = http.createServer(function(req, res) {
31
+ if (ok(req)) {
32
+ proxy.web(req, res);
33
+ } else {
34
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
35
+ res.end('200 OK');
36
+ }
37
+ });
38
+ s.on('upgrade', function(req, socket, head) {
39
+ if (ok(req)) { proxy.ws(req, socket, head); } else { socket.destroy(); }
40
+ });
41
+ s.listen(7860, function() { console.log('[GW] 7860 -> 3001'); });
42
+ GWEOF
43
+
44
+ RUN cat > /start.sh << 'SHEOF'
45
+ #!/bin/sh
46
+ python -m uvicorn main:app --host 0.0.0.0 --port 3001 &
47
+ sleep 3
48
+ exec node /app/gateway.js
49
+ SHEOF
50
+
51
+ RUN chmod +x /start.sh
52
+
53
  EXPOSE 7860
54
+ CMD ["/start.sh"]