Skip to content

Commit 9875d03

Browse files
committed
🐳 [maykinmedia/django-setup-configuration#1] add setup_configuration into docker
1 parent 4273d4f commit 9875d03

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ COPY --from=backend-build /usr/local/bin/uwsgi /usr/local/bin/uwsgi
5050

5151
# Stage 3.2 - Copy source code
5252
WORKDIR /app
53+
COPY ./bin/wait_for_db.sh /wait_for_db.sh
5354
COPY ./bin/docker_start.sh /start.sh
55+
COPY ./bin/setup_configuration.sh /setup_configuration.sh
5456
RUN mkdir /app/log /app/config
5557

5658
# 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

+19-2
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,36 @@ services:
1111

1212
web:
1313
build: .
14-
environment:
14+
environment: &app-env
1515
- DJANGO_SETTINGS_MODULE=objects.conf.docker
1616
- SECRET_KEY=${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
1717
- OBJECTS_SUPERUSER_USERNAME=admin
1818
- OBJECTS_SUPERUSER_PASSWORD=admin
1919
- OBJECTS_SUPERUSER_EMAIL=admin@localhost
2020
- ALLOWED_HOSTS=*
21+
# setup_configuration env vars
22+
- OBJECTS_DOMAIN=web:8000
23+
- OBJECTS_ORGANIZATION=Objects
24+
- OBJECTTYPES_API_ROOT=https://objecttypes.example.com/api/v2/
25+
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
26+
- DEMO_CONFIG_ENABLE=yes
27+
- DEMO_TOKEN=demo-random-string
28+
- DEMO_PERSON=Demo
29+
2130
ports:
2231
- 8000:8000
2332
depends_on:
24-
- db
33+
web-init:
34+
condition: service_completed_successfully
2535
volumes:
2636
- media:/app/media # Shared media volume to get access to saved OAS files
2737

38+
web-init:
39+
build: .
40+
environment: *app-env
41+
command: /setup_configuration.sh
42+
depends_on:
43+
- db
44+
2845
volumes:
2946
media:

0 commit comments

Comments
 (0)