Docker Deployment (ALMOST finished)
Hey guys!
Docker:
I am using Docker for deployment of this system to make it easy for anyone who has a weather station or network of them to showcase and monitor their own data. Docker is a type of virtualization (similar to VMs but instead sharing the kernel) that is a lot less resource intensive and is used for deploying a lot of small projects as well as any type of home labbing work flow (hosting your own server etc.). (Yes I pulled that explanation from my last devlog lmao). I will have a tutorial in the ReadME.
Within the docker stack, there are several containers with different jobs and responsibilities:
Web:
Hosts the FastAPI webserver. It uses a endpoint (/health) to monitor the servers responses. It is hosted on port 8000 by default (configurable in the .env file). I would forward this through Nginx or a Cloudflare tunnel to host it under your own domain.
Scraper:
Runs the status and weather scrapers every 15 and 5 minutes (offset by two mins) respectively through a crontab file (scraper.crontab). It is run using Supercronic. The scraper waits for the web server as well. Flock is used to prevent two instances of a program.
DB:
PostgreSQL server that holds all of the data. Weather data, users, etc. All of the other containers wait till the DB is healthy to start.
Db_backup:
A container created by Prodrigestivill to automate backups of Postgres databases. I have it configured to keep the last month and 14 days of backups. It saves all backups to the /opt/mesonet-backups folder.
I wrote scripts in order to test restoring backups (creates test table, restores using latest backup, and deletes it), create a manual backup, and restore the last backup.
Email Alerts:
Fairly similar to how emails are sent in the status-scraper, it obtains admin recpients from the web sever uses enviroment vairbales to send an email. It asks for subject and text using arguments in the terminal, so the user can send emails manually to admins as well.
Health-tests:
Runs a couple of health based scripts on a Supercronic schedule. Monthly restore test (runs the restore test mentioned before) and a daily backup health (checks how old the backup is). Emails will be sent to admins if the restore fails or the backup is more than 26 hours old.
Persistent Storage:
All the containers used volumes that continued even if the containers were deleted to be updated, the data (and the backups) are fine.