Skip to content

Commit 6ffe6a5

Browse files
authored
Production data on dev load automation (#1651) (#1691)
1 parent 8b43040 commit 6ffe6a5

File tree

7 files changed

+1982
-3
lines changed

7 files changed

+1982
-3
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22

33
db:
4-
image: postgres:12.0
4+
image: postgres:16.0
55
env_file: .env
66
environment:
77
- "POSTGRES_HOST_AUTH_METHOD=trust"

env.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ STATIC_CONTENT_BUCKET_NAME="stage.boost.org.v2"
2626
STATIC_CONTENT_REGION="us-east-2"
2727
STATIC_CONTENT_AWS_S3_ENDPOINT_URL="https://s3.us-east-2.amazonaws.com"
2828

29+
PROD_MEDIA_CONTENT_AWS_ACCESS_KEY_ID=$STATIC_CONTENT_AWS_ACCESS_KEY_ID
30+
PROD_MEDIA_CONTENT_AWS_SECRET_ACCESS_KEY=$STATIC_CONTENT_AWS_SECRET_ACCESS_KEY
31+
PROD_MEDIA_CONTENT_BUCKET_NAME="boost.org.media"
32+
PROD_MEDIA_CONTENT_REGION=$STATIC_CONTENT_REGION
33+
PROD_MEDIA_CONTENT_AWS_S3_ENDPOINT_URL=$STATIC_CONTENT_AWS_S3_ENDPOINT_URL
34+
2935
# Mailman database settings
3036
HYPERKITTY_DATABASE_NAME="hyperkitty_db"
3137
DATABASE_URL="postgresql://postgres@db:5432/postgres"
@@ -61,3 +67,7 @@ DEBUG_TOOLBAR=True
6167
# currently only pycharm is supported, vscode kept for example of alternative options
6268
# PYTHONBREAKPOINT=pycharm_debugger.set_trace
6369
# PYTHONBREAKPOINT=vscode_debugger.set_trace
70+
71+
# for production database dumps on Google Cloud Storage
72+
PROD_DB_DUMP_URL=gs://boostbackups/db1/daily/
73+
PROD_DB_DUMP_FILE_WILDCARD=boost_production.db1*

justfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,16 @@ alias shell := console
127127
@pip-compile-upgrade: ## Upgrade existing Python dependencies to their latest versions
128128
just pip-compile --upgrade
129129

130+
@load_production_data: ## downloads and loads the latest production database dump
131+
bash scripts/load_production_data.sh
132+
133+
@dump_database: ## dumps the current database to a .dump file in the project root
134+
#!/usr/bin/env bash
135+
DUMP_FILENAME="database_dump_$(date +"%Y-%m-%d-%H-%M-%S").dump"
136+
echo "Dumping database to ${DUMP_FILENAME}..."
137+
docker compose exec -T db pg_dump -U "$(grep PGDATABASE .env | cut -d= -f2)" -d "$(grep PGUSER .env | cut -d= -f2)" -F c -f "/tmp/${DUMP_FILENAME}"
138+
docker compose cp "db:/tmp/${DUMP_FILENAME}" "./${DUMP_FILENAME}"
139+
echo "Database dumped successfully to ${DUMP_FILENAME}"
140+
130141
@manage args:
131142
docker compose run --rm web python manage.py {{ args }}

libraries/forms.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,14 @@ def cache_html(self):
195195
# ensure we have "cleaned_data"
196196
if not self.is_valid():
197197
return ""
198-
html = render_to_string(self.html_template_name, self.get_stats())
198+
try:
199+
html = render_to_string(self.html_template_name, self.get_stats())
200+
except FileNotFoundError as e:
201+
html = (
202+
f"An error occurred generating the report: {e}. To see the image "
203+
f"which is broken copy the error and run the report again. This "
204+
f"error isn't shown on subsequent runs."
205+
)
199206
self.cache_set(html)
200207
return html
201208

0 commit comments

Comments
 (0)