Skip to content

Commit

Permalink
🐳 [maykinmedia/django-setup-configuration#1] add setup_configuration …
Browse files Browse the repository at this point in the history
…into docker
  • Loading branch information
annashamray committed Apr 23, 2024
1 parent a4de147 commit 5e3fadd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ COPY --from=backend-build /usr/local/bin/celery /usr/local/bin/celery

# Stage 3.2 - Copy source code
WORKDIR /app
COPY ./bin/wait_for_db.sh /wait_for_db.sh
COPY ./bin/docker_start.sh /start.sh
COPY ./bin/celery_worker.sh /celery_worker.sh
COPY ./bin/celery_flower.sh /celery_flower.sh
COPY ./bin/check_celery_worker_liveness.py ./bin/
COPY ./bin/setup_configuration.sh /setup_configuration.sh
RUN mkdir /app/log /app/config

# copy frontend build statics
Expand Down
6 changes: 2 additions & 4 deletions bin/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ uwsgi_threads=${UWSGI_THREADS:-2}

mountpoint=${SUBPATH:-/}

until pg_isready; do
>&2 echo "Waiting for database connection..."
sleep 1
done
# wait for required services
${SCRIPTPATH}/wait_for_db.sh

>&2 echo "Database is up."

Expand Down
10 changes: 10 additions & 0 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# setup initial configuration using environment variables
# Run this script from the root of the repository

#set -e
${SCRIPTPATH}/wait_for_db.sh

src/manage.py migrate
src/manage.py setup_configuration --no-selftest
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."
22 changes: 20 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,32 @@ services:
- CELERY_BROKER_URL=redis://redis:6379/1
- CELERY_RESULT_BACKEND=redis://redis:6379/1
- CELERY_LOGLEVEL=DEBUG
# setup_configuration env vars
- OBJECTS_DOMAIN=web:8000
- OBJECTS_ORGANIZATION=Objects
- OBJECTTYPES_API_ROOT=https://objecttypes.example.com/api/v2/
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
- DEMO_CONFIG_ENABLE=yes
- DEMO_TOKEN=demo-random-string
- DEMO_PERSON=Demo
- DEMO_EMAIL=demo@demo.local
ports:
- 8000:8000
depends_on:
- db
- redis
web-init:
condition: service_completed_successfully
volumes: &web_volumes
- media:/app/media # Shared media volume to get access to saved OAS files

web-init:
build: *web_build
environment: *web_env
command: /setup_configuration.sh
depends_on:
- db
- redis
volumes: *web_volumes

celery:
build: *web_build
environment: *web_env
Expand Down

0 comments on commit 5e3fadd

Please sign in to comment.