Skip to content

Commit 8ab589a

Browse files
authored
Production ready (#75)
* Add database backup to update * Minor production changes
1 parent d5a6789 commit 8ab589a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

config/settings/base.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
APPS_DIR = BASE_DIR / "hesma"
1212
env = environ.Env()
1313

14-
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
14+
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=True)
1515
if READ_DOT_ENV_FILE:
1616
# OS environment variables take precedence over variables from .env
1717
env.read_env(str(BASE_DIR / ".env"))
@@ -298,3 +298,11 @@
298298
# Hydro data directory for storing larger files (e.g. snapshots)
299299
HYDRO_DATA_DIR = env.str("HYDRO_DATA_DIR", default="hydro_data/")
300300
hydro_fs = FileSystemStorage(location=HYDRO_DATA_DIR)
301+
302+
# Tracer data directory for storing larger files (e.g. snapshots)
303+
TRACER_DATA_DIR = env.str("TRACER_DATA_DIR", default="tracer_data/")
304+
tracer_fs = FileSystemStorage(location=TRACER_DATA_DIR)
305+
306+
# RT data directory for storing larger files (e.g. snapshots)
307+
RT_DATA_DIR = env.str("RT_DATA_DIR", default="rt_data/")
308+
rt_fs = FileSystemStorage(location=RT_DATA_DIR)

production.yml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ services:
1515
image: hesma_production_django
1616
volumes:
1717
- production_django_media:/app/hesma/media
18+
- type: bind
19+
source: /var/www/hesma_data
20+
target: /data
1821
depends_on:
1922
- postgres
2023
- redis

scripts/update_production.sh

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
#!/bin/bash
22

3+
echo "Create database backup? (y/n)"
4+
read answer
5+
if [ "$answer" != "${answer#[Yy]}" ] ;then
6+
echo "Creating database backup..."
7+
# Load the environment variables
8+
source .envs/.production/.postgres
9+
10+
# Check if POSTGRES_BACKUP_DIR env var is set
11+
if [ -z "$POSTGRES_BACKUP_DIR" ]; then
12+
echo "POSTGRES_BACKUP_DIR is not set. Defaulting to ./backups"
13+
backup_dir="./backups"
14+
else
15+
echo "POSTGRES_BACKUP_DIR is set to $POSTGRES_BACKUP_DIR"
16+
backup_dir=$POSTGRES_BACKUP_DIR
17+
fi
18+
19+
# Create the backup directory if it doesn't exist
20+
if [ ! -d "$backup_dir" ]; then
21+
mkdir -p $backup_dir
22+
fi
23+
24+
# Backup the database
25+
docker exec -t hesma_production_postgres pg_dumpall -c -U $POSTGRES_USER | gzip > $backup_dir/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz
26+
27+
echo "Backup complete"
28+
fi
29+
330
echo "Shutting down the local cluster..."
431
docker compose -f production.yml down
532

0 commit comments

Comments
 (0)