Server Development Guide#
Project Build Dependencies#
The Server part is written in Rust. You should first install Rust. Development can be done locally or in docker. Deployment are done in Docker, so you should also install Docker. docker-buildx and docker-compose also need to be installed.
Server Configuration File#
Examples of all configuration files are stored in the config directory. It is best not to change these configuration files during the development phase.
Container Development#
We provide a docker compose file template for the development environment, you can modify it according to your needs
You can run:
docker compose -f docker/compose.devenv.yml up -d
to configure the development environment (postgres, redis, rabbitmq, etc.)
Security Warning#
If you are setting up environment on a server which has a public ip, please notice that docker will modify iptables to cross the firewall, so leaving these services which owns weak passwords is very dangerous.
You can choose the following setting in /etc/docker/daemon.json to avoid network attack problem.
{
"iptables": false
}
However, using this config is not one-and-down, it may cause some other services being down, but in your development machine, it is not a big problem.
The recommended development approach is to develop outside the container but use the environment set up inside the container, otherwise environment inconsistency issues may occur
First, switch to the server directory, all development will be done here.
Use when starting up
cargo run -- --config=cfg.toml
Start testing:
Please refer to Testing
Database#
This project uses Redis, PostgreSQL as databases, and uses sea-orm as the ORM framework. To better utilize this ORM framework, after modifying the database tables, you can run script/regenerate_entity.py to regenerate the files required by the ORM framework.
To run this script, you first need to run cargo install sea-orm-cli
Note: Please ensure that sea-orm-cli is up to date, otherwise it will be blocked by the script. If the script version is older, feel free to open an issue at any time.
Database Migration#
The migration directory contains the database migration module, which will automatically run pending database migrations when the server starts. To define a new database migration, please refer to sea orm