Skip to content
/ webapp-rs Public

Rust microservice setup with postgres, and diesel + rocket in docker

Notifications You must be signed in to change notification settings

clux/webapp-rs

Repository files navigation

Rust microservice setup with rocket and postgres diesel

CircleCI docker pulls docker image info docker tag

A JSON API microservice with database backing all running from a <7MB container.

Developing Easily

Install dependencies, setup rustup env, then start a dev postgres with credentials:

sudo pacman -S postgresql-libs # or distro equivalent
make setup
source env.sh
make db # runs postgres in a container

then run and test in parallel with:

make run
make test

This workflow is the fastest as it does not require waiting for docker builds, nor deal with a local installations of postgres. You just need to install docker, postgresql-libs to manage migrations in a container, and run against it with what's essentially cargo run.

Using docker-compose

You can develop and test production equivalents without rust, without local postgres, without postgres libs, and without diesel-cli locally.

This is the production equivalent flow:

# Build the app with clux/muslrust
make compile
# Put the built binary into a container and compose with a db.
# Then, once the db is up, use clux/diesel-cli to run migrations:
source env.sh
make compose
# Verify
make test

CI

Runs unit tests, musl build, intergration tests with docker compose and pushes to docker hub, all in <2 minutes (using a cache of rust target + registy directories).

Continuous Integration layout and timing

Using Kubernetes

Port to your templated wall of yaml of choice if you know what you are doing.

Caveats

NB: With docker-compose our migration would have to wait for postgres to initialize, either via a sleep or a psql "select 1" attempt. See make compose for more info.

NB: The compile step is required before any build step, so docker-compose up would fail without it. It's possible to fix this by using a multistep docker build for the app, but it makes local build caching harder.

About

Rust microservice setup with postgres, and diesel + rocket in docker

Resources

Stars

Watchers

Forks

Packages

No packages published