Table of Contents
DevOps
For a while, I’ve been wanting to add basic DevOps to my programming selfstudy. My main Python project, a security-focused Flask web app, has been developed so far by:
- adding features, checking for errors (manually, no testing yet)
- turning the code into a wheel
- running that wheel in a virtual environment with Gunicorn on sec.joostagterhoek.nl.
Currently that site is offline, because every time something was wrong or I had to restart anything, there was no automatic process for (re)deploying the app. So I thought, why not turn this into a learning opportunity? I could self-host a development operations pipeline, put the Flask app in a Docker container and make it all work automagically.
First things first
So, where’s that pipeline? Well, to make things somewhat easier, first I took this Zola-powered blog site and applied some CI/CD to it. As you may or may not know, Zola is a (Rust-based 🦀) static site generator working off of Markdown files, HTML templates, CSS, JS and the Tera templating engine (read its docs. In the context of my self-hosting platform of choice, YunoHost, this means installing Zola on a (sub)domain and adding any pages or blog posts as Markdown files to the Zola folder (in /var/www/zola/
). Zola would pick up any changes to those files and render and serve any changes.
As you can read elsewhere on this site, I worked out a way to sync changes to these files and use Zola for its ability to automatically serve new content and changes. What I would like even more, was if this was part of my Git workflow: make changes, test if the changes make for correct Zola content and let some kind of hook or process deploy everything to joostagterhoek.nl.
To summarise, I:
- switched from Gitea to Gitlab,
- got a Gitlab Runner 🏃♀️ working on my Raspberry Pi,
- worked out a (basic) SSH/SCP deploy script and…
- presto! Any Git push of blog content (so far) is instantly reflected on the site.
Next steps
So, the next plan is to apply what I learned to my Flask app project:
- Dockerize the app
- get that Docker app running on my server
- Work out a Docker container CI/CD pipeline
- Add some actual tests (I really need to learn Flask/Python testing 😳)
What I learned
Along the way, I learned some interesting things, including:
- Gitlab Runner YAML
- Linux file/directory ownership and access
- Some acces list/control options new to me (
setfacl
) - Bind mounts for SFTP-like access to root-owned (sub)folders (see this YunoHost-reference