Skip to content

Commit 5e3fadd

Browse files
committed
🐳 [maykinmedia/django-setup-configuration#1] add setup_configuration into docker
1 parent a4de147 commit 5e3fadd

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ COPY --from=backend-build /usr/local/bin/celery /usr/local/bin/celery
5151

5252
# Stage 3.2 - Copy source code
5353
WORKDIR /app
54+
COPY ./bin/wait_for_db.sh /wait_for_db.sh
5455
COPY ./bin/docker_start.sh /start.sh
5556
COPY ./bin/celery_worker.sh /celery_worker.sh
5657
COPY ./bin/celery_flower.sh /celery_flower.sh
5758
COPY ./bin/check_celery_worker_liveness.py ./bin/
59+
COPY ./bin/setup_configuration.sh /setup_configuration.sh
5860
RUN mkdir /app/log /app/config
5961

6062
# copy frontend build statics

bin/docker_start.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ uwsgi_threads=${UWSGI_THREADS:-2}
1515

1616
mountpoint=${SUBPATH:-/}
1717

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

2321
>&2 echo "Database is up."
2422

bin/setup_configuration.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# setup initial configuration using environment variables
4+
# Run this script from the root of the repository
5+
6+
#set -e
7+
${SCRIPTPATH}/wait_for_db.sh
8+
9+
src/manage.py migrate
10+
src/manage.py setup_configuration --no-selftest

bin/wait_for_db.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Wait for the database container
6+
# See: https://docs.docker.com/compose/startup-order/
7+
export PGHOST=${DB_HOST:-db}
8+
export PGPORT=${DB_PORT:-5432}
9+
10+
until pg_isready; do
11+
>&2 echo "Waiting for database connection..."
12+
sleep 1
13+
done
14+
15+
>&2 echo "Database is up."

docker-compose.yml

+20-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,32 @@ services:
3030
- CELERY_BROKER_URL=redis://redis:6379/1
3131
- CELERY_RESULT_BACKEND=redis://redis:6379/1
3232
- CELERY_LOGLEVEL=DEBUG
33+
# setup_configuration env vars
34+
- OBJECTS_DOMAIN=web:8000
35+
- OBJECTS_ORGANIZATION=Objects
36+
- OBJECTTYPES_API_ROOT=https://objecttypes.example.com/api/v2/
37+
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
38+
- DEMO_CONFIG_ENABLE=yes
39+
- DEMO_TOKEN=demo-random-string
40+
- DEMO_PERSON=Demo
41+
3342
ports:
3443
- 8000:8000
3544
depends_on:
36-
- db
37-
- redis
45+
web-init:
46+
condition: service_completed_successfully
3847
volumes: &web_volumes
3948
- media:/app/media # Shared media volume to get access to saved OAS files
4049

50+
web-init:
51+
build: *web_build
52+
environment: *web_env
53+
command: /setup_configuration.sh
54+
depends_on:
55+
- db
56+
- redis
57+
volumes: *web_volumes
58+
4159
celery:
4260
build: *web_build
4361
environment: *web_env

0 commit comments

Comments
 (0)