Skip to content

Commit

Permalink
🐳 Run setup_configuration in docker-compose.yml
Browse files Browse the repository at this point in the history
and add the required scripts to the docker image
  • Loading branch information
stevenbal committed Feb 25, 2025
1 parent d30bd8c commit b1563aa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ COPY ./bin/docker_start.sh /start.sh
# 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/wait_for_db.sh /wait_for_db.sh
COPY ./bin/setup_configuration.sh /setup_configuration.sh
RUN mkdir /app/bin /app/log /app/media

VOLUME ["/app/log", "/app/media"]
Expand Down
8 changes: 2 additions & 6 deletions bin/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,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"
Expand Down
14 changes: 14 additions & 0 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# setup initial configuration using a yaml file
# Run this script from the root of the repository

set -e

if [[ "${RUN_SETUP_CONFIG,,}" =~ ^(true|1|yes)$ ]]; then
# wait for required services
/wait_for_db.sh

src/manage.py migrate
src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml
fi
15 changes: 15 additions & 0 deletions bin/wait_for_db.sh
Original file line number Diff line number Diff line change
@@ -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."
59 changes: 30 additions & 29 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,40 @@ services:
web:
build: .
image: maykinmedia/referentielijsten-api:latest
environment:
- DJANGO_SETTINGS_MODULE=referentielijsten.conf.docker
- SECRET_KEY=${SECRET_KEY:-django-insecure-4foe-_dk9x=88*0sljyo1_ga!!nj*x8ye6u0p(@871e)zg^+q}
- DB_NAME=referentielijsten
- DB_USER=referentielijsten
- DB_HOST=db
- CACHE_DEFAULT=redis:6379/0
- CACHE_AXES=redis:6379/0
- SUBPATH=${SUBPATH:-/}
- DISABLE_2FA=${DISABLE_2FA:-True}
environment: &app-env
DJANGO_SETTINGS_MODULE: referentielijsten.conf.docker
SECRET_KEY: ${SECRET_KEY:-django-insecure-4foe-_dk9x=88*0sljyo1_ga!!nj*x8ye6u0p(@871e)zg^+q}
DB_NAME: referentielijsten
DB_USER: referentielijsten
DB_HOST: db
CACHE_DEFAULT: redis:6379/0
CACHE_AXES: redis:6379/0
SUBPATH: ${SUBPATH:-/}
DISABLE_2FA: ${DISABLE_2FA:-True}
# Only allow all hosts for development/testing purposes!
- ALLOWED_HOSTS=*
ALLOWED_HOSTS: '*'
ports:
- 8000:8000
volumes: &app-volumes
- media:/app/media # Shared media volume to get access to saved OAS files
- ./docker/setup_configuration:/app/setup_configuration
depends_on:
web-init:
condition: service_completed_successfully

web-init:
build: .
environment:
<<: *app-env
#
# Django-setup-configuration
RUN_SETUP_CONFIG: ${RUN_SETUP_CONFIG:-true}
command: /setup_configuration.sh
depends_on:
- db
- redis
volumes: *app-volumes

# See: src/referentielijsten/conf/docker.py
# Optional containers below:
# elasticsearch:
# # NOTE: No persistance storage configured.
# # See: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
# image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
# container_name: elasticsearch
# environment:
# - discovery.type=single-node
# - cluster.routing.allocation.disk.threshold_enabled=false
# ports:
# - 9200:9200
# redis:
# # NOTE: No persistance storage configured.
# # See: https://hub.docker.com/_/redis/
# image: redis
# ports:
# - 6379:6379
volumes:
media:
db:

0 comments on commit b1563aa

Please sign in to comment.