usmaanwahab.co.uk
Published: Aug 2025
Motivation
The initial motivation was to learn some Rust while also using it to showcase my skills.
Setup
The site uses Rocket.rs for the backend logic. Through Rocket.r, we can render templates using the Tera template engine. Tera allows us to include variables, expressions, conditional rendering that happens dynamically on a per request basis. Tera can also enable us to break up our HTML into many modular templates. In addition, the UI is created using Bootstrap 5 which comes with many pre-made componenets and a large online library of free to use componenets. This greatly simplifies UI development. There is also a sprinkle of custom JavaScript and CSS spread about to get things just right.
Docker
Originally the intent was to create a Dockerfile, containerise the application and automate deployment on a production branch update. However, there were limitations on the Digital Ocean
droplet used, as it was the cheapest with only 512MB of memory. This made it impractical to build the rust project on the droplet, and I was not keen on spending six-fold my initial plan.
As a 2GB droplet still came to a grinding halt when building what was a completely empty boilerplate project.
Why is building a project in rust so costly? Rust projects tend to have many dependencies as Rust follows a philosophy where modules tend to be smaller, and more concise. However, after
the first build dependencies are cached, making subsequent builds significantly faster. For example, when testing the this website, the build process will take only 2-3 seconds.
Aside - I was fiddling about with the caching in Docker but doing so felt conflicting as caching rust build dependencies using volumes felt a little counter-productive, as Docker is supposed to
allows us to have a standard reproducable environment but by caching rust dependencies we pollute this environment, especially if your team uses a several computer architectures.
This can lead to different behavior across machines, even if everyone's running the exact same commit.
deploy.sh
#! /bin/bash
build=true
while getopts "s" flag; do
case "$flag" in
s) build=false ;; # static only
esac
done
if [[ $build == true ]]; then
cargo build --release
fi
cd ..
if [[ $build == true ]]; then
scp usmaanwahab-co-uk/target/release/usmaanwahab-co-uk webserver:/root/
fi
scp usmaanwahab-co-uk/.env webserver:/root/
scp -r usmaanwahab-co-uk/templates/ webserver:/root/
scp -r usmaanwahab-co-uk/static/ webserver:/root/
ssh -t webserver 'sleep 1 && ./usmaanwahab-co-uk'