diff --git a/.woodpecker.yml b/.woodpecker.yml index 496c740..8ab13ce 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,5 +1,21 @@ pipeline: + build: + image: plugins/docker + volumes: + - /var/run/docker.sock:/var/run/docker.sock + settings: + registry: gitea.malloc.hackerbots.net + repo: gitea.malloc.hackerbots.net/tdfischer/hackerbots-live + daemon_off: true + #auto_tag: true + #tags: latest + username: + from_secret: GITEA_USERNAME + password: + from_secret: GITEA_PASSWORD deploy: + when: + branch: master image: alpine:3.13 volumes: - /var/web/live/:/deploy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..144ae9d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.9-alpine + +RUN pip install pipenv && pip install gunicorn==20.1.0 eventlet==0.30.2 + +WORKDIR /app +COPY . /app + +RUN pipenv install --system + +CMD ["gunicorn", "-k", "eventlet", "-w", "1", "-b", "0.0.0.0:5000", "app:app"] diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..2e617e6 --- /dev/null +++ b/Pipfile @@ -0,0 +1,15 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +flask = "*" +flask-json = "*" +requests = "*" +flask-socketio = "*" + +[requires] +python_version = "3.9" diff --git a/app.py b/app.py new file mode 100644 index 0000000..5f8e4c6 --- /dev/null +++ b/app.py @@ -0,0 +1,51 @@ +from flask import Flask, render_template +from flask_json import FlaskJSON, as_json +import requests +from flask_socketio import SocketIO + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'secret' +json = FlaskJSON(app) +socketio = SocketIO(app, logger=True, log_output=True) +socketio.init_app(app, cors_allowed_origins="*") + +CURRENT_LISTENERS = 0 + +def heartbeat(): + global CURRENT_LISTENERS + backendFetch = requests.get('http://hackerbots.net:8000/status-json.xsl') + stats = backendFetch.json()['icestats']['source'] + print(stats) + return { + 'title': stats.get('title', 'Unknown Track'), + 'listeners': CURRENT_LISTENERS, + 'show_title': 'Flask Test Show' + } + +@socketio.on('live.hello') +def on_hello(*args, **kwargs): + print("Hello!!!") + +@socketio.on('connect') +def on_new_listener(): + global CURRENT_LISTENERS + CURRENT_LISTENERS += 1 + socketio.emit('live.heartbeat', heartbeat()) + +@socketio.on('disconnect') +def on_new_listener(): + global CURRENT_LISTENERS + CURRENT_LISTENERS -= 1 + socketio.emit('live.heartbeat', heartbeat()) + +@app.route("/") +def index(): + return render_template('index.html') + +@app.route("/status.json") +@as_json +def status(): + return heartbeat() + +if __name__ == '__main__': + socketio.run(app, port=5000, host='0.0.0.0') diff --git a/index.html b/index.html deleted file mode 100644 index 6007f35..0000000 --- a/index.html +++ /dev/null @@ -1,208 +0,0 @@ - -
- - -