API
Development
System
If you’re using windows, it is better to use WSL so your development environment is similar to the production environment.
Development environment setup
You will have to use the bin/dev script, you might have to make it executable:
chmod +x bin/dev
You will be using the following commands:
bin/dev td # testdiff - Test only the files that have been modified
bin/dev t # test - Test all files or a specific file
bin/dev tdb # testdb - Setup the test databases
bin/dev s # server - Start the Rails server binding to 0.0.0.0
bin/dev c # console - Start the Rails console
bin/dev u # up - Install all required gems (bundle install)
bin/dev ce # credentials:edit - Edit Rails credentials using VS Code
bin/dev l # lint - Run RuboCop to auto-correct linting issues
bin/dev d # doc - Generate YARD documentation and start the YARD server
Start python web server (needed for AI features)
You also have bin/dev script in the app/python dir where the python code lives.
-
Create and activate a python virtual environment if you haven't already.
python3 -m venv /rails/.venv -
Activate the python virtual environment.
source /rails/.venv/bin/activate -
Install dependencies and run the python server
app/python/bin/dev u app/python/bin/dev s
VS Code
Type ctrl/command + shift + p and search for:
Extensions: Show Recommended Extensions
You will find a list of recommended extensions for the project that you can install to speed up your development.
Using dev containers
This is the recommended approach unless you face issues with docker, you’ll then need to use the local setup.
-
Have docker installed and running on your machine.
-
Open the project in VSCode.
-
Install the Dev Containers extension in VSCode.
-
Type Cmd/Ctrl + Shift + P and search for >Dev Containers: Reopen in Container. This will build the container and open the project in it.
-
You can use the terminal in VSCode to run the commands:
Install dependencies:
bin/dev u # or bin/dev up
Run the server:
bin/dev s # or bin/dev serve
-
Modify credentials:
bin/dev ce # -e production or test (is development if not specified)... short for bin/dev credentials:edit
Attention - This assumes you are using ssh keys to connect to github and that the ssk keys are in the .ssh directory in your home directory. Otherwise, git commands will not work. - If the VS Code source control (git) extension is not working, do Cmd/Ctrl + Shift + P and search >Developer: Reload Window. - To rebuild the container if you change config files or need a new environment, do the following: 1- Type Cmd/Ctrl + Shift + P and search for >Dev Containers: Rebuild Container. 2- Wait for the container to be rebuilt and the project to be opened in it.
Local setup
-
Install ruby, your ruby version should match the one in the
Gemfilefile. -
Create a
.envfile in the root of the project following the.env.examplefile. -
Install the dependencies packages present in the
Dockerfile'sapt-get installcommand which are basically: -
java 17 openjdk (don't forget to set the
JAVA_HOMEandRUBY_RJB_JVM_OPTSenvironment variables) -
freetds + dependencies
-
Install dependencies:
bin/dev u # or bin/dev upYou will also need Java with the
JAVA_HOMEenvironment variable set to install the pdf-related dependencies. You can check oracle's documentation on how to do so. -
Start the development server:
bin/dev s # or bin/dev serveThis starts your app in development mode, rebuilding assets on file changes.
Linting
Lint and auto-correct your code using rubocop:
bin/dev l # or bin/dev lint
Push your code
When working in teams, it’s important to follow the Github flow to push your code.
Dependencies update
Dependabot’s PRs should be reviewed and merged as soon as possible to keep the project up to date.
Dump the database
Use this python command line tool:
mssql-scripter -S $HOST -d $DB_NAME -U sa -P $PASSWWORD > $SCHEMA_PATH.sql
Testing
If database changes has been made, setup test dbs:
bin/dev tdb # or testdb
To run all tests, execute:
bin/dev t # or test
To run a specific test file, execute:
bin/dev t test/models/user_test.rb
To run the tests you changed only, execute:
bin/dev td # testdiff
Documentation
Database
To generate erd diagram PDFs, add your models to the .erdconfig file then run:
bundle exec erd
To generate an interractive mermaid ERD:
bundle exec rails mermaid_erd
open mermaid_erd/index.html
The mermaid erd is available online at schema.paiehub.ca. To update the content of the mermaid ERD, do the following:
npm install -g wrangler # Install wrangler if not currently present
wrangler login
bundle exec rails mermaid_erd
wrangler pages deploy mermaid_erd --project-name schema
If asked for a project name, use the name “schema”
Code documentation
To generate a reloadable documentation website based on the comments over the code, run:
bin/dev d # doc
The rails doc is available online at railsdoc.paiehub.ca. To update the content of the code doc, do the following:
npm install -g wrangler # Install wrangler if not currently present
wrangler login
bin/dev d
wrangler pages deploy ./doc --project-name railsdoc
Deployment
On your machine used to trigger the deployment
You will need to have access to the remote machine which will itself deploy. Get its password and copy your ssh key to it:
ssh-copy-id root@192.168.11.50 # Ip present in bin/deploy
then do
bin/deploy
On the remote machine where the app will be deployed
If you’re using a fresh rocky linux machine, execute first on it:
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
If you have a bad installation of docker or if docker is causing issues, remove it using and then reinstall:
sudo systemctl stop docker
sudo dnf remove -y docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
sudo groupdel docker
On the deployment machine
To deploy to production, have .env.production file in the root of the project and run:
kamal deploy
To deploy to staging, have .env.staging file in the root of the project and run:
kamal deploy -d staging