TechDev commited on
Commit
8589307
·
verified ·
1 Parent(s): 13a6f26

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +6 -25
  2. app.py +24 -13
  3. requirements.txt +3 -4
Dockerfile CHANGED
@@ -1,31 +1,12 @@
1
- FROM ubuntu
2
-
3
- RUN apt-get update && \
4
- apt-get install -y sudo && \
5
- apt-get clean
6
- RUN apt-get update && apt-get install -y python3 python3-pip python3.12-venv
7
- RUN apt-get update && apt-get install -y \
8
- curl \
9
- ca-certificates \
10
- megatools \
11
- gnupg && \
12
- curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
13
- RUN rm -rf /var/lib/apt/lists/*
14
-
15
- # Añadir un usuario llamado 'appuser'
16
- RUN useradd -ms /bin/bash appuser
17
- RUN usermod -aG sudo appuser
18
- RUN echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
19
-
20
- USER appuser
21
 
22
  WORKDIR /app
23
 
24
- COPY . /app
 
25
 
26
- RUN sudo chmod -R 777 /app
27
 
28
- RUN python3 -m venv venv
29
- RUN /bin/bash -c "source venv/bin/activate && pip3 install -r requirements.txt"
30
 
31
- CMD [ "venv/bin/python","app.py"]
 
1
+ FROM python:3.9-slim
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  WORKDIR /app
4
 
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
 
8
+ COPY . .
9
 
10
+ EXPOSE 7860
 
11
 
12
+ CMD ["gunicorn", "--worker-class", "eventlet", "-w", "1", "-b", "0.0.0.0:7860", "app:app"]
app.py CHANGED
@@ -1,21 +1,32 @@
1
  from flask import Flask, render_template
2
- from flask_socketio import SocketIO, send
3
- from flask_sock import Sock
4
 
5
  app = Flask(__name__)
6
- socketio = SocketIO(app)
7
- sock = Sock(app)
8
 
9
- # Ruta principal
10
- @app.route('/')
11
- def index():
12
- return "INICIADO"
 
 
 
 
13
 
14
- # Manejo de mensajes WebSocket
15
  @socketio.on('message')
16
- def handle_message(msg):
17
- print(f"Mensaje recibido: {msg}")
18
- send(msg, broadcast=True) # Reenvía el mensaje a todos los clientes conectados
 
 
 
 
 
 
 
 
 
19
 
20
  if __name__ == '__main__':
21
- socketio.run(app, host='0.0.0.0', port=7680, debug=True)
 
1
  from flask import Flask, render_template
2
+ from flask_socketio import SocketIO, send, emit
 
3
 
4
  app = Flask(__name__)
5
+ app.config['SECRET_KEY'] = 'secret!'
6
+ socketio = SocketIO(app, cors_allowed_origins="*")
7
 
8
+ @socketio.on('connect')
9
+ def handle_connect():
10
+ print('Client connected')
11
+ emit('response', {'data': 'Connected'})
12
+
13
+ @socketio.on('disconnect')
14
+ def handle_disconnect():
15
+ print('Client disconnected')
16
 
 
17
  @socketio.on('message')
18
+ def handle_message(message):
19
+ print('Received message:', message)
20
+ send('Message received: ' + message)
21
+
22
+ @socketio.on('custom_event')
23
+ def handle_custom_event(json):
24
+ print('Received custom event:', json)
25
+ emit('response', {'data': 'Custom event received'})
26
+
27
+ @app.route('/')
28
+ def index():
29
+ return render_template('index.html') # Basic HTML template for testing
30
 
31
  if __name__ == '__main__':
32
+ socketio.run(app, host='0.0.0.0', port=7860)
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- Flask
2
- Flask-SocketIO
3
- eventlet
4
- flask-sock
 
1
+ flask-socketio>=5.3.4
2
+ eventlet>=0.33.3
3
+ gunicorn>=20.1.0