docs: updated for docker; feat: local and latest dockerfiles; add: .dockerignore file; feat: implemented health check for adrianux app
This commit is contained in:
parent
2b6885055b
commit
fa730cac1b
7 changed files with 87 additions and 16 deletions
6
.dockerignore
Normal file
6
.dockerignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
.forgejo
|
||||
compose.yml
|
||||
*.dockerfile
|
||||
.gitignore
|
||||
LICENSE
|
||||
README.md
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
.venv
|
||||
.env
|
||||
__pycache__
|
||||
|
|
32
README.md
32
README.md
|
@ -1,32 +1,50 @@
|
|||
# Installation
|
||||
|
||||
|
||||
## Setting up the environment
|
||||
|
||||
1. Create a virtual environment:
|
||||
```bash
|
||||
```sh
|
||||
python3 -m venv .venv
|
||||
```
|
||||
|
||||
2. Activate the virtual environment:
|
||||
```bash
|
||||
```sh
|
||||
. .venv/bin/activate
|
||||
```
|
||||
|
||||
3. Install dependencies:
|
||||
```bash
|
||||
```sh
|
||||
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
|
||||
|
||||
```
|
||||
# <runtime> build -t adrianux:<tag> .
|
||||
```sh
|
||||
docker build -t adrianux:latest - < latest.dockerfile
|
||||
```
|
||||
|
||||
|
||||
## Running the container
|
||||
|
||||
```sh
|
||||
docker run adrianux:latest
|
||||
```
|
||||
# <runtime> run adrianux:<tag>
|
||||
# Docker Compose
|
||||
|
||||
```sh
|
||||
docker compose up adrianux
|
||||
```
|
||||
|
|
32
app.py
32
app.py
|
@ -1,7 +1,10 @@
|
|||
#!/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__)
|
||||
|
||||
|
@ -19,17 +22,18 @@ def homepage():
|
|||
|
||||
@app.route("/monitoring")
|
||||
def monitoring():
|
||||
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) )
|
||||
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)
|
||||
|
||||
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 get_status_code(link):
|
||||
match status_code:
|
||||
case 200:
|
||||
return "ONLINE"
|
||||
case _:
|
||||
|
@ -37,6 +41,16 @@ 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__":
|
||||
mode = os.environ['DEBUG_MODE']
|
||||
app.run(debug=mode)
|
||||
app.run(debug=os.environ['DEBUG_MODE'])
|
||||
|
||||
|
||||
|
||||
|
|
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
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"
|
19
local.dockerfile
Normal file
19
local.dockerfile
Normal file
|
@ -0,0 +1,19 @@
|
|||
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" ]
|
Loading…
Add table
Reference in a new issue