Skip to content

Commit 112f7a9

Browse files
committed
🐳 [maykinmedia/django-setup-configuration#1] add setup_configuration into docker
1 parent 178ede6 commit 112f7a9

6 files changed

+58
-13
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
55
pkg-config \
66
build-essential \
77
libpq-dev \
8+
git \
89
&& rm -rf /var/lib/apt/lists/*
910

1011
WORKDIR /app
@@ -54,7 +55,9 @@ COPY --from=build /usr/local/bin/uwsgi /usr/local/bin/uwsgi
5455

5556
# Stage 3.2 - Copy source code
5657
WORKDIR /app
58+
COPY ./bin/wait_for_db.sh /wait_for_db.sh
5759
COPY ./bin/docker_start.sh /start.sh
60+
COPY ./bin/setup_configuration.sh /setup_configuration.sh
5861
RUN mkdir /app/log /app/config
5962

6063
COPY --from=frontend-build /app/src/objecttypes/static /app/src/objecttypes/static

bin/docker_start.sh

+2-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +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
22-
23-
>&2 echo "Database is up."
18+
# wait for required services
19+
${SCRIPTPATH}/wait_for_db.sh
2420

2521
# Apply database migrations
2622
>&2 echo "Apply database migrations"

bin/setup_configuration.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
11+
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

+24-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,37 @@ version: '3'
22

33
services:
44
db:
5-
# NOTE: No persistance storage configured.
6-
# See: https://hub.docker.com/_/postgres/
7-
image: postgres
5+
image: postgres:11-alpine
86
environment:
9-
- POSTGRES_USER=${DB_USER:-objecttypes}
10-
- POSTGRES_PASSWORD=${DB_PASSWORD:-objecttypes}
7+
- POSTGRES_HOST_AUTH_METHOD=trust
8+
volumes:
9+
- ./docker-init-db.sql:/docker-entrypoint-initdb.d/init_db.sql
10+
# - db:/var/lib/postgresql/data
11+
command: postgres -c max_connections=300 -c log_min_messages=LOG
1112

1213
web:
1314
build: .
14-
environment:
15+
environment: &app-env
1516
- DJANGO_SETTINGS_MODULE=objecttypes.conf.docker
1617
- SECRET_KEY=${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cy$15d}
1718
- ALLOWED_HOSTS=*
19+
- TWO_FACTOR_FORCE_OTP_ADMIN=no
20+
- TWO_FACTOR_PATCH_ADMIN=no
21+
# setup_configuration env vars
22+
- OBJECTTYPES_DOMAIN=web:8000
23+
- OBJECTTYPES_ORGANIZATION=ObjectTypes
24+
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
25+
- OBJECTS_OBJECTTYPES_PERSON=Some Person
26+
1827
ports:
1928
- 8000:8000
2029
depends_on:
21-
- db
30+
web-init:
31+
condition: service_completed_successfully
32+
33+
web-init:
34+
build: .
35+
environment: *app-env
36+
command: /setup_configuration.sh
37+
depends_on:
38+
- db

docker-init-db.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE USER objecttypes;
2+
CREATE DATABASE objecttypes;
3+
GRANT ALL PRIVILEGES ON DATABASE objecttypes TO objecttypes;

0 commit comments

Comments
 (0)