Skip to content

Commit

Permalink
Upgrade django-setup-configuration
Browse files Browse the repository at this point in the history
Certain steps (e.g loading sites, tokens, services) will be replaced
through separate branches. Those branches will branch from this branch.
  • Loading branch information
Sonny Bakker committed Dec 12, 2024
1 parent 259c9a6 commit bec6031
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 654 deletions.
14 changes: 9 additions & 5 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

# setup initial configuration using environment variables
# setup initial configuration using an yaml file
# Run this script from the root of the repository

#set -e
${SCRIPTPATH}/wait_for_db.sh
set -e

src/manage.py migrate
src/manage.py setup_configuration --no-selftest
if [[ "${RUN_SETUP_CONFIG,,}" =~ ^(true|1|yes)$ ]]; then
# wait for required services
/wait_for_db.sh

src/manage.py migrate
src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml
fi
46 changes: 20 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,17 @@ services:
build: &web_build
context: .
environment: &web_env
- DJANGO_SETTINGS_MODULE=objects.conf.docker
- SECRET_KEY=${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
- IS_HTTPS=no
- ALLOWED_HOSTS=*
- CACHE_DEFAULT=redis:6379/0
- CACHE_AXES=redis:6379/0
- CELERY_BROKER_URL=redis://redis:6379/1
- CELERY_RESULT_BACKEND=redis://redis:6379/1
- CELERY_LOGLEVEL=DEBUG
- DISABLE_2FA=${DISABLE_2FA:-yes}
- SUBPATH=${SUBPATH}
# setup_configuration env vars
- SITES_CONFIG_ENABLE=yes
- OBJECTS_DOMAIN=web:8000
- OBJECTS_ORGANIZATION=Objects
- OBJECTS_OBJECTTYPES_CONFIG_ENABLE=false
# - 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]
DJANGO_SETTINGS_MODULE: objects.conf.docker
SECRET_KEY: ${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
IS_HTTPS: no
ALLOWED_HOSTS: *
CACHE_DEFAULT: redis:6379/0
CACHE_AXES: redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/1
CELERY_RESULT_BACKEND: redis://redis:6379/1
CELERY_LOGLEVEL: DEBUG
DISABLE_2FA: ${DISABLE_2FA:-yes}
SUBPATH: ${SUBPATH}
healthcheck:
test: ["CMD", "python", "-c", "import requests; exit(requests.head('http://localhost:8000/admin/').status_code not in [200, 302])"]
interval: 30s
Expand All @@ -46,7 +35,7 @@ services:
# This should allow for enough time for migrations to run before the max
# retries have passed. This healthcheck in turn allows other containers
# to wait for the database migrations.
start_period: 30s
start_period: 30s
ports:
- 8000:8000
depends_on:
Expand All @@ -58,12 +47,17 @@ services:
web-init:
image: maykinmedia/objects-api:latest
build: *web_build
environment: *web_env
environment:
<<: *web_env
#
# Django-setup-configuration
RUN_SETUP_CONFIG: $RUN_SETUP_CONFIG:-true}
command: /setup_configuration.sh
depends_on:
- db
- redis
volumes: *web_volumes
volumes:
- ./docker/setup_configuration:/app/setup_configuration

celery:
image: maykinmedia/objects-api:latest
Expand All @@ -75,7 +69,7 @@ services:
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
start_period: 10s
depends_on:
web:
condition: service_healthy
Expand Down
1 change: 1 addition & 0 deletions docker/setup_configuration/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
...
101 changes: 11 additions & 90 deletions docs/installation/config_cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ Configuration (CLI)
After deploying Objecttypes API and Objects API, they need to be configured to be fully functional. The
command line tool `setup_configuration`_ assist with this configuration:

* It uses environment variables for all configuration choices, therefore you can integrate this with your
infrastructure tooling such as init containers and/or Kubernetes Jobs.
* The command can self-test the configuration to detect problems early on

You can get the full command documentation with:

.. code-block:: bash
Expand All @@ -28,88 +24,28 @@ Preparation
===========

The command executes the list of pluggable configuration steps, and each step
required specific environment variables, that should be prepared.
Here is the description of all available configuration steps and the environment variables,
use by each step for both APIs.

requires specific configuration information, that should be prepared.
Here is the description of all available configuration steps and the configuration
format, use by each step.

Objects API
===========

Sites configuration
-------------------

Configure the domain where Objects API is hosted
Objecttypes connection configuration
------------------------------------

* ``SITES_CONFIG_ENABLE``: enable Site configuration. Defaults to ``False``.
* ``OBJECTS_DOMAIN``: a ``[host]:[port]`` or ``[host]`` value. Required.
* ``OBJECTS_ORGANIZATION``: name of Objects API organization. Required.
Tokens configuration
-------------------

Objecttypes configuration
Notifications configuration
-------------------------

Objects API uses Objecttypes API to validate data against JSON schemas, therefore
it should be able to request Objecttypes API.

* ``OBJECTS_OBJECTTYPES_CONFIG_ENABLE``: enable Objecttypes configuration. Defaults
to ``False``.
* ``OBJECTTYPES_API_ROOT``: full URL to the Objecttypes API root, for example
``https://objecttypes.gemeente.local/api/v1/``. Required.
* ``OBJECTTYPES_API_OAS``: full URL to the Objecttypes OpenAPI specification.
* ``OBJECTS_OBJECTTYPES_TOKEN``: authorization token. Required.
* ``OBJECTS_OBJECTTYPES_PERSON``: Objects API contact person. Required.
* ``OBJECTS_OBJECTTYPES_EMAIL``: Objects API contact email. Required.

Demo user configuration
-----------------------

Demo user can be created to check if Objects API work. It has superuser permissions,
so its creation is not recommended on production environment.

* ``DEMO_CONFIG_ENABLE``: enable demo user configuration. Defaults to ``False``.
* ``DEMO_PERSON``: demo user contact person. Required.
* ``DEMO_EMAIL``: demo user email. Required.
* ``DEMO_TOKEN``: demo token. Required.


Objecttypes API
===============

ObjectTypes API has similar configuration steps as the Objects API.
Mozilla-django-oidc-db
----------------------

Sites configuration
-------------------

Configure the domain where Objects API is hosted

* ``SITES_CONFIG_ENABLE``: enable Site configuration. Defaults to ``False``.
* ``OBJECTTYPES_DOMAIN``: a ``[host]:[port]`` or ``[host]`` value. Required.
* ``OBJECTTYPES_ORGANIZATION``: name of Objecttypes API organization. Required.

Objects configuration
---------------------

Objects API uses Objecttypes API to validate data against JSON schemas, therefore
it should be able to request Objecttypes API.

* ``OBJECTS_OBJECTTYPES_CONFIG_ENABLE``: enable Objecttypes configuration. Defaults
to ``False``.
* ``OBJECTTYPES_API_ROOT``: full URL to the Objecttypes API root, for example
``https://objecttypes.gemeente.local/api/v1/``. Required.
* ``OBJECTTYPES_API_OAS``: full URL to the Objecttypes OpenAPI specification.
* ``OBJECTS_OBJECTTYPES_TOKEN``: authorization token. Required.

Demo user configuration
-----------------------

The similar configuration as in Objects API.

* ``DEMO_CONFIG_ENABLE``: enable demo user configuration. Defaults to ``False``.
* ``DEMO_PERSON``: demo user contact person. Required.
* ``DEMO_EMAIL``: demo user email. Required.
* ``DEMO_TOKEN``: demo token. Required.


Execution
=========

Expand All @@ -119,19 +55,4 @@ tested.

.. code-block:: bash
src/manage.py setup_configuration
You can skip the self-tests by using the ``--no-selftest`` flag.

.. code-block:: bash
src/manage.py setup_configuration --no-self-test
``setup_configuration`` command checks if the configuration already exists before changing it.
If you want to change some of the values of the existing configuration you can use ``--overwrite`` flag.

.. code-block:: bash
src/manage.py setup_configuration --overwrite
src/manage.py setup_configuration --yaml-file /path/to/config.yaml
19 changes: 17 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
amqp==5.2.0
# via kombu
annotated-types==0.7.0
# via pydantic
ape-pie==0.2.0
# via
# commonground-api-common
Expand Down Expand Up @@ -151,7 +153,7 @@ django-sendfile2==0.7.0
# via django-privates
django-sessionprofile==3.0.0
# via open-api-framework
django-setup-configuration==0.1.0
django-setup-configuration==0.4.0
# via open-api-framework
django-simple-certmanager==1.4.1
# via zgw-consumers
Expand Down Expand Up @@ -260,6 +262,14 @@ psycopg2==2.9.9
# via open-api-framework
pycparser==2.20
# via cffi
pydantic==2.9.2
# via
# django-setup-configuration
# pydantic-settings
pydantic-core==2.23.4
# via pydantic
pydantic-settings[yaml]==2.6.1
# via django-setup-configuration
pyjwt==2.4.0
# via
# commonground-api-common
Expand All @@ -278,7 +288,9 @@ python-dateutil==2.9.0.post0
python-decouple==3.8
# via open-api-framework
python-dotenv==1.0.0
# via open-api-framework
# via
# open-api-framework
# pydantic-settings
pytz==2024.1
# via
# drf-yasg
Expand All @@ -288,6 +300,7 @@ pyyaml==6.0.1
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
qrcode==6.1
# via django-two-factor-auth
redis==3.5.3
Expand Down Expand Up @@ -321,6 +334,8 @@ tornado==6.4.1
typing-extensions==4.9.0
# via
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# zgw-consumers
tzdata==2024.1
# via celery
Expand Down
23 changes: 22 additions & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ amqp==5.2.0
# via
# -r requirements/base.txt
# kombu
annotated-types==0.7.0
# via
# -r requirements/base.txt
# pydantic
ape-pie==0.2.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -235,7 +239,7 @@ django-sessionprofile==3.0.0
# via
# -r requirements/base.txt
# open-api-framework
django-setup-configuration==0.1.0
django-setup-configuration==0.4.0
# via
# -r requirements/base.txt
# open-api-framework
Expand Down Expand Up @@ -447,6 +451,19 @@ pycparser==2.20
# via
# -r requirements/base.txt
# cffi
pydantic==2.9.2
# via
# -r requirements/base.txt
# django-setup-configuration
# pydantic-settings
pydantic-core==2.23.4
# via
# -r requirements/base.txt
# pydantic
pydantic-settings[yaml]==2.6.1
# via
# -r requirements/base.txt
# django-setup-configuration
pyflakes==3.2.0
# via flake8
pyjwt==2.4.0
Expand Down Expand Up @@ -483,6 +500,7 @@ python-dotenv==1.0.0
# via
# -r requirements/base.txt
# open-api-framework
# pydantic-settings
pytz==2024.1
# via
# -r requirements/base.txt
Expand All @@ -494,6 +512,7 @@ pyyaml==6.0.1
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
# vcrpy
qrcode==6.1
# via
Expand Down Expand Up @@ -552,6 +571,8 @@ typing-extensions==4.9.0
# via
# -r requirements/base.txt
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# zgw-consumers
tzdata==2024.1
# via
Expand Down
Loading

0 comments on commit bec6031

Please sign in to comment.