From 2693069d0c38751e389bf5ee6042052d884c8ac8 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Wed, 10 Jan 2024 10:12:49 +0100 Subject: [PATCH] Make wagtail DB persistent --- CHANGELOG.md | 1 + Makefile | 13 +++++++++---- deps/wagtail/docker/Dockerfile | 10 ++++------ .../laymanportal/laymanportal/settings/base.py | 2 +- deps/wagtail/laymanportal/start_wagtail.sh | 10 ++++++++++ deps/wagtail/{laymanportal => sample}/db.sqlite3 | Bin docker-compose.deps.yml | 4 ++++ 7 files changed, 29 insertions(+), 11 deletions(-) create mode 100755 deps/wagtail/laymanportal/start_wagtail.sh rename deps/wagtail/{laymanportal => sample}/db.sqlite3 (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4731dd82a..7183834a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - GET Workspace [Layers](doc/rest.md#get-workspace-layers)/[Maps](doc/rest.md#get-workspace-maps) - GET [Layers](doc/rest.md#get-layers)/[Maps](doc/rest.md#get-maps)/[Publications](doc/rest.md#get-publications) - [#165](https://github.com/LayerManager/layman/issues/165) Name of [users](doc/models.md#username) and [public workspaces](doc/models.md#public-workspace) are from now on restricted to a maximum length of 59 characters. +- [941](https://github.com/LayerManager/layman/issues/941) Wagtail database is now persistent when restarting Layman or Wagtail. - All changes from [v1.22.1](#v1221), [v1.22.2](#v1222) and [v1.22.3](#v1223). - [#960](https://github.com/LayerManager/layman/issues/960) Handle WMS requests with HTTP error more efficiently in timgen. - [#962](https://github.com/LayerManager/layman/issues/962) Make values of `layman_metadata.publication_status` and `status` key(s) more consistent in responses of PATCH Workspace [Layer](doc/rest.md#patch-workspace-layer)/[Map](doc/rest.md#patch-workspace-map) and GET Workspace [Layer](doc/rest.md#get-workspace-layer)/[Map](doc/rest.md#get-workspace-map). diff --git a/Makefile b/Makefile index 7739fd322..f673ab8a0 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ start-demo-only: docker compose -f docker-compose.deps.demo.yml -f docker-compose.demo.yml up -d --force-recreate --no-deps layman celery_worker flower timgen layman_client nginx start-demo-full-with-optional-deps: - mkdir -p layman_data deps/qgis/data + mkdir -p layman_data deps/qgis/data deps/wagtail/data docker compose -f docker-compose.deps.demo.yml -f docker-compose.demo.yml build layman layman_client timgen docker compose -f docker-compose.deps.demo.yml -f docker-compose.demo.yml up -d postgresql docker compose -f docker-compose.deps.demo.yml -f docker-compose.demo.yml run --rm --no-deps -u root layman bash -c "cd src && python3 -B setup_geoserver.py" @@ -60,7 +60,7 @@ deps-stop: docker compose -f docker-compose.deps.yml stop start-dev: - mkdir -p layman_data layman_data_test tmp deps/qgis/data + mkdir -p layman_data layman_data_test tmp deps/qgis/data deps/wagtail/data docker compose -f docker-compose.deps.yml -f docker-compose.dev.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.dev.yml run --rm --no-deps -u root layman_dev bash -c "cd src && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.dev.yml up --force-recreate -d @@ -107,7 +107,7 @@ upgrade-dev: docker compose -f docker-compose.deps.yml -f docker-compose.dev.yml run --rm --no-deps layman_dev bash -c "cd src && python3 layman_flush_redis.py && python3 wait_for_deps.py && python3 standalone_upgrade.py" prepare-dirs: - mkdir -p layman_data layman_data_test tmp deps/qgis/data + mkdir -p layman_data layman_data_test tmp deps/qgis/data deps/wagtail/data build-dev: docker compose -f docker-compose.deps.yml -f docker-compose.dev.yml build --force-rm layman_dev @@ -143,7 +143,7 @@ reset-data-directories: docker compose -f docker-compose.deps.yml rm -fsv docker volume rm layman_redis-data || true sudo rm -rf layman_data layman_data_test deps/*/data - mkdir -p layman_data layman_data_test tmp deps/qgis/data + mkdir -p layman_data layman_data_test tmp deps/qgis/data deps/wagtail/data clear-python-cache-dev: docker compose -f docker-compose.deps.yml -f docker-compose.dev.yml run --rm --no-deps layman_dev bash /code/src/clear-python-cache.sh @@ -313,11 +313,16 @@ wagtail-exec: docker compose -f docker-compose.deps.yml exec wagtail bash wagtail-restart: + mkdir -p deps/wagtail/data docker compose -f docker-compose.deps.yml up --force-recreate --no-deps -d wagtail wagtail-stop: docker compose -f docker-compose.deps.yml stop wagtail +wagtail-reset-datadir: + mkdir -p deps/wagtail/data + rm -rf deps/wagtail/data/* + micka-restart: docker compose -f docker-compose.deps.yml up --force-recreate --no-deps -d micka diff --git a/deps/wagtail/docker/Dockerfile b/deps/wagtail/docker/Dockerfile index bdbbdc1e0..c209b1ba2 100644 --- a/deps/wagtail/docker/Dockerfile +++ b/deps/wagtail/docker/Dockerfile @@ -21,15 +21,13 @@ RUN pip install -r /app/requirements.txt # Copy the entire project code. COPY laymanportal /app/ -# Prepare the app. -RUN python manage.py migrate +# Prepare the app: migrations (not needed as db.sqlite3a was generated after migrations) +# RUN python manage.py migrate + +# Prepare the app: collect statis files RUN python manage.py collectstatic --noinput # Create a "coderedcms" user account to run the app. RUN useradd coderedcms RUN chown -R coderedcms /app/ USER coderedcms - -# Finally, run the app on port 8000. -EXPOSE 8000 -CMD exec waitress-serve --listen "*:8000" "laymanportal.wsgi:application" diff --git a/deps/wagtail/laymanportal/laymanportal/settings/base.py b/deps/wagtail/laymanportal/laymanportal/settings/base.py index de5ae3dcf..e4d317b1c 100644 --- a/deps/wagtail/laymanportal/laymanportal/settings/base.py +++ b/deps/wagtail/laymanportal/laymanportal/settings/base.py @@ -125,7 +125,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + "NAME": os.path.join(BASE_DIR, "data/db.sqlite3"), } } diff --git a/deps/wagtail/laymanportal/start_wagtail.sh b/deps/wagtail/laymanportal/start_wagtail.sh new file mode 100755 index 000000000..17c7f2782 --- /dev/null +++ b/deps/wagtail/laymanportal/start_wagtail.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -ex + +if [ ! -f /app/data/db.sqlite3 ]; then + echo "File db.sqlite3 not found, copying the default one." + cp /app/initial_data/db.sqlite3 /app/data/ +fi + +exec waitress-serve --listen "*:8000" "laymanportal.wsgi:application" diff --git a/deps/wagtail/laymanportal/db.sqlite3 b/deps/wagtail/sample/db.sqlite3 similarity index 100% rename from deps/wagtail/laymanportal/db.sqlite3 rename to deps/wagtail/sample/db.sqlite3 diff --git a/docker-compose.deps.yml b/docker-compose.deps.yml index e7539644f..7fc763753 100644 --- a/docker-compose.deps.yml +++ b/docker-compose.deps.yml @@ -67,6 +67,10 @@ services: dockerfile: docker/Dockerfile ports: - 8083:8000 + command: /app/start_wagtail.sh + volumes: + - ./deps/wagtail/data:/app/data/ + - ./deps/wagtail/sample:/app/initial_data/ micka: container_name: micka