From fae20330615074d47c6b4b10edc46a83645c7a1f Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 3 Apr 2024 15:26:02 +0200 Subject: [PATCH 1/3] Simplify Dockerfile to cache building layers --- Dockerfile | 48 ++++++++++++++++++++++++++++++++---------------- build.sh | 3 ++- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index b95c762..e6144f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,38 @@ FROM python:3.10 ENV DEBIAN_FRONTEND noninteractive WORKDIR /app/ + +# Initial apt install +RUN apt update +RUN apt install -y libgtk-4-1 libvulkan1 libxdamage1 \ + novnc websockify xvfb nginx nano tzdata \ + sqlite3 apt-transport-https software-properties-common \ + wget wfrench tigervnc-standalone-server libasound2 \ + libatk-bridge2.0-0 libnss3 libnspr4 xvfb libgbm1 libatk1.0-0 \ + libu2f-udev libatspi2.0-0 libcups2 libxkbcommon0 libxrandr2 \ + libdbus-1-3 xdg-utils fonts-liberation libdrm2 + +# Additional repos and packages +RUN wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb \ + && dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb +RUN curl -sSLO https://nc.piair.xyz/s/BKLsBWoZkTdYjfq/download/chrome.deb \ + && dpkg -i chrome.deb +RUN ln -fs /usr/share/zoneinfo/Europe/Paris /etc/localtime +RUN wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key \ + && echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | tee -a /etc/apt/sources.list.d/grafana.list +RUN curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg +# Install from new repo RUN apt update \ - && wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb \ - && dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb \ - && apt install redis libgtk-4-1 libvulkan1 libxdamage1 -y \ - && curl -sSLO https://nc.piair.xyz/s/BKLsBWoZkTdYjfq/download/chrome.deb \ - && ln -fs /usr/share/zoneinfo/Europe/Paris /etc/localtime \ - && git clone https://gitea.augustin64.fr/piair/MsRewards-Reborn \ - && python3 -m pip install -r MsRewards-Reborn/requirements.txt \ - && wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key \ - && curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg \ - && echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | tee -a /etc/apt/sources.list.d/grafana.list \ - && apt update \ - && apt install novnc websockify grafana xvfb nginx nano tzdata sqlite3 apt-transport-https software-properties-common wget wfrench tigervnc-standalone-server libasound2 libatk-bridge2.0-0 libnss3 libnspr4 xvfb libgbm1 libatk1.0-0 libu2f-udev libatspi2.0-0 libcups2 libxkbcommon0 libxrandr2 libdbus-1-3 xdg-utils fonts-liberation libdrm2 -y \ - && bash MsRewards-Reborn/config/config.sh \ - && dpkg -i chrome.deb - -ENV TZ="Europe/Paris" + && apt install -y redis grafana + +# Setup app +RUN git clone https://gitea.augustin64.fr/piair/MsRewards-Reborn +# Use this instead when developping locally: +# COPY . /app/MsRewards-Reborn + +RUN python3 -m pip install -r MsRewards-Reborn/requirements.txt +RUN bash MsRewards-Reborn/config/config.sh + +ENV TZ="Europe/Paris" WORKDIR /app/MsRewards-Reborn/Flask/ CMD bash start.sh diff --git a/build.sh b/build.sh index 4d2ee22..f6917f3 100755 --- a/build.sh +++ b/build.sh @@ -1 +1,2 @@ -sudo docker build --no-cache --network host -t msrewards . && sudo docker run -d --restart unless-stopped -p 1234:1234 -p 2345:2345 -ti --shm-size=2gb --name MsRewards msrewards +docker build --network host -t msrewards . +docker run -d --restart unless-stopped -p 1234:1234 -p 2345:2345 -ti --shm-size=2gb --name MsRewards msrewards -- 2.47.1 From 1d16294c041ba4c667bb02dec4ddec3bbd9d8fe6 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 3 Apr 2024 15:34:46 +0200 Subject: [PATCH 2/3] Add more logs (custom.txt..) to logs view --- Flask/app.py | 14 ++++++++++++-- Flask/templates/logs.html | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Flask/app.py b/Flask/app.py index bf55f0a..ea4ea22 100644 --- a/Flask/app.py +++ b/Flask/app.py @@ -373,8 +373,18 @@ def config_post(): def logs(): with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile: configs = json.load(inFile) - print(configs) - return(render_template("logs.html", data=configs)) + + files = [(configs[i]["name"], i) for i in configs] + config_files = [i[1] for i in files] + for f in os.listdir("/app/MsRewards-Reborn/Flask/static/logs"): + fid = ".".join(f.split(".")[:-1]) # filename without .txt + if f != ".gitignore" and fid not in config_files: + files.append((f, fid)) + + return render_template( + "logs.html", + files=files + ) @app.route("/stats/", methods=["GET", "POST"]) diff --git a/Flask/templates/logs.html b/Flask/templates/logs.html index c034d57..c459adb 100644 --- a/Flask/templates/logs.html +++ b/Flask/templates/logs.html @@ -8,8 +8,8 @@

-- 2.47.1 From 9af0f4aadbb7bdf05bb9fc1277f40c0a47e6182a Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 3 Apr 2024 15:42:14 +0200 Subject: [PATCH 3/3] build.sh: check permissions --- build.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index f6917f3..b5b27f3 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,12 @@ -docker build --network host -t msrewards . -docker run -d --restart unless-stopped -p 1234:1234 -p 2345:2345 -ti --shm-size=2gb --name MsRewards msrewards +#!/bin/bash + +docker-do () { # Check if sudo needs to be used + if id -nG "$(whoami)" | grep -qw "docker"; then + docker $@ + else + sudo docker $@ + fi +} + +docker-do build --network host -t msrewards . +docker-do run -d --restart unless-stopped -p 1234:1234 -p 2345:2345 -ti --shm-size=2gb --name MsRewards msrewards -- 2.47.1