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 5, 2024
1 parent 2c97b69 commit 5ec9046
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
build-essential \
libpq-dev \
git \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app
Expand Down Expand Up @@ -54,7 +55,9 @@ COPY --from=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 --from=frontend-build /app/src/objecttypes/static /app/src/objecttypes/static
Expand Down
8 changes: 2 additions & 6 deletions bin/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ uwsgi_threads=${UWSGI_THREADS:-2}

mountpoint=${SUBPATH:-/}

until pg_isready; do
>&2 echo "Waiting for database connection..."
sleep 1
done

>&2 echo "Database is up."
# wait for required services
${SCRIPTPATH}/wait_for_db.sh

# Apply database migrations
>&2 echo "Apply database migrations"
Expand Down
11 changes: 11 additions & 0 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/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."
31 changes: 24 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@ version: '3'

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

web:
build: .
environment:
environment: &app-env
- DJANGO_SETTINGS_MODULE=objecttypes.conf.docker
- SECRET_KEY=${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cy$15d}
- ALLOWED_HOSTS=*
- TWO_FACTOR_FORCE_OTP_ADMIN=no
- TWO_FACTOR_PATCH_ADMIN=no
# setup_configuration env vars
- OBJECTTYPES_DOMAIN=web:8000
- OBJECTTYPES_ORGANIZATION=ObjectTypes
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
- OBJECTS_OBJECTTYPES_PERSON=Some Person
- [email protected]
ports:
- 8000:8000
depends_on:
- db
web-init:
condition: service_completed_successfully

web-init:
build: .
environment: *app-env
command: /setup_configuration.sh
depends_on:
- db
3 changes: 3 additions & 0 deletions docker-init-db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE USER objecttypes;
CREATE DATABASE objecttypes;
GRANT ALL PRIVILEGES ON DATABASE objecttypes TO objecttypes;
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ line_length = 88
multi_line_output = 3
skip = env,node_modules
skip_glob = **/migrations/**
not_skip = __init__.py
known_django=django
known_first_party=objecttypes
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

0 comments on commit 5ec9046

Please sign in to comment.