Skip to content

Commit

Permalink
Initialize db on docker compose up
Browse files Browse the repository at this point in the history
Make the app a little easier to setup locally,
by running django migrate and importing schemas,
on first start of docker compose containers.
  • Loading branch information
Yrob committed Jun 7, 2024
1 parent 5da6d8c commit 02d9676
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 6 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
version: "3.7"
services:
# This Postgres container is used for testing by Jenkins.
# The actual deployment uses a database configured separately.
# For development, use the one from dataservices-airflow;
# see dev-docs/source/howto/install.rst.
database:
image: postgis/postgis:14-3.2
restart: always
Expand Down Expand Up @@ -42,7 +37,7 @@ services:
UWSGI_MASTER: 1
UWSGI_STATIC_MAP: "/dso_api/static=/static"
SECRET_KEY: insecure
DATABASE_URL: "${DATABASE_URL:-postgres://postgres:insecure@database/dataservices}"
DATABASE_URL: "${DATABASE_URL:-postgresql://postgres:insecure@database/dataservices}"
DJANGO_LOG_LEVEL: "${DJANGO_LOG_LEVEL}"
DSO_API_LOG_LEVEL: "${DSO_API_LOG_LEVEL}"
DSO_API_AUDIT_LOG_LEVEL: "${DSO_API_AUDIT_LOG_LEVEL}"
Expand All @@ -55,13 +50,16 @@ services:
DATAPUNT_API_URL: "${DATAPUNT_API_URL}"
DJANGO_DEBUG: 1
APIKEY_ENABLED: "${APIKEY_ENABLED}"
INITIALIZE_DB: "${INITIALIZE_DB:-true}"
SCHEMA_URL: "https://schemas.data.amsterdam.nl/datasets/"
volumes:
- ./src:/app
- ./docs/build/html:/docs-static
- "../amsterdam-schema/datasets:/tmp/datasets"
- "../schema-tools:/tmp/schema-tools"
command: uwsgi --py-auto-reload=1 --enable-threads --lazy-apps --buffer-size=65535

command: >
/bin/bash -c "sh /app/initialize_db.sh
&& uwsgi --py-auto-reload=1 --enable-threads --lazy-apps --buffer-size=65535"
redis:
image: 'bitnami/redis:latest'
environment:
Expand Down
8 changes: 8 additions & 0 deletions src/initialize_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Run when INITIALIZE_DB parameter is set and migrations are available.
if ! django migrate --check && "$INITIALIZE_DB" = "true";
then
./manage.py migrate;
./manage.py import_schemas --create-tables;
schema permissions apply --auto --revoke --create-roles --execute -a "datasets_dataset:SELECT;scope_openbaar" -a "datasets_datasettable:SELECT;scope_openbaar" -a "datasets_datasetfield:SELECT;scope_openbaar" -a "datasets_datasetprofile:SELECT;scope_openbaar";
fi

0 comments on commit 02d9676

Please sign in to comment.