Spaces:
Running
Running
Commit
·
b59d98b
1
Parent(s):
05c54fa
using reverse nginx proxy
Browse files- .mercs.yaml +4 -4
- Dockerfile +23 -11
- README.md +6 -6
- myNodeServer.js +134 -0
- nginx.conf +36 -0
- packages/omni-server/src/run.ts +1 -1
- run.sh +18 -0
.mercs.yaml
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
server:
|
2 |
network:
|
3 |
-
public_url: http://
|
4 |
rateLimit:
|
5 |
global: false
|
6 |
max: 1000
|
@@ -111,7 +111,7 @@ server:
|
|
111 |
cdn:
|
112 |
type: local
|
113 |
useLocalRoute: true #whether to use the local route or seaweed returned public url for serving images
|
114 |
-
localRoute: 'http://
|
115 |
kvStorage:
|
116 |
dbPath: './data.local/db'
|
117 |
|
@@ -119,11 +119,11 @@ server:
|
|
119 |
default_ttl: 7d #default ttl for temp artifacts
|
120 |
# ${{ if navigator.platform.startsWith("Win") }}:
|
121 |
# root: 'c://temp//cdn'
|
122 |
-
# url: '
|
123 |
# insecure: true #whether to use https (e.g. behind reverse proxy) when talking to volume nodes on the backend
|
124 |
# ${{ else }}:
|
125 |
root: './data.local/files'
|
126 |
-
url: '
|
127 |
insecure: true #whether to use https (e.g. behind reverse proxy) when talking to volume nodes on the backend
|
128 |
|
129 |
routes:
|
|
|
1 |
server:
|
2 |
network:
|
3 |
+
public_url: http://0.0.0.0.1688
|
4 |
rateLimit:
|
5 |
global: false
|
6 |
max: 1000
|
|
|
111 |
cdn:
|
112 |
type: local
|
113 |
useLocalRoute: true #whether to use the local route or seaweed returned public url for serving images
|
114 |
+
localRoute: 'http://0.0.0.0.1688/fid'
|
115 |
kvStorage:
|
116 |
dbPath: './data.local/db'
|
117 |
|
|
|
119 |
default_ttl: 7d #default ttl for temp artifacts
|
120 |
# ${{ if navigator.platform.startsWith("Win") }}:
|
121 |
# root: 'c://temp//cdn'
|
122 |
+
# url: '0.0.0.0.1688'
|
123 |
# insecure: true #whether to use https (e.g. behind reverse proxy) when talking to volume nodes on the backend
|
124 |
# ${{ else }}:
|
125 |
root: './data.local/files'
|
126 |
+
url: '0.0.0.0.1688'
|
127 |
insecure: true #whether to use https (e.g. behind reverse proxy) when talking to volume nodes on the backend
|
128 |
|
129 |
routes:
|
Dockerfile
CHANGED
@@ -1,21 +1,33 @@
|
|
1 |
-
FROM
|
2 |
-
USER node
|
3 |
-
WORKDIR /home/node/app
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
RUN curl -L https://github.com/omnitool-ai/omnitool/raw/main/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1 -o _tempfile.bin
|
6 |
-
RUN mkdir -p /
|
7 |
-
RUN chmod 777 /
|
8 |
-
RUN mv _tempfile.bin /
|
9 |
-
RUN chmod 777 /
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
RUN yarn install
|
14 |
|
15 |
-
EXPOSE
|
16 |
|
17 |
-
CMD [ "
|
18 |
|
19 |
|
20 |
# ## docker build -t manusapiens/omnitool-test2b .
|
21 |
-
# ## docker run --name
|
|
|
1 |
+
FROM nikolaik/python-nodejs:python3.10-nodejs20
|
|
|
|
|
2 |
|
3 |
+
USER root
|
4 |
+
RUN apt-get -y update && apt-get -y install nginx
|
5 |
+
RUN mkdir -p /var/cache/nginx \
|
6 |
+
/var/log/nginx \
|
7 |
+
/var/lib/nginx
|
8 |
+
RUN touch /var/run/nginx.pid
|
9 |
+
RUN chown -R pn:pn /var/cache/nginx \
|
10 |
+
/var/log/nginx \
|
11 |
+
/var/lib/nginx \
|
12 |
+
/var/run/nginx.pid
|
13 |
+
|
14 |
+
|
15 |
RUN curl -L https://github.com/omnitool-ai/omnitool/raw/main/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1 -o _tempfile.bin
|
16 |
+
RUN mkdir -p /app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/
|
17 |
+
RUN chmod 777 /app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/
|
18 |
+
RUN mv _tempfile.bin /app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1 && chown -R root /app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1
|
19 |
+
RUN chmod 777 /app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1
|
20 |
|
21 |
+
# FROM node:20.6.1
|
22 |
+
WORKDIR /app
|
23 |
+
COPY --chown=root . /app
|
24 |
|
25 |
RUN yarn install
|
26 |
|
27 |
+
EXPOSE 4444
|
28 |
|
29 |
+
CMD ["bash", "run.sh"]
|
30 |
|
31 |
|
32 |
# ## docker build -t manusapiens/omnitool-test2b .
|
33 |
+
# ## docker run --name n13 -p 1688:1688 -d manusapiens/omnitool-test2b
|
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title: O T 3
|
3 |
emoji: 🐳
|
4 |
colorFrom: yellow
|
5 |
colorTo: gray
|
6 |
sdk: docker
|
7 |
-
app_port:
|
8 |
---
|
9 |
# Omnitool.ai - Your Open Source AI Desktop
|
10 |
|
@@ -182,14 +182,14 @@ You can then access the Omnitool software from a web browser on your local machi
|
|
182 |
|
183 |
```
|
184 |
◐ Booting Server
|
185 |
-
✔ Server has started and is ready to accept connections on http://
|
186 |
✔ Ctrl-C to quit.
|
187 |
```
|
188 |
|
189 |
5. **Open Omnitool in a Web Browser**
|
190 |
|
191 |
Omnitool.ai can now be accessed from:
|
192 |
-
[
|
193 |
|
194 |
---
|
195 |
6. **Explore the Sample Recipes**
|
@@ -266,7 +266,7 @@ Once you have your JWT, you can execute a recipe by making a POST request to the
|
|
266 |
**Endpoint**
|
267 |
|
268 |
```
|
269 |
-
POST http://
|
270 |
```
|
271 |
|
272 |
**Header**
|
@@ -282,7 +282,7 @@ Authorization: Bearer <token>
|
|
282 |
To make the request using curl, you would use the following command, replacing <token> with your actual JWT:
|
283 |
|
284 |
```
|
285 |
-
curl -X POST http://
|
286 |
```
|
287 |
|
288 |
**Response**
|
|
|
1 |
---
|
2 |
+
title: O T 3 - nginx edition
|
3 |
emoji: 🐳
|
4 |
colorFrom: yellow
|
5 |
colorTo: gray
|
6 |
sdk: docker
|
7 |
+
app_port: 4444
|
8 |
---
|
9 |
# Omnitool.ai - Your Open Source AI Desktop
|
10 |
|
|
|
182 |
|
183 |
```
|
184 |
◐ Booting Server
|
185 |
+
✔ Server has started and is ready to accept connections on http://0.0.0.0.1688.
|
186 |
✔ Ctrl-C to quit.
|
187 |
```
|
188 |
|
189 |
5. **Open Omnitool in a Web Browser**
|
190 |
|
191 |
Omnitool.ai can now be accessed from:
|
192 |
+
[0.0.0.0.1688](http://0.0.0.0.1688)
|
193 |
|
194 |
---
|
195 |
6. **Explore the Sample Recipes**
|
|
|
266 |
**Endpoint**
|
267 |
|
268 |
```
|
269 |
+
POST http://0.0.0.0.1688/api/v1/workflow/exec
|
270 |
```
|
271 |
|
272 |
**Header**
|
|
|
282 |
To make the request using curl, you would use the following command, replacing <token> with your actual JWT:
|
283 |
|
284 |
```
|
285 |
+
curl -X POST http://0.0.0.0.1688/api/v1/workflow/exec -H "Authorization: Bearer <token>"
|
286 |
```
|
287 |
|
288 |
**Response**
|
myNodeServer.js
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const fastify = require('fastify')({ logger: true });
|
2 |
+
const { spawn } = require('child_process');
|
3 |
+
|
4 |
+
let OMNITOOL_READY = false;
|
5 |
+
let ALREADY_STARTING = false;
|
6 |
+
let MANAGEMENT_SERVER_PORT = 7860;
|
7 |
+
let SERVER_HOST = '0.0.0.0';
|
8 |
+
console.log(`************ Management Server ************`);
|
9 |
+
let omnitoolLogs = [];
|
10 |
+
|
11 |
+
async function startOmnitoolServer() {
|
12 |
+
if (ALREADY_STARTING) return;
|
13 |
+
ALREADY_STARTING = true;
|
14 |
+
|
15 |
+
console.log('Starting Omnitool Server...');
|
16 |
+
return new Promise((resolve, reject) => {
|
17 |
+
const omnitoolStartProcess = spawn('./omnitool_start.sh');
|
18 |
+
|
19 |
+
omnitoolStartProcess.stdout.on('data', (data) => {
|
20 |
+
omnitoolLogs.push(data.toString());
|
21 |
+
console.log(`omnitool stdout: ${data}`);
|
22 |
+
if (data.toString().includes(`Server has started and is ready to accept connections`)) {
|
23 |
+
OMNITOOL_READY = true;
|
24 |
+
console.log('Omnitool server started successfully');
|
25 |
+
resolve();
|
26 |
+
}
|
27 |
+
});
|
28 |
+
|
29 |
+
omnitoolStartProcess.stderr.on('data', (data) => {
|
30 |
+
console.error(`omnitool stderr: ${data}`);
|
31 |
+
});
|
32 |
+
|
33 |
+
omnitoolStartProcess.on('close', (code) => {
|
34 |
+
console.log(`Omnitool server process exited with code ${code}`);
|
35 |
+
if (!OMNITOOL_READY) {
|
36 |
+
ALREADY_STARTING = false;
|
37 |
+
reject(`Omnitool server did not start within the timeout period.`);
|
38 |
+
}
|
39 |
+
});
|
40 |
+
});
|
41 |
+
}
|
42 |
+
|
43 |
+
fastify.get('/', async (request, reply) => {
|
44 |
+
const localUrl = request.headers['host'];
|
45 |
+
|
46 |
+
if (!OMNITOOL_READY) {
|
47 |
+
let htmlContent = `
|
48 |
+
<html>
|
49 |
+
<head><title>Proxy Server</title></head>
|
50 |
+
<body>
|
51 |
+
<button id="startServerButton" onclick="startServer()">Start Omnitool Server</button>
|
52 |
+
<button onclick="window.location.href='http://${localUrl}'">${localUrl}</button>
|
53 |
+
<div id="logs" style="white-space: pre-wrap;"></div>
|
54 |
+
<script>
|
55 |
+
function startServer() {
|
56 |
+
document.getElementById('startServerButton').disabled = true;
|
57 |
+
fetch('/start-omnitool-server')
|
58 |
+
.then(response => response.json())
|
59 |
+
.then(data => {
|
60 |
+
startLogPolling();
|
61 |
+
});
|
62 |
+
}
|
63 |
+
|
64 |
+
function startLogPolling() {
|
65 |
+
const interval = setInterval(() => {
|
66 |
+
fetch('/omnitool-logs')
|
67 |
+
.then(response => response.json())
|
68 |
+
.then(data => {
|
69 |
+
document.getElementById('logs').innerText = data.logs.join("\\n");
|
70 |
+
if (data.ready) {
|
71 |
+
clearInterval(interval);
|
72 |
+
window.location.reload(); // Refresh the page when Omnitool is ready
|
73 |
+
}
|
74 |
+
});
|
75 |
+
}, 1000);
|
76 |
+
}
|
77 |
+
|
78 |
+
startLogPolling();
|
79 |
+
</script>
|
80 |
+
</body>
|
81 |
+
</html>
|
82 |
+
`;
|
83 |
+
reply.type('text/html').send(htmlContent);
|
84 |
+
} else {
|
85 |
+
let htmlContent = `
|
86 |
+
<html>
|
87 |
+
<head><title>Proxy Server</title></head>
|
88 |
+
<body>
|
89 |
+
<button onclick="redirect()">Goto: ${localUrl}</button>
|
90 |
+
<script>
|
91 |
+
function redirect() {
|
92 |
+
window.location.replace('http://${localUrl}/omnitool');
|
93 |
+
}
|
94 |
+
</script>
|
95 |
+
<div id="logs" style="white-space: pre-wrap;"></div>
|
96 |
+
</body>
|
97 |
+
</html>
|
98 |
+
`;
|
99 |
+
reply.type('text/html').send(htmlContent);
|
100 |
+
}
|
101 |
+
});
|
102 |
+
|
103 |
+
fastify.get('/omnitool-logs', async (request, reply) => {
|
104 |
+
reply.send({ logs: omnitoolLogs, ready: OMNITOOL_READY });
|
105 |
+
});
|
106 |
+
|
107 |
+
fastify.get('/start-omnitool-server', async (request, reply) => {
|
108 |
+
if (!OMNITOOL_READY) {
|
109 |
+
if (ALREADY_STARTING) {
|
110 |
+
return { message: "Omnitool server already starting" };
|
111 |
+
}
|
112 |
+
try {
|
113 |
+
await startOmnitoolServer();
|
114 |
+
reply.send({ message: "Omnitool server started successfully" });
|
115 |
+
} catch (error) {
|
116 |
+
console.error(error);
|
117 |
+
reply.send({ message: `Error starting Omnitool server: ${error}` });
|
118 |
+
}
|
119 |
+
} else {
|
120 |
+
reply.send({ message: "Omnitool server already running" });
|
121 |
+
}
|
122 |
+
});
|
123 |
+
|
124 |
+
const start = async () => {
|
125 |
+
try {
|
126 |
+
await fastify.listen({ port: MANAGEMENT_SERVER_PORT, host: SERVER_HOST });
|
127 |
+
console.log(`Server is listening on port ${MANAGEMENT_SERVER_PORT}`);
|
128 |
+
} catch (err) {
|
129 |
+
console.error(`Error starting server: ${err}`);
|
130 |
+
process.exit(1);
|
131 |
+
}
|
132 |
+
};
|
133 |
+
|
134 |
+
start();
|
nginx.conf
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
server {
|
2 |
+
listen 4444 default_server;
|
3 |
+
listen [::]:4444 default_server;
|
4 |
+
|
5 |
+
server_name _;
|
6 |
+
|
7 |
+
location / {
|
8 |
+
# Serve myNodeServer 7860
|
9 |
+
proxy_pass http://localhost:7860;
|
10 |
+
proxy_http_version 1.1;
|
11 |
+
proxy_set_header Upgrade $http_upgrade;
|
12 |
+
proxy_set_header Connection 'upgrade';
|
13 |
+
proxy_set_header Host $host;
|
14 |
+
proxy_set_header X-Real-IP $remote_addr;
|
15 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
16 |
+
proxy_cache_bypass $http_upgrade;
|
17 |
+
proxy_read_timeout 86400;
|
18 |
+
proxy_redirect off;
|
19 |
+
}
|
20 |
+
|
21 |
+
location /omnitool/ {
|
22 |
+
# Serve omnitool on 1688
|
23 |
+
rewrite ^/omnitool/(.*) /$1 break;
|
24 |
+
proxy_pass http://localhost:1688;
|
25 |
+
proxy_http_version 1.1;
|
26 |
+
proxy_set_header Upgrade $http_upgrade;
|
27 |
+
proxy_set_header Connection 'upgrade';
|
28 |
+
proxy_set_header Host $host;
|
29 |
+
proxy_set_header X-Real-IP $remote_addr;
|
30 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
31 |
+
proxy_cache_bypass $http_upgrade;
|
32 |
+
proxy_read_timeout 86400;
|
33 |
+
proxy_redirect off;
|
34 |
+
}
|
35 |
+
|
36 |
+
}
|
packages/omni-server/src/run.ts
CHANGED
@@ -229,7 +229,7 @@ const boot = async (options: OptionValues) => {
|
|
229 |
// needs to be reworked. But for now this allows us to run code on both client and server.
|
230 |
const apiConfig: IAPIServerServiceConfig = {
|
231 |
id: 'api',
|
232 |
-
host: 'http://
|
233 |
integrationsUrl: '/api/v1/mercenaries/integrations'
|
234 |
};
|
235 |
server.use(APIServerService, apiConfig);
|
|
|
229 |
// needs to be reworked. But for now this allows us to run code on both client and server.
|
230 |
const apiConfig: IAPIServerServiceConfig = {
|
231 |
id: 'api',
|
232 |
+
host: 'http://0.0.0.0.1688', // remote API is disabled?
|
233 |
integrationsUrl: '/api/v1/mercenaries/integrations'
|
234 |
};
|
235 |
server.use(APIServerService, apiConfig);
|
run.sh
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Start Nginx
|
4 |
+
service nginx start
|
5 |
+
|
6 |
+
# Start the Node.js server in the background
|
7 |
+
node myNodeServer.js --port 7860 --host 0.0.0.0 & echo $! > node_server.pid
|
8 |
+
|
9 |
+
# Start the main application with yarn in the background
|
10 |
+
# yarn
|
11 |
+
# yarn start -u -rb -R blocks & echo $! > yarn_service.pid
|
12 |
+
|
13 |
+
# The script waits here for the yarn start process to terminate
|
14 |
+
wait $(cat node_server.pid)
|
15 |
+
|
16 |
+
# Cleanup: terminate and clean up background services
|
17 |
+
pkill -F node_server.pid
|
18 |
+
rm node_server.pid
|