diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ade01cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.forgejo +*compose.yml +Dockerfile +.git* +Jenkinsfile +LICENSE +README.md diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..68a5b06 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +DEBUG_MODE=False diff --git a/.forgejo/workflows/update.yaml b/.forgejo/workflows/update.yaml deleted file mode 100644 index 981d93d..0000000 --- a/.forgejo/workflows/update.yaml +++ /dev/null @@ -1,7 +0,0 @@ -on: [push] -jobs: - update: - runs-on: self-hosted - steps: - - run: sudo git -C /opt/Adrianux.net/ pull - - run: sudo systemctl restart adrianux \ No newline at end of file diff --git a/.gitignore b/.gitignore index 033df5f..03741ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -.venv +.venv* +.env __pycache__ +*theia-workspace \ No newline at end of file diff --git a/Containerfile b/Containerfile deleted file mode 100644 index 6060264..0000000 --- a/Containerfile +++ /dev/null @@ -1,14 +0,0 @@ -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 go -COPY . . -RUN chmod +x website - -EXPOSE 8080 - -CMD [ "/opt/./website" ] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..951996a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine:latest +WORKDIR /opt/ + +ENV DEBUG_MODE=False + +COPY . . + +RUN apk add --no-cache python3 py3-flask py3-waitress + +EXPOSE 8080 + +HEALTHCHECK --interval=5m CMD wget --delete-after http://localhost:8080 + +CMD [ "waitress-serve", "--listen=0.0.0.0:8080", "app:app" ] diff --git a/README.md b/README.md index 37b9af4..7cf7903 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,62 @@ # 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 DEBUGMODE=False +``` + +Or source the .env file: + +```sh +cp .env.example .env # change the variables to suit your environment as needed +``` + +```sh +. .env +``` + +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 . ``` -# build -t adrianux: . -``` - ## Running the container +```sh +docker run adrianux:latest ``` -# run adrianux: +# Docker Compose + +```sh +docker compose up adrianux ``` diff --git a/app.py b/app.py new file mode 100755 index 0000000..aa9dfa6 --- /dev/null +++ b/app.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +from flask import Flask, render_template, url_for +import os + + +app = Flask(__name__) + +@app.route("/imprint") +def root(): + return render_template("imprint.j2") + +@app.route("/about") +def about(): + return render_template("about.j2") + +@app.route("/") +def homepage(): + return render_template("homepage.j2") + + +if __name__ == "__main__": + app.run(debug=os.environ['DEBUG_MODE']) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7107bd6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +--- +services: + container_name: "adrianux" + image: "git.adrianux.net/ahoemann/adrianux.net:1.2.0" + env_file: .env + ports: + - "127.0.0.1:8080:8080" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..398b875 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask +waitress +requests \ No newline at end of file diff --git a/templates/about.html b/templates/about.j2 similarity index 93% rename from templates/about.html rename to templates/about.j2 index 6184755..16e4c30 100644 --- a/templates/about.html +++ b/templates/about.j2 @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "base.j2" %} {% block title %}About{% endblock %} {% block head %} {{ super() }} @@ -10,7 +10,7 @@

Languages: German, English

Programming languages: Python, Bash, POSIX Shell, Powershell

Markup languages: HTML, MD

-

Structure languages: JSON, XML, YAML, TOML

+

Structure languages: JSON, XML, YAML, TOML, Jinja2

Query languages: SQL(MariaDB, SQLite3)

Services managed: SSH, DNS, DHCP, AD, PF, UFW, NF-Tables, RDP(XRDP, Microsoft RDP), Webserver(Apache24, Nginx, OpenBSD-httpd, diff --git a/templates/base.html b/templates/base.j2 similarity index 80% rename from templates/base.html rename to templates/base.j2 index c0305b6..e3f8a47 100644 --- a/templates/base.html +++ b/templates/base.j2 @@ -1,5 +1,5 @@ - + {% block head %} @@ -14,8 +14,9 @@

  • Homepage
  • Imprint
  • About
  • -
  • Monitoring
  • -
  • Git
  • +
  • Monitoring
  • +
  • Git
  • +
  • Bin
  • diff --git a/templates/homepage.html b/templates/homepage.j2 similarity index 74% rename from templates/homepage.html rename to templates/homepage.j2 index 72ce93c..c40b0eb 100644 --- a/templates/homepage.html +++ b/templates/homepage.j2 @@ -1,9 +1,9 @@ -{% extends "base.html" %} +{% extends "base.j2" %} {% block title %}Homepage{% endblock %} {% block head %} {{ super() }} {% endblock %} {% block content %} -

    This is Adrian's homepage, checkout his running services and their state here

    +

    This is Adrian's homepage, checkout his running services and their state here

    Yes, Adrian is refering to himself in the third person.

    {% endblock %} diff --git a/templates/imprint.html b/templates/imprint.j2 similarity index 91% rename from templates/imprint.html rename to templates/imprint.j2 index 59c6e38..011a5f2 100644 --- a/templates/imprint.html +++ b/templates/imprint.j2 @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "base.j2" %} {% block title %}Imprint{% endblock %} {% block head %} {{ super() }} diff --git a/templates/monitoring.html b/templates/monitoring.html deleted file mode 100644 index c41ec0b..0000000 --- a/templates/monitoring.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends "base.html" %} -{% block title %}Monitoring{% endblock %} -{% block head %} - {{ super() }} -{% endblock %} -{% block content %} -

    Git status: {{ git_status }}

    -

    Website status: {{ website_status }}

    -{% endblock %} diff --git a/website.go b/website.go deleted file mode 100755 index 2520cfc..0000000 --- a/website.go +++ /dev/null @@ -1,69 +0,0 @@ -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" -} -