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 Mar 11, 2024
1 parent d5ea12d commit 9109e7e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ COPY --from=backend-build /usr/local/bin/uwsgi /usr/local/bin/uwsgi

# 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/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."
21 changes: 19 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,36 @@ services:

web:
build: .
environment:
environment: &app-env
- DJANGO_SETTINGS_MODULE=objects.conf.docker
- SECRET_KEY=${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
- OBJECTS_SUPERUSER_USERNAME=admin
- OBJECTS_SUPERUSER_PASSWORD=admin
- OBJECTS_SUPERUSER_EMAIL=admin@localhost
- ALLOWED_HOSTS=*
# 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
- [email protected]
ports:
- 8000:8000
depends_on:
- db
web-init:
condition: service_completed_successfully
volumes:
- media:/app/media # Shared media volume to get access to saved OAS files

web-init:
build: .
environment: *app-env
command: /setup_configuration.sh
depends_on:
- db

volumes:
media:

0 comments on commit 9109e7e

Please sign in to comment.