$ git clone https://github.com/BlockheaderWeb3-Community/autoswappr-backend.git
$ cd autoswappr-backend
Install Rust as described in The Rust Programming Language, chapter 1.
This is the official Rust language manual and is freely available on doc.rust-lang.org.
The latest stable version is fine.
sqlx-cli
SQLx provides a command-line tool for creating and managing databases as well as migrations. It is published
on the Cargo crates registry as sqlx-cli
and can be installed like so:
$ cargo install sqlx-cli --features postgres
By far the easiest way to run Postgres these days is using a container with a pre-built image.
The following command will start version 14 of Postgres (the latest at time of writing) using Docker (this command should also work with Podman, a daemonless FOSS alternative).
$ docker run -d --name postgres-14 -p 5432:5432 -e POSTGRES_PASSWORD={password} postgres:{version}
Set {password}
to a password of your choosing.
Set {version}
to a version of your choosing.
Ensure the Postgres server is running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
621eb8962016 postgres:{version} "docker-entrypoint.s…" 30 seconds ago Up 30 seconds 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp postgres-14
Configuring the backend application is done, preferentially, via environment variables. This is the easiest way to pass sensitive configuration data like database credentials and HMAC keys in a deployment environment such as Kubernetes secrets.
To make working with environment variables easier during development, we can use .env files to avoid having to define the variables every time.
As a starting point, you can simply cp .env.sample .env
in this repo and modify the .env
file as described by
the comments there.
With sqlx-cli
installed and your .env
file set up, you only need to run the following command to get the
Postgres database ready for use:
$ sqlx db setup
With everything else set up, all you should have to do at this point is:
$ cargo run
If successful, the Autoswappr API is now listening at port 8080.