Skip to content

Playing with web dev in Rust. This is a sample Rust microservice that can be deployed on Kubernetes.

Notifications You must be signed in to change notification settings

andregs/rust-auth-demo

Repository files navigation

Auth in Rust

This is a sample Rust microservice that can be deployed on Kubernetes.

This is a pet project for learning purposes that started from this tutorial.

tl;dr

Execute this demo app in minikube with:

minikube start --mount --mount-string=$PWD:/mnt/host --cpus=4
skaffold dev --trigger=manual --iterative-status-check

What's inside

This project demonstrates how to create:

rust-auth.mp4

More details / How I did it

Skaffold will build the app, deploy it in the cluster, watch for code changes and cleanup on quit.

Use kubectl to generate k8s yaml files (and customize them according your needs).

kubectl create blablabla --dry-run=client -o yaml > ops/k8s/file.yaml

Local Dev

Execute the app locally:

skaffold dev -m migrations --iterative-status-check --port-forward
APP_PROFILE=local cargo run

Execute the tests locally:

skaffold dev -m migrations --iterative-status-check --port-forward
DATABASE_URL=$(dasel -f App.toml -r toml test.db.url) sqlx database reset -y && cargo test

Initialize skaffold project

skaffold init -k ./ops/k8s/storage/*.yaml --skip-build

Deploy PostgreSQL + Redis and execute migrations

skaffold dev -m migrations --iterative-status-check --port-forward

Now you have the servers available for connection at localhost. Both dev & test databases get created and migrations executed.

Install sqlx and dasel CLIs locally

sudo apt-get install libpq-dev
cargo install sqlx-cli --no-default-features --features native-tls,postgres
curl -sSLf "$(curl -sSLf https://api.github.com/repos/tomwright/dasel/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d\" -f 4)" -L -o dasel && chmod +x dasel
mv ./dasel /usr/local/bin/dasel

You can use the sqlx cli to create migration files and prepare the sqlx-data.json, and dasel cli is useful to parse toml files. For example, to validate your SQL queries against your local DB and generate the json file, you can execute:

DATABASE_URL=$(dasel -f App.toml -r toml local.db.url) cargo sqlx prepare -- --lib

About

Playing with web dev in Rust. This is a sample Rust microservice that can be deployed on Kubernetes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages