Compare commits

..

No commits in common. "c9d61cd9fb74544e35df88b6ed82456961f7b2e5" and "2b6885055b7a59033214138c569f89d7c3a9427b" have entirely different histories.

7 changed files with 16 additions and 89 deletions

View file

@ -1,6 +0,0 @@
.forgejo
compose.yml
*.dockerfile
.gitignore
LICENSE
README.md

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
.venv
.env
__pycache__

View file

@ -13,6 +13,4 @@ RUN apk del git
EXPOSE 8080
HEALTHCHECK --interval=5m CMD wget --delete-after http://localhost:8080
CMD [ "/opt/.venv/bin/waitress-serve", "--listen=0.0.0.0:8080", "app:app" ]

View file

@ -1,50 +1,32 @@
# Installation
## Setting up the environment
1. Create a virtual environment:
```sh
```bash
python3 -m venv .venv
```
2. Activate the virtual environment:
```sh
```bash
. .venv/bin/activate
```
3. Install dependencies:
```sh
```bash
pip install requirements.txt
```
4. Set the environment variables:
```sh
export GIT_URL=http://git.adrianux.net
export WEBSITE_URL=http://adrianux.net
export DEBUGMODE=False
```
5. Run the app:
```sh
waitress-serve --listen=0.0.0.0:8080 app:app
```
# Docker
## Building the container
```sh
docker build -t adrianux:latest - < latest.dockerfile
```
# <runtime> build -t adrianux:<tag> .
```
## Running the container
```sh
docker run adrianux:latest
```
# Docker Compose
```sh
docker compose up adrianux
# <runtime> run adrianux:<tag>
```

32
app.py
View file

@ -1,10 +1,7 @@
#!/usr/bin/env python3
from flask import Flask, render_template, redirect, url_for
from concurrent.futures import ThreadPoolExecutor
import requests
import os
import time
app = Flask(__name__)
@ -22,18 +19,17 @@ def homepage():
@app.route("/monitoring")
def monitoring():
global git_status
global website_status
executor = ThreadPoolExecutor(2)
executor.submit(monitor)
return render_template("monitoring.html", git_status = git_status, website_status = website_status)
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):
requested_site = requests.get(link)
return requested_site.status_code
def get_status(link):
requested_site = requests.get(link)
status_code = requested_site.status_code
try:
match status_code:
match get_status_code(link):
case 200:
return "ONLINE"
case _:
@ -41,16 +37,6 @@ def get_status(link):
except:
return "OFFLINE"
def monitor():
while True:
git_status = get_status(os.environ['GIT_URL'])
website_status = get_status(os.environ['WEBSITE_URL'])
time.sleep(5)
if __name__ == "__main__":
app.run(debug=os.environ['DEBUG_MODE'])
mode = os.environ['DEBUG_MODE']
app.run(debug=mode)

View file

@ -1,13 +0,0 @@
---
services:
build:
context: "."
dockerfile: "latest.dockerfile"
container_name: "adrianux"
image: "adrianux:latest"
environment:
- "GIT_URL=http://git.adrianux.net"
- "WEBSITE_URL=http://adrianux.net"
- "DEBUG_MODE=False"
ports:
- "127.0.0.1:8080:8080"

View file

@ -1,19 +0,0 @@
FROM alpine:latest
WORKDIR /opt/
ENV GIT_URL=https://git.adrianux.net
ENV WEBSITE_URL=https://adrianux.net
ENV DEBUG_MODE=False
COPY . .
RUN apk add --no-cache git python3
RUN python3 -m venv /opt/.venv
RUN /opt/.venv/bin/pip install --no-cache-dir -r requirements.txt
RUN apk del git
EXPOSE 8080
HEALTHCHECK --interval=5m CMD wget --delete-after http://localhost:8080
CMD [ "/opt/.venv/bin/waitress-serve", "--listen=0.0.0.0:8080", "app:app" ]