# 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 ```mermaid graph LR B -- http(s)://127.0.0.1:8000 <--> C[nginx] -- http(s)://bartender/whisky/STYLE <--> I([Internet]) A[flask] -- wsgi <--> B[gunicorn]; ``` The implimentation ```mermaid 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 ``` ## The source code and the results - [https://github.com/suspect-devices/bartender](https://github.com/suspect-devices/bartender) The source code for the bartender service serves the it's documentation as well as several other sites. - [https://www.digithink.com](https://www.digithink.com) is the one of the target websites. - [https://www.3dangst.com](https://www.3dangst.com) is another one of the target website. - [https://bartender.digithink.com/](https://bartender.digithink.com/) contains this and the other documents for the service. ### Installing the service ```sh 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 ```sh # 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 ```python from flask import Flask from markupsafe import escape import subprocess app = Flask(__name__) @app.route("/whiskey/