From d57c44cc85004c7a3cf6c77b590a8e5631d67421 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:08:59 +0000 Subject: [PATCH 1/2] Bump django from 4.2.11 to 4.2.14 Bumps [django](https://github.com/django/django) from 4.2.11 to 4.2.14. - [Commits](https://github.com/django/django/compare/4.2.11...4.2.14) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7da8b1c..de96ce5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ beautifulsoup4==4.12.2 gunicorn==22.0.0 -Django==4.2.11 +Django==4.2.14 environs==9.5.0 feedparser==6.0.10 psycopg2==2.9.5 From 7ce005d2e0dfef2c0b6806a25074579e2643e8ca Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Jul 2024 20:23:22 +1000 Subject: [PATCH 2/2] update docs and glamr-dev - improve README: adds instructions for restoring backups, and setting crontab - remove deprecated "version" from docker-compose - add nginx example conf - add .env to .gitignore (!) --- .gitignore | 3 ++- README.md | 59 ++++++++++++++++++++++++++++++++++++++-------- docker-compose.yml | 4 +--- glamr-dev | 5 +++- nginx.conf.example | 24 +++++++++++++++++++ 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 nginx.conf.example diff --git a/.gitignore b/.gitignore index 1b217cd..07021de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /data fixtures /static +.env .env.dev -z_README_Hugh.md \ No newline at end of file +z_README_Hugh.md diff --git a/README.md b/README.md index a0e19c7..a5a1995 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,18 @@ A django app running on Docker. Replaces _Aus GLAM Blogs_. ## Deploy * `cp .env.example .env` and enter env values for your app -* set up web server config (nginx example coming soon) +* set up web server config (see nginx example) * `docker compose build` -* `./glamr-dev migrate` +* `./glamr-dev migrate` (you may get an error at this point - ignore) * `./glamr-dev createsuperuser` +* `./glamr-dev collectstatic` +* copy static files to where your webserver can find them, e.g.`/srv/ausglamr` * `docker compose up -d` -* set up database backups (as cron jobs): `./glamr-dev backup`: -* set up cron jobs for management commands as below +* set up cron jobs for management commands as outlined below ## Admin -Don't forget to add some Content Warnings for use by the Mastodon bot, within `/admin`. +Don't forget to add some **Content Warnings** for use by the Mastodon bot, within `/admin`. ## CLI tool @@ -59,9 +60,9 @@ These will not be triggered within the app - they should be called via cron jobs ### announce -This announces the next queued announcement on Mastodon. +This posts the next queued announcement on Mastodon. -Run every 21 mins. +Run about every 20 mins. ### check_feeds @@ -83,8 +84,46 @@ Does what you think. Creates a weekly email of the latest stuff, and send to eve Run weekly. -### Backups +## Backups -There is a `backup` command in `glamr-dev`. You can adjust the filepaths in your `.env` file. +### Creating backups -Run daily \ No newline at end of file +There is a `backup` command in `glamr-dev`. The backup is named after the current day of the week, so in effect there will be a maximum of 7 rotating backups. The backup command relies on two environment variables: `DOCKER_PATH` and `BACKUPS_DIR` - you need to set these in your `.env` if you plan to run backups manually, but if you are running it with a cron job (recommended) you need to set environment variables within the crontab itself. See more details below. + +### Restoring backups + +1. back up your VPS if possible (e.g. taking a snapshot) +2. Locate the latest backup, or run the backup program: `./glamr-dev backup` +3. copy database dump into the container: `docker cp ~/ausglamr.dump ausglamr-db-1:/tmp/` +4. restore the dump: `docker exec -d ausglamr-db-1 pg_restore -c -e -U ausglamr -d ausglamr /tmp/ausglamr.dump` + +## Cron jobs + +The obvious way to run the management and backup commands is via cron jobs. It's important to note that environment variables generally need to be set within the crontab - you can't rely on passing them in from Ausglamr nor from a user context. If you forget to to this they will be blank and one of the bad things that will happen is cron will try and fail to run the Unix program `exec` instead of `docker exec` when trying to run backups. + +Below are suggested crontab settings and jobs for Ausglamr. + +``` +# Aus GLAMR +# --------- + +# envs +PATH=/bin:/usr/bin:/usr/local/bin:/snap/bin +DOCKER_PATH=/usr/bin/docker +BACKUPS_DIR=/home/ausglamr/backups + +# Announce thrice an hour +1,23,47 * * * * cd /home/ausglamr/ausglamr && /home/ausglamr/ausglamr/glamr-dev announce + +# Check feeds hourly on the eleventh minute +11 * * * * cd /home/ausglamr/ausglamr && /home/ausglamr/ausglamr/glamr-dev check_feeds + +# Queue event announcements daily at 4:01am +1 4 * * * cd /home/ausglamr/ausglamr && /home/ausglamr/ausglamr/glamr-dev queue_announcements + +# Run backups daily - 1:01am +1 1 * * * cd /home/ausglamr/ausglamr && /home/ausglamr/ausglamr/glamr-dev backup + +# Send email weekly at 12:05pm +5 12 * * 1 cd /home/ausglamr/ausglamr && /home/ausglamr/ausglamr/glamr-dev send_weekly_email +``` diff --git a/docker-compose.yml b/docker-compose.yml index ec7ef7c..2fc1b9f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: db: image: postgres:13 @@ -25,4 +23,4 @@ services: volumes: pgdata: networks: - main: \ No newline at end of file + main: diff --git a/glamr-dev b/glamr-dev index fbdbd0e..78ff9d8 100755 --- a/glamr-dev +++ b/glamr-dev @@ -44,6 +44,9 @@ case "$CMD" in collectstatic) runweb python manage.py collectstatic ;; + copystatic) + cp -r static /srv/ausglamr/ + ;; createsuperuser) runweb python manage.py createsuperuser --no-input ;; @@ -80,4 +83,4 @@ case "$CMD" in set +x echo "That is not a command" ;; -esac \ No newline at end of file +esac diff --git a/nginx.conf.example b/nginx.conf.example new file mode 100644 index 0000000..5682b66 --- /dev/null +++ b/nginx.conf.example @@ -0,0 +1,24 @@ +server { + server_name example.com; + + location = /favicon.ico { + access_log off; + log_not_found off; + } + + location /static { + autoindex on; + alias /srv/ausglamr/static; + } + + location / { + root html; + index index.html index.htm; + proxy_pass http://127.0.0.1:8080; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } +}