Slightly better build process. Socket.io can now add CORS allowed origin

This commit is contained in:
Martin Asprusten 2025-04-20 17:28:43 +02:00
parent da99a1bdd5
commit 5d6138bdc2
2 changed files with 10 additions and 8 deletions

View File

@ -3,21 +3,21 @@ FROM python:3.13-slim-bookworm AS build
WORKDIR /santa
RUN mkdir -p /santa/WebServer/static
COPY setup-server.sh /santa/setup-server.sh
RUN apt-get update && apt-get install -y curl
RUN apt-get update && apt-get install -y curl bzip2
RUN /santa/setup-server.sh --download-only
COPY requirements.txt /santa/requirements.txt
COPY src/setup.py /santa/src/setup.py
COPY src/SantaExchange/ /santa/src/SantaExchange/
COPY WebServer/__init__.py WebServer/server.py /santa/WebServer/
COPY WebServer/templates/ /santa/WebServer/templates/
COPY WebServer/static/exchange_client.py WebServer/static/exchange_worker.js WebServer/static/style.css /santa/WebServer/static/
RUN pip install -r /santa/requirements.txt
RUN /santa/setup-server.sh
FROM python:3.13-slim-bookworm
RUN pip install flask flask-socketio gunicorn eventlet
COPY --from=build /santa/WebServer /WebServer
COPY WebServer/__init__.py WebServer/server.py /WebServer/
COPY WebServer/templates/ /WebServer/templates/
COPY WebServer/static/exchange_client.py WebServer/static/exchange_worker.js WebServer/static/style.css /WebServer/static/
WORKDIR /WebServer
EXPOSE 8000
CMD ["gunicorn", "--worker-class", "eventlet", "-w", "4", "--bind", "0.0.0.0:8000", "server:app"]
CMD ["gunicorn", "--worker-class", "eventlet", "-w", "1", "--bind", "0.0.0.0:8000", "server:app"]

View File

@ -1,11 +1,13 @@
import json
from collections import defaultdict
import os
from flask import Flask, render_template
from flask_socketio import SocketIO, join_room, leave_room, send
app = Flask(__name__)
socketio = SocketIO(app)
if 'CORS_ORIGIN' in os.environ and os.environ['CORS_ORIGIN'] is not None:
socketio = SocketIO(app, cors_allowed_origins=[os.environ['CORS_ORIGIN']])
else:
socketio = SocketIO(app)
if __name__ == 'main':
socketio.run(app)