clone3 commited on
Commit
efcf453
·
verified ·
1 Parent(s): 2fa2d17

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +33 -81
Dockerfile CHANGED
@@ -1,87 +1,39 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const http = require('http');
4
- const SSHClient = require('ssh2').Client;
5
- const socketIO = require('socket.io');
6
 
7
- // Create HTTP server
8
- const server = http.createServer(onRequest);
9
 
10
- // Attach Socket.IO to the server
11
- const io = socketIO(server);
12
 
13
- // Load static files into memory
14
- let staticFiles = {};
15
- let basePath = path.join(require.resolve('xterm'), '..');
16
- staticFiles['/xterm.css'] = fs.readFileSync(path.join(basePath, '../css/xterm.css'));
17
- staticFiles['/xterm.js'] = fs.readFileSync(path.join(basePath, 'xterm.js'));
18
- basePath = path.join(require.resolve('xterm-addon-fit'), '..');
19
- staticFiles['/xterm-addon-fit.js'] = fs.readFileSync(path.join(basePath, 'xterm-addon-fit.js'));
20
- staticFiles['/'] = fs.readFileSync('index.html');
21
 
22
- // Handle static file serving
23
- function onRequest(req, res) {
24
- let file;
25
- if (req.method === 'GET' && (file = staticFiles[req.url])) {
26
- res.writeHead(200, {
27
- 'Content-Type': 'text/' + (/css$/.test(req.url) ? 'css' : (/js$/.test(req.url) ? 'javascript' : 'html'))
28
- });
29
- return res.end(file);
30
- }
31
- res.writeHead(404);
32
- res.end();
33
- }
 
34
 
35
- // Setup WebSocket connection
36
- io.on('connection', (socket) => {
37
- const conn = new SSHClient();
38
-
39
- // Debug logging
40
- conn.on('debug', (msg) => {
41
- console.log('DEBUG:', msg);
42
- });
43
-
44
- // On SSH connection ready
45
- conn.on('ready', () => {
46
- socket.emit('data', '\r\n*** SSH CONNECTION ESTABLISHED ***\r\n');
47
-
48
- // Start shell session
49
- conn.shell((err, stream) => {
50
- if (err) {
51
- return socket.emit('data', '\r\n*** SSH SHELL ERROR: ' + err.message + ' ***\r\n');
52
- }
53
-
54
- // When data is received from the client, write to the stream
55
- socket.on('data', (data) => {
56
- stream.write(data);
57
- });
58
-
59
- // Send data back to the client when received from the SSH session
60
- stream.on('data', (d) => {
61
- socket.emit('data', d.toString('binary'));
62
- }).on('close', () => {
63
- conn.end();
64
- });
65
- });
66
- })
67
- .on('close', () => {
68
- socket.emit('data', '\r\n*** SSH CONNECTION CLOSED ***\r\n');
69
- })
70
- .on('error', (err) => {
71
- console.error('SSH Connection Error:', err);
72
- socket.emit('data', '\r\n*** SSH CONNECTION ERROR: ' + err.message + ' ***\r\n');
73
- })
74
- .connect({
75
- host: process.env.REMOTE_HOST, // Use environment variable
76
- port: 22, // Default SSH port
77
- username: process.env.REMOTE_USERNAME, // Use environment variable
78
- password: process.env.REMOTE_PASSWORD, // Use environment variable (or use privateKey if required)
79
- readyTimeout: 60000, // Increase timeout to 60 seconds
80
- debug: (msg) => console.log('DEBUG:', msg) // Enable debug logging
81
- });
82
- });
83
 
84
- // Start the server
85
- const port = 8000;
86
- console.log('Listening on port', port);
87
- server.listen(port);
 
 
 
 
 
 
 
1
+ # Use Red Hat UBI minimal image
2
+ FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5-204
 
 
 
3
 
4
+ # Set working directory
5
+ WORKDIR /app
6
 
7
+ # Copy application files
8
+ COPY app/* /app/
9
 
10
+ # Switch to root user to install necessary packages
11
+ USER root
 
 
 
 
 
 
12
 
13
+ # Update and install dependencies
14
+ RUN microdnf update -y && \
15
+ rm -rf /var/cache/yum && \
16
+ microdnf install nodejs && \
17
+ microdnf install python3 && \
18
+ microdnf install make && \
19
+ microdnf install gcc && \
20
+ microdnf install gcc-c++ && \
21
+ microdnf install cmake && \
22
+ cd /app && \
23
+ rm -rf node_modules && \
24
+ npm install --unsafe-perm && \
25
+ chown -R 1001:0 /app
26
 
27
+ # Switch back to a non-root user for security
28
+ USER 1001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ # Expose the application port
31
+ EXPOSE 8000
32
+
33
+ # Define environment variables (optional, you can set them at runtime too)
34
+ ENV REMOTE_HOST=your.remote.host
35
+ ENV REMOTE_USERNAME=username
36
+ ENV REMOTE_PASSWORD=password
37
+
38
+ # Start the Node.js server
39
+ CMD [ "node", "server.js" ]