diff --git a/Dockerfile b/Dockerfile index 9f0aff9394..795109200c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,8 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-reco build-essential \ python3-dev \ libpq-dev \ + # TODO should be removed + git \ shared-mime-info \ # lxml/xmlsec deps zlib1g-dev \ @@ -86,6 +88,8 @@ COPY ./bin/celery_worker.sh /celery_worker.sh COPY ./bin/celery_beat.sh /celery_beat.sh COPY ./bin/celery_flower.sh /celery_flower.sh COPY ./bin/dump_configuration.sh /dump_configuration.sh +COPY ./bin/wait_for_db.sh /wait_for_db.sh +COPY ./bin/setup_configuration.sh /setup_configuration.sh RUN mkdir /app/bin /app/log /app/media /app/private_media /app/certifi_ca_bundle /app/tmp COPY \ ./bin/check_celery_worker_liveness.py \ diff --git a/bin/docker_start.sh b/bin/docker_start.sh index 042bb65fa0..577712ea0f 100755 --- a/bin/docker_start.sh +++ b/bin/docker_start.sh @@ -2,11 +2,6 @@ set -ex -# Wait for the database container -# See: https://docs.docker.com/compose/startup-order/ -export PGHOST=${DB_HOST:-db} -export PGPORT=${DB_PORT:-5432} - fixtures_dir=${FIXTURES_DIR:-/app/fixtures} uwsgi_port=${UWSGI_PORT:-8000} @@ -15,12 +10,8 @@ uwsgi_threads=${UWSGI_THREADS:-1} mountpoint=${SUBPATH:-/} -until pg_isready; do - >&2 echo "Waiting for database connection..." - sleep 1 -done - ->&2 echo "Database is up." +# wait for required services +${SCRIPTPATH}/wait_for_db.sh # Apply database migrations >&2 echo "Apply database migrations" diff --git a/bin/setup_configuration.sh b/bin/setup_configuration.sh new file mode 100755 index 0000000000..6a13c74619 --- /dev/null +++ b/bin/setup_configuration.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# setup initial configuration using environment variables +# Run this script from the root of the repository + +set -e + +# wait for required services +${SCRIPTPATH}/wait_for_db.sh + +src/manage.py migrate +src/manage.py setup_configuration --no-selftest --yaml-file data/services.yaml diff --git a/bin/wait_for_db.sh b/bin/wait_for_db.sh new file mode 100755 index 0000000000..89e15e6a1b --- /dev/null +++ b/bin/wait_for_db.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +# Wait for the database container +# See: https://docs.docker.com/compose/startup-order/ +export PGHOST=${DB_HOST:-db} +export PGPORT=${DB_PORT:-5432} + +until pg_isready; do + >&2 echo "Waiting for database connection..." + sleep 1 +done + +>&2 echo "Database is up." diff --git a/docker-compose.yml b/docker-compose.yml index 29fe538895..a2d30f5397 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -88,15 +88,35 @@ services: volumes: &web_volumes - media:/app/media - private_media:/app/private_media + - ./docker/data:/app/data + # TODO should be removed + - ./bin/setup_configuration.sh:/setup_configuration.sh - log:/app/log - certifi_ca_bundle:/app/certifi_ca_bundle ports: - 8000:8000 + depends_on: + db: + condition: service_started + redis: + condition: service_started + smtp: + condition: service_started + clamav: + condition: service_started + web-init: + condition: service_completed_successfully + networks: + - open-forms-dev + + web-init: + build: . + environment: *web_env + command: /setup_configuration.sh + volumes: *web_volumes depends_on: - db - redis - - smtp - - clamav networks: - open-forms-dev diff --git a/docker/data/services.yaml b/docker/data/services.yaml new file mode 100644 index 0000000000..3a137d747b --- /dev/null +++ b/docker/data/services.yaml @@ -0,0 +1,17 @@ +ZGW_CONSUMERS_CONFIG_ENABLE: True +ZGW_CONSUMERS: + services: + - slug: objecttypen-test + label: Objecttypen API test + api_root: https://httpstat.us/404 + api_type: orc + auth_type: api_key + header_key: Authorization + header_value: Token foo + - slug: objecten-test + label: Objecten API test + api_root: https://httpstat.us/403 + api_type: orc + auth_type: api_key + header_key: Authorization + header_value: Token bar