Skip to content

cas-4/backend

Repository files navigation

CAS4 backend API

Logo

This repo refers to a GraphQL API written in Rust used for a project for the Context Aware System class at the University of Bologna.

Development

You need:

Now you set up some env variables:

  • RUST_LOG: used by the logger.

  • DATABASE_URL: it can be in a DSN format such as host=localhost user=postgres password=password dbname=cas4 port=5432 or in a URL format such as postgres://postgres:password@localhost:5432/cas4.

  • JWT_SECRET: this must be secret because it is used to encrypt/decrypt JWT tokens.

  • ALLOWED_HOST: refers to the online host of the service (eg: 0.0.0.0:8000).

  • EXPO_ACCESS_TOKEN: used by the Expo API access.

  • UNREALSPEECH_TOKEN: used by Unrealspeech for text-to-speach API.

After that you must copy the schema/init.sql file into the database.

Now just run the app

cargo run

Deploy

Fortunately the deployment is automatized by the GitHub Action cd.yml which pushes the latest release version to a GHCR.io package.

A new version is released using

./scripts/release X.Y.Z

Now you just exec

docker pull ghcr.io/cas-4/backend:latest

Or you can build a new image

docker build -t cas:latest .
docker run \
    -e RUST_LOG=... \
    -e DATABASE_URL=... \
    -e JWT_SECRET=... \
    -e ALLOWED_HOST=... \
    -e EXPO_ACCESS_TOKEN ... \
    -e UNREALSPEECH_TOKEN ... \
    cas:latest

Or the Docker compose which puts up also the PostgreSQL locally.

docker compose up

Kubernetes

If you do not want to use Docker or Docker compose directly, you can use a Kubernetes cluster like MiniKube and follow the istructions available at github.com/cas-4/network.

Documentation

An always updated documentation is available at this link.