From ee14c3fd7e7ebbc3dc2b8e908e063215d772e16c Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sun, 21 Jul 2024 23:49:12 +0200 Subject: [PATCH] feat: add build & update to latest python --- .github/workflows/main.yaml | 32 ++++++++++++++++++++++++++++ Dockerfile | 13 ++++++++++++ app.py | 2 ++ server.py | 42 +++++++++++++++++++++---------------- 4 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/main.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..348763c --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,32 @@ +name: Container Build for open-web-leaderboard + +on: + push: + branches: + - "master" + +jobs: + docker: + runs-on: ubuntu-latest + environment: + name: prod + steps: + - uses: actions/checkout@v3 + - + name: Checkout + uses: actions/checkout@v3 + - + name: Login to Docker Registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.REGISTRY }} + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASS }} + - + name: open-web-leaderboard + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: true + tags: "${{ secrets.REGISTRY }}/atlantishq/open-web-leaderboard:latest" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f228eee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine + +RUN apk add --no-cache py3-pip +RUN python3 -m pip install --no-cache-dir --break-system-packages waitress +COPY req.txt . +RUN python3 -m pip install --no-cache-dir --break-system-packages -r req.txt + +RUN mkdir /app +WORKDIR /app +COPY ./ . + +ENTRYPOINT ["waitress-serve"] +CMD ["--host", "0.0.0.0", "--port", "5000", "--call", "app:createApp"] diff --git a/app.py b/app.py index 6a108a0..a6fa46e 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ import server def createApp(envivorment=None, start_response=None): + with server.app.app_context(): + server.create_app() return server.app diff --git a/server.py b/server.py index 39245cb..dae5cc4 100755 --- a/server.py +++ b/server.py @@ -10,8 +10,8 @@ import MapSummary from database import DatabaseConnection -import valve.source.a2s -from valve.source import NoResponseError +#import valve.source.a2s +#from valve.source import NoResponseError app = flask.Flask("open-leaderboard") @@ -42,8 +42,9 @@ def playersOnline(): for s in SERVERS: try: - with valve.source.a2s.ServerQuerier((s["host"], s["port"])) as server: - playerTotal += int(server.info()["player_count"]) + pass + #with valve.source.a2s.ServerQuerier((s["host"], s["port"])) as server: + # playerTotal += int(server.info()["player_count"]) except NoResponseError: error = "Server Unreachable" except Exception as e: @@ -276,11 +277,11 @@ def leaderboard(): if maxEntry <= 100: start = max(start, 0) - finalResponse = flask.render_template("base.html", playerList=playerList, \ - doNotComputeRank=doNotComputeRank, \ - start=start, \ - endOfBoardIndicator=endOfBoardIndicator, \ - findPlayer=cannotFindPlayer, \ + finalResponse = flask.render_template("base.html", playerList=playerList, + doNotComputeRank=doNotComputeRank, + start=start, + endOfBoardIndicator=endOfBoardIndicator, + findPlayer=cannotFindPlayer, searchName=searchName, nextPageNumber=int(pageInt)+1, prevPageNumber=int(pageInt)-1) @@ -288,12 +289,14 @@ def leaderboard(): @app.route('/static/') def send_js(path): + response = send_from_directory('static', path) response.headers['Cache-Control'] = "max-age=2592000" return response -@app.before_first_request -def init(): + +def create_app(): + global SERVERS SERVERS_FILE = "servers.json" @@ -302,16 +305,19 @@ def init(): SERVERS = json.load(f) if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Start open-leaderboard', \ - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('--interface', default="localhost", \ + + parser = argparse.ArgumentParser(description='Start open-leaderboard', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('--interface', default="localhost", help='Interface on which flask (this server) will take requests on') - parser.add_argument('--port', default="5002", \ + parser.add_argument('--port', default="5002", help='Port on which flask (this server) will take requests on') + parser.add_argument('--skillbird-db', required=True, + help='skillbird database (overrides web connection if set)') + + with app.app_context(): + create_app() - parser.add_argument('--skillbird-db', required=True, help='skillbird database (overrides web connection if set)') - - args = parser.parse_args() app.config["DB_PATH"] = args.skillbird_db app.run(host=args.interface, port=args.port)