Skip to content

Setup a development environment

Pre requisites

Tools

Following tools need to be installed on your workstation:

  • Docker
  • Docker-compose
  • Python 3.9
  • Python virtualenv
  • Poetry
  • npm 8

System packages

Ubuntu based OS:

sudo apt-get install libmysqlclient-dev graphviz default-mysql-client libsqlite3-dev libsasl2-dev python3-dev libldap2-dev libssl-dev libpq-dev

CentOS/RedHat/Fedora

sudo yum install mysql-devel graphviz mysql libsq3-devel libpq-devel

Start a development environment

The development environment is composed of 4 parts:

  • Docker compose: The Docker compose file is used to deploy all required components such as the database and the message broker
  • Celery worker: The Celery worker is a separated process that receive tasks from the main Django process to be executed asynchronously
  • Celery beat: Celery beat is a periodic task scheduler that send task into the celery worker based on a frequency. This part is used by Squest to check the status of executed RHAAP/AWX job
  • Django built in web server: Integrated web server used only for development purpose. main process of the application that serve the Web Ui and the API

Docker compose

Run the Docker compose file with only required services to bring up database, message broker and other required system

docker-compose -f docker-compose.yml  -f dev.docker-compose.yml up db phpmyadmin rabbitmq redis-cache
If you use postgreSQL, update docker/environment_variables/squest.env, then run
docker-compose -f docker-compose.yml  -f psql.docker-composer.yml -f dev.docker-compose.yml up db phpmyadmin rabbitmq redis-cache

Javascript libraries

Install JS libs (npm need to be installed)

npm install

Python environment

Initializing and installing python libraries with Poetry

poetry install

Go into the python virtual env

poetry shell

Create the database with Django migration script

python manage.py migrate

Collect static files

python manage.py collectstatic --noinput

Insert default data

python manage.py insert_default_data

Celery worker and periodic task scheduler

Run Celery process for async tasks from a new terminal

poetry shell
celery -A service_catalog worker -l info

Run Celery beat for periodic tasks from a new terminal

poetry shell
celery -A service_catalog worker --beat -l info

Django integrated web server

This next command should be executed from your IDE.

Run django dev server

poetry shell
python manage.py runserver

Settings are placed into the squest/settings.py file which is a standard Django core settings file.

Commands

To clean all Celery pending tasks

poetry shell
celery -A restapi purge

Execute tests

Run unit tests

poetry shell
python manage.py test

Run code coverage

coverage run --source='.' manage.py test
# generate terminal report
coverage report
# generate HTML report
coverage html

phpMyAdmin

phpMyAdmin is exposed on localhost:8082.

  • server : db
  • user : root
  • password : p@ssw0rd