tdp-server
provides a server to interact with tdp-lib
.
A full beginers guide to launch a testing server is provided at docs/quick-start.md
.
The server is made with Python. The following is required:
- Python
^3.6
- Poetry
1.1.15
- A RDBMS, to store deployment history (e.g. PostgresQL)
- An identity management system, for authentication purposes (e.g. Keycloak)
A dev/testing environment using Keycloak and PostgreSQL is provided through docker-compose
:
docker-compose -f dev/docker-compose.yml up -d
-
Use Poetry to download and install the required Python dependencies:
poetry install
-
Define the required environment variables in an
.env
file. An example file is provided indev/.env-dev
:cp dev/.env-dev .env
In particular:
DATABASE_DSN
: the data source name of the RDBMS.TDP_COLLECTION_PATH
: the path to one or more TDP collection, separated by:
(astdp-collection
andtdp-collection-extras
).TDP_VARS
: the path to an empty directory where thetdp_vars
will be stored and versioned.TDP_RUN_DIRECTORY
: the path to the directory where the Ansible command will be launched (astdp-getting-started
for example). Note: theansible.cfg
file of the working directory must contain the path of thetdp_vars
directory defined previously.
-
Initialize the database and the
tdp_vars
directory:python tdp_server/initialize_database.py python tdp_server/initialize_tdp_vars.py
Start the server using:
uvicorn tdp_server.main:app --reload
docker build -t tdp_server -f docker/Dockerfile .
Executing the container with the minimal configuration variables:
docker run \
-e TDP_COLLECTION_PATH="/tdp/ops/tdp/ansible/ansible_collections/tosit/tdp" \
-e TDP_RUN_DIRECTORY="/tdp/ops" \
-e TDP_VARS="/tdp/ops/inventory/tdp_vars" \
-e DATABASE_DSN=sqlite:////tdp/sqlite.db \
-e OPENID_CONNECT_DISCOVERY_URL="http://host.docker.internal:8080/auth/realms/tdp_server/.well-known/openid-configuration" \
-e OPENID_CLIENT_ID=tdp_server \
-e OPENID_CLIENT_SECRET=secret \
-v "..../sqlite.db:/tdp/sqlite.db" \
-v"..../tdp-ops:/tdp/ops" \
-p 8000:8000 \
tdp_server
N.B.: Mounting a sqlite database is not the recommended way to persist the server's data.
A token must be provided to access the API. Tokens can be obtained using the get_token.py
script.
For example, using curl
:
token=$(python get_token.py)
curl -H "Authorization: Bearer $token" http://localhost:8000/api/v1/service/
Documentation pages of the API are available at:
- OpenAPI UI http://localhost:8000/docs
- ReDoc UI http://localhost:8000/redoc
tdp-server
uses Git Hooks to enforce consistency in the code and commit messages.
Use Poetry to install the hooks:
poetry run pre-commit install --hook-type pre-commit
poetry run pre-commit install --hook-type commit-msg
The following environment variables can be used to ease development:
DO_NOT_USE_IN_PRODUCTION_DISABLE_TOKEN_CHECK
MOCK_DEPLOY