From a6aae99ed0ce4966a50bc04804cf2fc467d101ec Mon Sep 17 00:00:00 2001 From: ahoemann Date: Fri, 17 Jan 2025 08:29:25 +0100 Subject: [PATCH 1/2] feat: set urls via environment variables; removed: configuration parser --- Containerfile | 5 ++++- adrianux.toml | 5 ----- app.py | 14 ++++---------- 3 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 adrianux.toml diff --git a/Containerfile b/Containerfile index f44420d..b5b19a6 100644 --- a/Containerfile +++ b/Containerfile @@ -1,6 +1,9 @@ FROM alpine:latest WORKDIR /opt/ +ENV git_url=https://git.adrianux.net +ENV website_url=https://adrianux.net +ENV debug_mode=False RUN apk add --no-cache git python3 RUN git clone https://git.adrianux.net/ahoemann/Adrianux.net.git /opt RUN python3 -m venv /opt/.venv @@ -9,4 +12,4 @@ RUN apk del git EXPOSE 8080 -CMD [ "/opt/.venv/bin/waitress-serve", "--listen=0.0.0.0:8080", "app:app" ] \ No newline at end of file +CMD [ "/opt/.venv/bin/waitress-serve", "--listen=0.0.0.0:8080", "app:app" ] diff --git a/adrianux.toml b/adrianux.toml deleted file mode 100644 index 0dc3ed8..0000000 --- a/adrianux.toml +++ /dev/null @@ -1,5 +0,0 @@ -[site] -git_url=https://git.adrianux.net -website_url=https://adrianux.net -[mode] -debug_mode=False diff --git a/app.py b/app.py index 10e479d..29999af 100755 --- a/app.py +++ b/app.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 from flask import Flask, render_template, redirect, url_for import requests -import configparser - +import os app = Flask(__name__) @@ -20,8 +19,8 @@ def homepage(): @app.route("/monitoring") def monitoring(): - git_url = parser("site", "git_url") - website_url = parser("site", "website_url") + git_url = os.environ['GIT_URL'] + website_url = os.environ['WEBSITE_URL'] return render_template("monitoring.html", git_status = get_status(git_url), website_status = get_status(website_url) ) def get_status_code(link): @@ -38,11 +37,6 @@ def get_status(link): except: return "OFFLINE" -def parser(section, attribute): - config = configparser.RawConfigParser() - config.read("./adrianux.toml") - return config.get(section, attribute) - if __name__ == "__main__": - mode = parser("mode","debug_mode") + mode = os.environ['DEBUG_MODE'] app.run(debug=mode) -- 2.39.5 From 4f73502d004c0f56514cab2567fed084d588caac Mon Sep 17 00:00:00 2001 From: ahoemann Date: Fri, 17 Jan 2025 08:35:14 +0100 Subject: [PATCH 2/2] fix: set default environment variables names --- Containerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Containerfile b/Containerfile index b5b19a6..4ac1b83 100644 --- a/Containerfile +++ b/Containerfile @@ -1,9 +1,10 @@ FROM alpine:latest WORKDIR /opt/ -ENV git_url=https://git.adrianux.net -ENV website_url=https://adrianux.net -ENV debug_mode=False +ENV GIT_URL=https://git.adrianux.net +ENV WEBSITE_URL=https://adrianux.net +ENV DEBUG_MODE=False + RUN apk add --no-cache git python3 RUN git clone https://git.adrianux.net/ahoemann/Adrianux.net.git /opt RUN python3 -m venv /opt/.venv -- 2.39.5