Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
a2b99b2976 | |||
9f8f0c94ff | |||
b83a60f822 | |||
709b0fbe21 |
4 changed files with 73 additions and 51 deletions
|
@ -5,12 +5,10 @@ ENV GIT_URL=https://git.adrianux.net
|
||||||
ENV WEBSITE_URL=https://adrianux.net
|
ENV WEBSITE_URL=https://adrianux.net
|
||||||
ENV DEBUG_MODE=False
|
ENV DEBUG_MODE=False
|
||||||
|
|
||||||
RUN apk add --no-cache git python3
|
RUN apk add go
|
||||||
RUN git clone https://git.adrianux.net/ahoemann/Adrianux.net.git /opt
|
COPY . .
|
||||||
RUN python3 -m venv /opt/.venv
|
RUN chmod +x website
|
||||||
RUN /opt/.venv/bin/pip install --no-cache-dir -r requirements.txt
|
|
||||||
RUN apk del git
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD [ "/opt/.venv/bin/waitress-serve", "--listen=0.0.0.0:8080", "app:app" ]
|
CMD [ "/opt/./website" ]
|
42
app.py
42
app.py
|
@ -1,42 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
from flask import Flask, render_template, redirect, url_for
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
@app.route("/imprint")
|
|
||||||
def root():
|
|
||||||
return render_template("imprint.html")
|
|
||||||
|
|
||||||
@app.route("/about")
|
|
||||||
def about():
|
|
||||||
return render_template("about.html")
|
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def homepage():
|
|
||||||
return render_template("homepage.html")
|
|
||||||
|
|
||||||
@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) )
|
|
||||||
|
|
||||||
def get_status_code(link):
|
|
||||||
requested_site = requests.get(link)
|
|
||||||
return requested_site.status_code
|
|
||||||
|
|
||||||
def get_status(link):
|
|
||||||
try:
|
|
||||||
match get_status_code(link):
|
|
||||||
case 200:
|
|
||||||
return "ONLINE"
|
|
||||||
case _:
|
|
||||||
return "ERROR"
|
|
||||||
except:
|
|
||||||
return "OFFLINE"
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
mode = os.environ['DEBUG_MODE']
|
|
||||||
app.run(debug=mode)
|
|
|
@ -1,3 +0,0 @@
|
||||||
flask
|
|
||||||
waitress
|
|
||||||
requests
|
|
69
website.go
Executable file
69
website.go
Executable file
|
@ -0,0 +1,69 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var templates = template.Must(template.ParseGlob("*.html"))
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
mode := os.Getenv("DEBUG_MODE")
|
||||||
|
if mode == "true" {
|
||||||
|
log.Println("Debug mode is on")
|
||||||
|
}
|
||||||
|
http.HandleFunc("/imprint", imprint)
|
||||||
|
http.HandleFunc("/about", about)
|
||||||
|
http.HandleFunc("/", homepage)
|
||||||
|
http.HandleFunc("/monitoring", monitoring)
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func imprint(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renderTemplate(w, "imprint.html")
|
||||||
|
}
|
||||||
|
|
||||||
|
func about(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renderTemplate(w, "about.html")
|
||||||
|
}
|
||||||
|
|
||||||
|
func homepage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renderTemplate(w, "homepage.html")
|
||||||
|
}
|
||||||
|
|
||||||
|
func monitoring(w http.ResponseWriter, r *http.Request) {
|
||||||
|
gitURL := os.Getenv("GIT_URL")
|
||||||
|
websiteURL := os.Getenv("WEBSITE_URL")
|
||||||
|
gitStatus := getStatus(gitURL)
|
||||||
|
websiteStatus := getStatus(websiteURL)
|
||||||
|
data := struct {
|
||||||
|
GitStatus string
|
||||||
|
WebsiteStatus string
|
||||||
|
}{
|
||||||
|
GitStatus: gitStatus,
|
||||||
|
WebsiteStatus: websiteStatus,
|
||||||
|
}
|
||||||
|
renderTemplate(w, "monitoring.html", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderTemplate(w http.ResponseWriter, tmpl string, data ...interface{}) {
|
||||||
|
err := templates.ExecuteTemplate(w, tmpl, data)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStatus(link string) string {
|
||||||
|
resp, err := http.Get(link)
|
||||||
|
if err != nil {
|
||||||
|
return "OFFLINE"
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return "ONLINE"
|
||||||
|
}
|
||||||
|
return "ERROR"
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue