Giter Site home page Giter Site logo

andregs / rust-auth-demo Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 0.0 191 KB

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

Rust 99.37% Procfile 0.10% Dockerfile 0.53%
buildpacks kubernetes microservice redis rocket rust skaffold sqlx

rust-auth-demo's Introduction

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

rust-auth-demo's People

Contributors

andregs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.