In this post, I will show you the fastest way to deploy a Rust project to any hosting provider. We'll focus on Digital Ocean, but The principles discussed here can also be applied to other hosting providers. This guide assumes you already have a Rust project with a web server running on port 3000. Since Rust compiles to an executable binary, you don't need Docker or have to install Rust on the server, and you probably don't need Nginx either. Just compile, upload, and run.
We aim to create a script that will update the server from a local environment. While it's possible to use something from a Continuous Integration (CI) pipeline, this post will focus on a quick deployment to allow you to get back to building your project.
$ dpkg --print-architecture
amd64
cross build --target x86_64-unknown-linux-gnu --release
scp /your-path/my_app/target/x86_64-unknown-linux-gnu/release/my_app [email protected]:/root/my_app
ssh -f [email protected] 'chmod +x /root/my_app/my_app'
ssh -f [email protected] './root/my_app'
Here's a script to use for future updates to the Rust app.
cargo install cross
cross build --target x86_64-unknown-linux-gnu --release
ssh -f [email protected] 'sudo kill $(sudo lsof -t -i :3000)'
ssh -f [email protected] 'cd my_app && git pull'
scp /your-path/my_app/target/x86_64-unknown-linux-gnu/release/my_app [email protected]:/root/my_app
ssh -f [email protected] 'chmod +x /root/my_app/my_app'
ssh -f [email protected] './root/my_app'
While this method is a quick way to deploy an app and return to building, it is worth noting that it misses some best practices for deploying a production application.