Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Latest commit

 

History

History
132 lines (85 loc) · 4.78 KB

README.md

File metadata and controls

132 lines (85 loc) · 4.78 KB

safe-config-service

Coverage Status

The safe-config-service is a service that provides configuration information in the context of the Safe clients environment (eg.: list of available safe apps).

Requirements

Setup

The service uses Gunicorn+Nginx as a connection proxy, Django as the main application layer and PostgreSQL as a relational database. All these services are provided with Docker images that can be started using the provided docker-compose (local setup of the services is out of scope for this document).

1. Configuration

The environment variables are set via the .env file. The configuration in .env.example is meant to be production ready. You can copy it and adjust it to your development needs (refer to the file for the explanation about each environment variable).

cp .env.example .env

Some variables are required to be set before running the application: SECRET_KEY, POSTGRES_USER, POSTGRES_PASSWORD. They can be set either locally on your environment or (as a provided example) by uncommenting these variables from the .env file.

2. Service deployment/development

a) with Django

If you wish to develop locally without running an image for the Django service you can do the following:

  1. Install the required Python dependencies. Eg.: With a python virtual environment:
python -m venv venv # creates a virtual environment venv in the local directory
source venv/bin/activate
pip install -r requirements-dev.txt
  1. Export the environment variables of .env to the local shell/environment (some shells might require you to allexport before doing that)
source .env
  1. Run a PostgreSQL database locally. Check your .env to see the user, host and port details which are expected by the Django application. You can also run the bundled Postrges image with Docker.
docker-compose up -d db # postgres will list on port $POSTGRES_PORT
  1. Launch the django app:
python src/manage.py runserver

b) with Docker

  1. Override the docker-compose for local development – by default the Django application won't reload when the codebase changes (restarting the images is required). In order to see our changes without restarting the docker images:
cp docker-compose.override.yml.example docker-compose.override.yml
  1. Set the mount point to /app in the .env file
DOCKER_WEB_VOLUME=.:/app
  1. Launch images
docker-compose up -d

This will start the Nginx proxy server, the safe-config-service and a postgres database. Nginx exposes the port 8080 to the host which is the port used to interact with the application.

Once you have the images up and running the service can be reached via localhost:8080.

  1. ./run script

The ./run script is meant to be used as an utility to interact with the running image. You can execute ./run help to see the available commands.

Example: if you want to issue a command to the image which is running the Django service from your host you can do the following:

./run manage <django-command>

Development Tools

The project uses a variety of tools to make sure that the styling, health and correctness are validated on each change. These tools are available via requirements-dev.txt so to have them available in your virtual environment run:

pip install -r requirements-dev.txt

Testing

Pytest is used to run the available tests in the project. Some of these tests validate the integration with the database so having one running is required. From the project root:

pytest src

Code Style Formatter and Linter

Black, Flake8 and isort are the tools used to validate the style of the changes being pushed. You can refer to the documentation of these tools to check how to integrate them with your editor/IDE.

isort --profile black src # sorts imports according to the isort spec with a profile compatible with Black
black src # formats the files in the src folder using Black
flake8 src # runs flake8 Linter in the src folder

There's also a pre-commit hook that you can install locally via pre-commit so that it formats the files changed on each commit automatically:

pre-commit install # installs commit hook under .git/hooks/pre-commit
git commit # Initially this can take a couple minutes to setup the environment (which will be reused in following commits)