Skip to content

nawok/zero-to-production-in-rust

Repository files navigation

Zero to Production in Rust

CI Security audit Coverage

Faster inner development loop

  1. Install an alternative linker for the current OS (see Cargo.toml)
  2. cargo install cargo-watch
  3. cargo watch -x check -x test -x run

De-occupy the port

lsof -t -i tcp:8000 | xargs kill -9

Expand macros

  1. cargo install cargo-expand
  2. rustup toolchain install nightly --allow-downgrade
  3. cargo +nightly expand

Remove unused dependencies

  1. cargo install cargo-udeps
  2. cargo +nightly udeps

Docker

# Update SQLx schema for offline builds
cargo sqlx prepare -- --lib

# Build and run image
docker build --tag zero2prod --file Dockerfile .
docker run -p 8000:8000 --network=host zero2prod

Digital Ocean

# Create app
doctl apps create --spec spec.yaml

# Get app ID and URL
app_id=$(doctl apps list | awk '/zero2prod/ {print $1}')
app_url=$(doctl apps list | awk '/zero2prod/ {print $3}')

# Update app
doctl apps update $app_id --spec=spec.yaml

# Migrate database
DATABASE_URL=$database_url sqlx migrate run

# Health check
curl -v $app_url/health_check

# Post
curl -v $app_url/subscriptions -d 'name=Le%20Guin&email=ursula%40leguin.com'

# Delete
doctl app delete --force $app_id

About

My notes and code for the “Zero to Production in Rust” book by Luca Palmieri

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published