Spaces:
Running
Running
Commit
·
18e92b1
1
Parent(s):
b59d98b
tweaking nginx
Browse files- Dockerfile +21 -10
- README.md +1 -1
- myNodeServer.js +2 -99
- nginx.conf +4 -4
- run.sh +14 -5
Dockerfile
CHANGED
@@ -6,25 +6,36 @@ 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
|
10 |
/var/log/nginx \
|
11 |
/var/lib/nginx \
|
12 |
/var/run/nginx.pid
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# FROM node:20.6.1
|
22 |
-
|
23 |
-
COPY --chown=root . /app
|
24 |
|
25 |
RUN yarn install
|
26 |
|
27 |
-
EXPOSE
|
28 |
|
29 |
CMD ["bash", "run.sh"]
|
30 |
|
|
|
6 |
/var/log/nginx \
|
7 |
/var/lib/nginx
|
8 |
RUN touch /var/run/nginx.pid
|
9 |
+
RUN chown -R root:root /var/cache/nginx \
|
10 |
/var/log/nginx \
|
11 |
/var/lib/nginx \
|
12 |
/var/run/nginx.pid
|
13 |
|
14 |
+
|
15 |
+
ENV HOME=/home/root \
|
16 |
+
PATH=/home/root/.local/bin:$PATH
|
17 |
+
WORKDIR $HOME/app
|
18 |
+
|
19 |
+
RUN mkdir -p $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/
|
20 |
+
RUN chmod 777 $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/
|
21 |
+
RUN curl -L https://github.com/omnitool-ai/omnitool/raw/main/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1 -o $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1
|
22 |
+
RUN chmod 777 $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1
|
23 |
+
#RUN mv _tempfile.bin $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1 && chown -R root $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1
|
24 |
+
RUN mkdir $HOME/app/node_modules
|
25 |
+
RUN chmod 777 $HOME/app/node_modules
|
26 |
+
|
27 |
+
# Install dependencies and build app as non-root
|
28 |
+
#USER root
|
29 |
+
|
30 |
+
#COPY --chown=root _tempfile.bin $HOME/app/packages/omni-server/config.default/models/nsfwjs/mobilenet-v2-quant/group1-shard1of1
|
31 |
|
32 |
# FROM node:20.6.1
|
33 |
+
|
34 |
+
COPY --chown=root . $HOME/app
|
35 |
|
36 |
RUN yarn install
|
37 |
|
38 |
+
EXPOSE 1687
|
39 |
|
40 |
CMD ["bash", "run.sh"]
|
41 |
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🐳
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: gray
|
6 |
sdk: docker
|
7 |
-
app_port:
|
8 |
---
|
9 |
# Omnitool.ai - Your Open Source AI Desktop
|
10 |
|
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: gray
|
6 |
sdk: docker
|
7 |
+
app_port: 1687
|
8 |
---
|
9 |
# Omnitool.ai - Your Open Source AI Desktop
|
10 |
|
myNodeServer.js
CHANGED
@@ -1,87 +1,12 @@
|
|
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 |
-
|
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>
|
@@ -97,28 +22,6 @@ fastify.get('/', async (request, reply) => {
|
|
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 () => {
|
|
|
1 |
const fastify = require('fastify')({ logger: true });
|
|
|
|
|
|
|
|
|
2 |
let MANAGEMENT_SERVER_PORT = 7860;
|
3 |
let SERVER_HOST = '0.0.0.0';
|
4 |
+
console.log(`************ Management Server v 0.002 ************`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
fastify.get('/', async (request, reply) => {
|
7 |
const localUrl = request.headers['host'];
|
8 |
|
9 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
let htmlContent = `
|
11 |
<html>
|
12 |
<head><title>Proxy Server</title></head>
|
|
|
22 |
</html>
|
23 |
`;
|
24 |
reply.type('text/html').send(htmlContent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
});
|
26 |
|
27 |
const start = async () => {
|
nginx.conf
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
server {
|
2 |
-
listen
|
3 |
-
listen [::]:
|
4 |
|
5 |
server_name _;
|
6 |
|
7 |
location / {
|
8 |
-
# Serve myNodeServer
|
9 |
-
proxy_pass http://localhost:
|
10 |
proxy_http_version 1.1;
|
11 |
proxy_set_header Upgrade $http_upgrade;
|
12 |
proxy_set_header Connection 'upgrade';
|
|
|
1 |
server {
|
2 |
+
listen 1687 default_server;
|
3 |
+
listen [::]:1687 default_server;
|
4 |
|
5 |
server_name _;
|
6 |
|
7 |
location / {
|
8 |
+
# Serve myNodeServer 1689
|
9 |
+
proxy_pass http://localhost:1689;
|
10 |
proxy_http_version 1.1;
|
11 |
proxy_set_header Upgrade $http_upgrade;
|
12 |
proxy_set_header Connection 'upgrade';
|
run.sh
CHANGED
@@ -1,18 +1,27 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start Nginx
|
|
|
4 |
service nginx start
|
5 |
|
6 |
# Start the Node.js server in the background
|
7 |
-
|
|
|
8 |
|
9 |
# Start the main application with yarn in the background
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
# The script waits here for the yarn start process to terminate
|
14 |
-
|
|
|
15 |
|
16 |
# Cleanup: terminate and clean up background services
|
|
|
17 |
pkill -F node_server.pid
|
18 |
-
|
|
|
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start Nginx
|
4 |
+
echo "Starting Nginx..."
|
5 |
service nginx start
|
6 |
|
7 |
# Start the Node.js server in the background
|
8 |
+
echo "Starting Node.js server..."
|
9 |
+
node myNodeServer.js --port 1689 --host 0.0.0.0 & echo $! > node_server.pid
|
10 |
|
11 |
# Start the main application with yarn in the background
|
12 |
+
echo "Starting Yarn..."
|
13 |
+
yarn
|
14 |
+
|
15 |
+
echo "Starting Yarn service..."
|
16 |
+
yarn start -u -rb -R blocks & echo $! > yarn_service.pid
|
17 |
|
18 |
# The script waits here for the yarn start process to terminate
|
19 |
+
echo "Waiting for Yarn to terminate..."
|
20 |
+
wait $(cat yarn_service.pid)
|
21 |
|
22 |
# Cleanup: terminate and clean up background services
|
23 |
+
echo "Cleaning up..."
|
24 |
pkill -F node_server.pid
|
25 |
+
|
26 |
+
echo "killing .pid files..."
|
27 |
+
rm node_server.pid yarn_service.pid
|