Skip to content

Latest commit

 

History

History
108 lines (79 loc) · 3.21 KB

File metadata and controls

108 lines (79 loc) · 3.21 KB

APP_NAME

FastAPI/Django/React-based web application. This application is constructed to be deployed inside a cloud-harness Kubernetes. It can be also run locally for development and test purpose.

The code is generated with the script harness-application and is in part automatically generated from openapi definition.

Configuration

Accounts

The CloudHarness Django application template comes with a configuration that can retrieve user account updates from Keycloak (accounts) To enable this feature:

  • log in into the accounts admin interface
  • select in the left sidebar Events
  • select the Config tab
  • enable "metacell-admin-event-listener" under the Events Config - Event Listeners

An other option is to enable the "metacell-admin-event-listener" through customizing the Keycloak realm.json from the CloudHarness repository.

Develop

This application is composed of a FastAPI Django backend and a React frontend.

Backend

Backend code is inside the backend directory. See [backend/README.md#Develop]

Frontend

Frontend code is inside the frontend directory.

Frontend is by default generated as a React web application, but no constraint about this specific technology.

Call the backend apis

All the api stubs are automatically generated in the frontend/rest directory by harness-application and harness-generate.

Update the backend apis from openapi.yaml

THe backend openapi models and main.py can be updated using the genapi.sh from the api folder.

Local build & run

Install dependencies

1 - Clone cloud-harness into your project root folder

2 - Install cloud-harness requirements

cd cloud-harness
bash install.sh

3 - Install cloud-harness common library

cd libraries/cloudharness-common
pip install -e .

4 - Install cloud-harness django library

cd ../../infrastructure/common-images/cloudharness-django/libraries/cloudharness-django
pip install -e .

5 - Install cloud-harness fastapi requirements

cd ../fastapi
pip install -r requirements.txt

Prepare backend

Create a Django local superuser account, this you only need to do on initial setup

cd backend
python3 manage.py migrate # to sync the database with the Django models
python3 manage.py collectstatic --noinput # to copy all assets to the static folder
python3 manage.py createsuperuser
# link the frontend dist to the django static folder, this is only needed once, frontend updates will automatically be applied
cd static/www
ln -s ../../../frontend/dist dist

Build frontend

Compile the frontend

cd frontend
npm install
npm run build

Run backend application

start the FastAPI server

uvicorn --workers 2 --host 0.0.0.0 --port 8000 main:app

Running local with port forwardings to a kubernetes cluster

When you create port forwards to microservices in your k8s cluster you want to forced your local backend server to initialize the AuthService and EventService services. This can be done by setting the KUBERNETES_SERVICE_HOST environment variable to a dummy or correct k8s service host. The KUBERNETES_SERVICE_HOST switch will activate the creation of the keycloak client and client roles of this microservice.