summaryrefslogtreecommitdiff
path: root/whiskey
diff options
context:
space:
mode:
Diffstat (limited to 'whiskey')
-rw-r--r--whiskey/README.md16
-rw-r--r--whiskey/drink.py52
-rw-r--r--whiskey/files/bartender-nginx.conf29
-rw-r--r--whiskey/files/whiskey.service23
-rw-r--r--whiskey/logs/.gitignore3
-rw-r--r--whiskey/wsgi.py4
6 files changed, 127 insertions, 0 deletions
diff --git a/whiskey/README.md b/whiskey/README.md
new file mode 100644
index 0000000..73d3def
--- /dev/null
+++ b/whiskey/README.md
@@ -0,0 +1,16 @@
+# Bartender: a wsgi server.
+
+I wanted to do a simple git hook for a static website or two where the content was pulled down and converted from markdown with a little mermaid to static html. I have been doing this manually for a while but it gets to be a pain and besides all the kids are doing ci-cd and I thought it might help me actually write more.
+
+Once apon a time when apache was really the best way to serve http writing interactive sites in python was a matter of enableing mod_wsgi and throwing up 20 lines of python.
+
+Gone are those days.
+
+Three days of swimming through uwsgi, unit and 3 other overtly complicated half thought out python solutions all of which require a separate standalone service I settled on a flask and gunicorn. It's still a kludgy pile. Time to go queue TurboNegros "I hate the kids" and just make it work.
+
+This part of the digithink repo contains the wsgi app that is called whenever changes are pushed to digithink.com as well as the documentation and files needed to deploy it. The details and source code are found under [bartender/docs](bartender/docs/README.md).
+
+At some point I may make the bartender and the digithink.com separate repos. At that point I will probably serve more than whiskey/neat and start developing some of my other web sites.
+
+
+``` \ No newline at end of file
diff --git a/whiskey/drink.py b/whiskey/drink.py
new file mode 100644
index 0000000..4a0ae0d
--- /dev/null
+++ b/whiskey/drink.py
@@ -0,0 +1,52 @@
+# Bare Bones POC
+# Signature code stolen directly from Lukas Pühringer
+# https://gist.github.com/lukpueh/498ff3489321bdc7106c05a2fd5b941c
+# NOTE: Rquires payload to be set to json
+# https://blog.gitguardian.com/how-to-handle-secrets-in-python/
+from flask import Flask , request, abort
+from markupsafe import escape
+from dotenv import load_dotenv
+import hmac
+import hashlib
+import os
+import subprocess
+
+app = Flask(__name__)
+
+load_dotenv()
+
+GITHUB_SECRET = os.getenv("GITHUB_SECRET")
+
+@app.route("/whiskey/<style>",methods = ['POST', 'GET'])
+def whiskey(style):
+
+ # Extract signature header
+ signature = request.headers.get("X-Hub-Signature")
+ if not signature or not signature.startswith("sha1="):
+ abort(400, "X-Hub-Signature required")
+
+ # Create local hash of payload
+ digest = hmac.new(GITHUB_SECRET.encode(),
+ request.data, hashlib.sha1).hexdigest()
+
+ # Verify signature
+ if not hmac.compare_digest(signature, "sha1=" + digest):
+ #abort(400, signature+"<>sha1="+digest)
+ abort(400, "I am going to need to see some id.")
+
+ # After we have detemined that this is legit.
+ match style:
+ case "neat":
+ subprocess.call(['at', 'now', '-f', '/var/www/digithink/repo/makesite.sh'])
+ case "sour":
+ subprocess.call(['at', 'now', '-f', '/var/www/3dangst/repo/makesite.sh'])
+ case _: abort(404,"We Don't Serve That Here!")
+
+ return f"One Whiskey, {escape(style)}!"
+
+@app.route("/")
+def root():
+ return f"Not much here...."
+
+if __name__ == "__main__":
+ app.run(host='0.0.0.0')
diff --git a/whiskey/files/bartender-nginx.conf b/whiskey/files/bartender-nginx.conf
new file mode 100644
index 0000000..b0eebaa
--- /dev/null
+++ b/whiskey/files/bartender-nginx.conf
@@ -0,0 +1,29 @@
+# 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/digithink/whiskey/bartender;
+ index index.html;
+ location /whiskey {
+ include proxy_params;
+ proxy_pass http://bartender/whiskey;
+ }
+}
+
+server {
+ root /var/www/digithink/whiskey/bartender;
+ index index.html;
+ 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
+}
+
diff --git a/whiskey/files/whiskey.service b/whiskey/files/whiskey.service
new file mode 100644
index 0000000..d7e968e
--- /dev/null
+++ b/whiskey/files/whiskey.service
@@ -0,0 +1,23 @@
+[Unit]
+Description=Gunicorn instance to serve whiskey
+After=network.target
+
+[Service]
+User=www-data
+Group=www-data
+WorkingDirectory=/var/www/digithink/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/digithink/whiskey/logs/gunicorn_access.log \
+ --error-logfile /var/www/digithink/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
diff --git a/whiskey/logs/.gitignore b/whiskey/logs/.gitignore
new file mode 100644
index 0000000..e7a210e
--- /dev/null
+++ b/whiskey/logs/.gitignore
@@ -0,0 +1,3 @@
+*
+*/
+!.gitignore \ No newline at end of file
diff --git a/whiskey/wsgi.py b/whiskey/wsgi.py
new file mode 100644
index 0000000..f9c8563
--- /dev/null
+++ b/whiskey/wsgi.py
@@ -0,0 +1,4 @@
+from drink import app
+
+if __name__ == "__main__":
+ app.run() \ No newline at end of file