# genesis-os-server **Repository Path**: nowxtech/genesis-os-server ## Basic Information - **Project Name**: genesis-os-server - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-10 - **Last Updated**: 2024-05-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # genesis_os_server ## Poetry This project uses poetry. It's a modern dependency management tool. To run the project use this set of commands: ```bash poetry install poetry run python -m genesis_os_server ``` This will start the server on the configured host. You can find swagger documentation at `/docs`. You can read more about poetry here: https://python-poetry.org/ ## Docker You can start the project with docker using this command: ```bash docker-compose -f docker/docker-compose.yml --project-directory . up --build -d ``` If you want to develop in docker with autoreload add `-f docker/docker-compose.dev.yml` to your docker command. Like this: ```bash docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml -f docker/milvus-standalone-docker-compose.yml --project-directory . up --build -d ``` This command exposes the web application on port 8000, mounts current directory and enables autoreload. But you have to rebuild image every time you modify `poetry.lock` or `pyproject.toml` with this command: ```bash docker-compose -f docker/docker-compose.yml --project-directory . build ``` ## Project structure ```bash $ tree "genesis_os_server" genesis_os_server ├── conftest.py # Fixtures for all tests. ├── db # module contains db configurations │   ├── repo # Data Access Objects. Contains different classes to interact with database. │   └── models # Package contains different models for ORMs. ├── __main__.py # Startup script. Starts uvicorn. ├── services # Package for different external services such as rabbit or redis etc. ├── settings.py # Main configuration settings for project. ├── static # Static content. ├── tests # Tests for project. └── web # Package contains web server. Handlers, startup config. ├── api # Package with all handlers. │   └── router.py # Main router. ├── application.py # FastAPI application configuration. └── lifetime.py # Contains actions to perform on startup and shutdown. ``` ## Configuration This application can be configured with environment variables. You can create `.env` file in the root directory and place all environment variables here. All environment variables should start with "GENESIS_OS_SERVER_" prefix. For example if you see in your "genesis_os_server/settings.py" a variable named like `random_parameter`, you should provide the "GENESIS_OS_SERVER_RANDOM_PARAMETER" variable to configure the value. This behaviour can be changed by overriding `env_prefix` property in `genesis_os_server.settings.Settings.Config`. An example of .env file: ```bash GENESIS_OS_SERVER_RELOAD="True" GENESIS_OS_SERVER_PORT="8000" GENESIS_OS_SERVER_ENVIRONMENT="dev" ``` You can read more about BaseSettings class here: https://pydantic-docs.helpmanual.io/usage/settings/ ## Pre-commit To install pre-commit simply run inside the shell: ```bash pre-commit install ``` pre-commit is very useful to check your code before publishing it. It's configured using .pre-commit-config.yaml file. By default it runs: * black (formats your code); * mypy (validates types); * isort (sorts imports in all files); * flake8 (spots possible bugs); You can read more about pre-commit here: https://pre-commit.com/ ## Migrations If you want to migrate your database, you should run following commands: ```bash # To run all migrations until the migration with revision_id. alembic upgrade "" # To perform all pending migrations. alembic upgrade "head" ``` ### Reverting migrations If you want to revert migrations, you should run: ```bash # revert all migrations up to: revision_id. alembic downgrade # Revert everything. alembic downgrade base ``` ### Migration generation To generate migrations you should run: ```bash # For automatic change detection. alembic revision --autogenerate # For empty file generation. alembic revision ``` ## Running tests If you want to run it in docker, simply run: ```bash docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml --project-directory . run --build --rm api pytest -vv . docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml --project-directory . down ``` For running tests on your local machine. 1. you need to start a database. I prefer doing it with docker: ``` docker run -p "5432:5432" -e "POSTGRES_PASSWORD=genesis_os_server" -e "POSTGRES_USER=genesis_os_server" -e "POSTGRES_DB=genesis_os_server" postgres:13.8-bullseye ``` 2. Run the pytest. ```bash pytest -vv . ``` ### Taskiq run worker ```bash taskiq worker genesis_os_server.tkq:broker --fs-discover --tasks-pattern "genesis_os_server/tasks/*.py" ```