Skip to content

Bartender is a server of wsgi for building sites in response to a webhook

Notifications You must be signed in to change notification settings

suspect-devices/bartender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bartender: a wsgi server

This impliments a wsgi server that is called by a github webhook. When called it validates the request, schedules an at job, and returns a status. The at job pulls the "docs" off of github, builds the site, and moves it into place.

The Stack

graph LR
    B -- http(s)://127.0.0.1:8000 <--> C[nginx] -- http(s)://bartender/whisky/STYLE <--> I([Internet])
    A[flask] -- wsgi <--> B[gunicorn];
Loading

The implimentation

graph LR 
   A[bartender app] --> C[AT]
   A -- 200 ok / 400 bad id / 404  --> N[NGinX]
   N <-- bartender.digithink.com --> I([Internet])
   G[(github)] -- pull --> D
   C --> D[makesite.sh]
   D -- mkdocks build --> O[(site)] -->N
   N -- whiskey/STYLE --> A
Loading

The source code and the results

Installing the service

apt install nginx
apt install certbot python3-certbot-nginx
apt install python3-flask
apt install python3-gunicorn
apt install at

echo www-data |tee /etc/at.allow
nano /etc/systemd/system/whiskey.service
[Unit]
Description=Gunicorn instance to serve whiskey
After=network.target

[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/bartender/repo/whiskey
#Environment="PATH=/home/sammy/myproject/myprojectenv/bin"
#     --bind unix:/run/whiskey.sock  \

ExecStart=/usr/bin/gunicorn \
     --workers 3 \
     --bind 127.0.0.1:5000 \
     --reload \
     --access-logfile /var/www/bartender/repo/whiskey/logs/gunicorn_access.log \
     --error-logfile /var/www/bartender/repo/whiskey/logs/gunicorn_error.log \
     -m 007 wsgi:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
^X
systemctl enable whiskey
systemctl start whiskey

nginx.conf

# lots of hard coded foo here
server {
    server_name bartender.digithink.com;

    listen 198.202.31.232:443 ssl;
    server_name bartender.digithink.com;
    ssl_certificate /etc/letsencrypt/live/bartender.digithink.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/bartender.digithink.com/privkey.pem; # managed by Certbot

    root /var/www/bartender/site;
    index index.html;
    location /whiskey {
        include proxy_params;
        proxy_pass http://bartender/whiskey;
    }

    error_page 404 /404.html;
    location  /404.html {
          internal;
    #     root  /var/www/digithink/site;
    }
    location /lacuenta { # FIX THIS
        root /var/www/bartender/whiskey/logs;
    }
}

server {
    if ($host = bartender.digithink.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 198.202.31.232:80;
    server_name bartender.digithink.com;
    return 404; # managed by Certbot
}

the WSGI app

The actual app will grow into something with better feedback more general use (ie to make different static web sites)

drink.py

Minimum Viable Product

from flask import Flask
from markupsafe import escape
import subprocess

app = Flask(__name__)

@app.route("/whiskey/<style>",methods = ['POST'])
def whiskey(style):
    # break this out by style.
    subprocess.call(['at', 'now', '-f', '/var/www/digithink/repo/makesite.sh'])
    return f"One Whiskey, {escape(style)}!"

The actual drink.py is slightly more developed.

wsgi.py, Turning the above into a WSGI app

from drink import app

if __name__ == "__main__":
    app.run()

Converting the git content to a static html site.

mkdocs plus the extensions

Ubuntu (... ok, debian really...) fracked up the packaging for mkdocs and mkdocs-material. I wound up removing the packages and pip3 installing most of it with --break-system-packages.

apt remove mkdocs*
apt remove markdown
apt remove python3-markdown
apt install python3-regex
apt install libvips-dev
apt install python3-pip
pip3 install mkdocs-material --break-system-packages
pip3 install mkdocs-with-pdf -U git+https://github.com/domWalters/[email protected] --break-system-packages

pull dependencies based on the current mkdocs install and mkdocs.yml

cd /var/www/digithink/&& git pull 
mkdocs-get-deps > requirements.txt
pip3 install $(mkdocs-get-deps) --break-system-packages
mkdocs build && chown -R www-data:www-data site/

linkdump

About

Bartender is a server of wsgi for building sites in response to a webhook

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published