From 64a0948c272806e13e89480c3e2d4d27a7ed7d0e Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 4 Mar 2025 15:50:45 +0100 Subject: [PATCH] :whale: [#55] Load fixtures automatically in docker run loaddata for all fixtures present in `/app/fixtures/` (which can be mounted as a volume), this makes it easier to load fixtures without having to manually execute loaddata commands --- Dockerfile | 1 + bin/docker_start.sh | 2 ++ bin/load_fixtures.sh | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) create mode 100755 bin/load_fixtures.sh diff --git a/Dockerfile b/Dockerfile index 825dde7..c7fff39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,7 @@ COPY ./bin/docker_start.sh /start.sh # COPY ./bin/celery_beat.sh /celery_beat.sh # COPY ./bin/celery_flower.sh /celery_flower.sh COPY ./bin/wait_for_db.sh /wait_for_db.sh +COPY ./bin/load_fixtures.sh /load_fixtures.sh COPY ./bin/setup_configuration.sh /setup_configuration.sh RUN mkdir /app/bin /app/log /app/media diff --git a/bin/docker_start.sh b/bin/docker_start.sh index bb59ffe..c80e4da 100755 --- a/bin/docker_start.sh +++ b/bin/docker_start.sh @@ -22,6 +22,8 @@ ${SCRIPTPATH}/wait_for_db.sh >&2 echo "Apply database migrations" python src/manage.py migrate +${SCRIPTPATH}/load_fixtures.sh + # Start server >&2 echo "Starting server" exec uwsgi \ diff --git a/bin/load_fixtures.sh b/bin/load_fixtures.sh new file mode 100755 index 0000000..fc8808c --- /dev/null +++ b/bin/load_fixtures.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +fixtures_dir=${FIXTURES_DIR:-/app/fixtures} + +# Load any JSON fixtures present +if [ -d $fixtures_dir ]; then + echo "Loading fixtures from $fixtures_dir" + + for fixture in $(ls "$fixtures_dir/"*.json) + do + echo "Loading fixture $fixture" + python src/manage.py loaddata $fixture + done +fi