Editor’s note: This article was last updated on 4 July 2023 to remove outdated Rust deployment libraries and replace them with more popular libraries.
In the recent Stack Overflow developer survey, Rust emerged as the most loved language for the 8th time in a row, thanks in large part to the core team’s penchant for challenging the status quo of existing systems such as C/C++ and the growing community.
Most Rust programmers speak highly of the productivity, efficiency, performance, and reliability of the language, which sets it apart as a premier choice for building mission-critical applications, dev tools, and highly performant applications.
It’s no surprise that companies are scrambling to migrate their web apps and systems to Rust. Deployment can be a major speed bump in this process. In this guide, we’ll introduce you to some deployment libraries and services that are currently available for Rust.
Jump ahead:
- What is deployment?
- Criteria for evaluating deployment tools
- Shuttle
- Heroku
- Docker
- Render
- NGINX
- Clever Cloud
What is deployment?
Software deployment refers to the activities, procedures, and steps that are necessary to make a software system available for the consumption of end users. The word deployment can also mean moving or migrating a software system or app to a remote server. Software deployment can also refer to updates, patches, or new apps with either automated or manual processes, including but not limited to installation, builds, testing, release, and performance monitoring.
Innovation has flourished over the past few decades, with software development teams building new systems, architectures, principles, and patterns for software delivery to improve the speed and accuracy of product release. For example, today a feature could be pushed and instantly made available on production, provided that the code and features pass the deployment phases. This process brings about various deployment options, including infrastructure-as-a-service (IaaS), platform-as-a-service (Paas), virtualization servers, and more.
As Rust grows in popularity, hosting companies and services have been channeling their resources toward supporting Rust for the web. Developers can’t wait to have their full-fledged performance apps on the web.
Before we proceed, it’s important to understand a few key terms we’ve already mentioned:
- Platform-as-a-service (PaaS): Cloud-based computing services that provide a platform to help developers and users handle complex aspects of app deployment, such as infrastructure (automation scripts, run, manage, monitor, etc.). Examples of PaaS providers include Heroku, Google App Engine, Render, and IBM Cloud Code Engine
- Infrastructure-as-a-service (IaaS): An instant online computing platform that provides infrastructure (firewall, security, scaling, location, resources, etc.) to simplify owning and managing physical servers or data centers. Some of the infrastructure includes Oracle VirtualBox, Oracle VM, VMware, etc. Examples of popular IaaS providers include AWS, Microsoft Azure, and Google Cloud
- Virtual private server (VPS): Equivalent to a dedicated physical server, which is the process of providing users with a copy of an OS instance with full access to install almost anything that is compatible. However, the underlying physical hardware is shared with other users — even though they might share a physical server, the performance of one VPS is not affected by other VPS’s on the same server. Examples of VPS providers include DigitalOcean, Linode, and Vult
Now let’s discuss some key criteria to consider when choosing a deployment tool for your Rust app.
Criteria for evaluating deployment tools
When evaluating deployment tools for Rust or any other programming language, it’s essential to consider several key factors. These criteria can help you choose the right tool for your specific needs and ensure that your deployment process is as smooth and efficient as possible:
- Ease of use: The tool should have a user-friendly interface and be easy to set up and configure, even for developers who may not have extensive experience with deployment processes
- Documentation: Comprehensive and clear documentation is crucial. It should provide step-by-step guides for setting up and using the tool, as well as troubleshooting tips for common issues
- Integration: The tool should integrate seamlessly with other services and tools you’re using, such as version control systems (like Git), continuous integration/continuous deployment (CI/CD) pipelines, and cloud platforms
- Support for Rust: Given that Rust has unique features and requirements, the tool should have robust support for Rust applications. This includes support for Rust’s package manager, Cargo, and popular Rust frameworks
- Pricing: Consider the cost of the tool and whether it fits within your budget. Some tools offer free tiers or open source versions, while others may require a monthly or annual subscription
- Scalability: The tool should be able to handle your application as it grows in size and complexity. This includes the ability to manage multiple environments (like staging and production) and to handle increased traffic and data volume
- Community and support: A strong community and good customer support can be invaluable, especially when you run into problems or need advice. Look for tools that have active forums, regular updates, and responsive support teams
- Production-readiness: The tool should be reliable and stable enough to handle production workloads. This includes features like zero-downtime deployments, rollback capabilities, and robust error handling
With that out of the way, let’s explore the popular deployment tools in the Rust community
Shuttle
Shuttle is a Rust deployment platform that allows you to deploy your Rust application to the cloud for free. It’s pretty straightforward to set up and get your Rust application up and running in no time, depending on the complexity of your own application.
- Pricing: Shuttle is free for now
- Is it production-ready? Shuttle is fairly new, and it’s not clear whether it is ready for production or not
Deployment procedure
To use Shuttle, you’ll first install it by running the following code:
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
This should take less than a minute to complete and then you can run:
cargo binstall cargo-shuttle
Once that is complete, you should see the version of Shuttle when you run cargo shuttle
--version
. Then, create an account on the website with your GitHub account. When you are logged in, run cargo shuttle login --api-key {key}
to authenticate yourself:
Then, run cargo shuttle project start
to add Shuttle to your project and get it ready for deployment. Finally, run cargo shuttle deploy
. Here is an example of a Hello World
app’s successful deployment:
For more details about working with Shuttle, I suggest you check out the documentation.
Heroku
Heroku is a cloud PaaS tool that supports the seamless deployment of projects built with different languages, libraries, and frameworks such as PHP, Python, Go, React, Node.js, Scala, etc.
Heroku, however, does not natively support Rust but there are a handful of Heroku buildpacks that make it easy to deploy Rust on Heroku with support for Cargo and Rustup.
- Pricing: The price depends on the services you choose. The pricing page looks like the one below:
As you can see, the price can go from $7 to $20 per month depending on your system requirements.
- Is it production-ready? Yes, Heroku is used by many organizations in production
Deployment procedure
For an efficient deployment process, it’s recommended to kick-start by installing the Heroku Command Line Interface (CLI). If you don’t already have it installed, you can run the following commands to install it if you are on Mac:
brew tap heroku/brew && brew install heroku
For Linux:
curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
For Windows users, you can download the installer for your system architecture from the Heroku website. Once your installation is complete, head over to the directory that contains your project and run the command below to add the unofficial Rust buildpack to your project.
Before you run the command below, you must first create an account on the Heroku site and then run heroku login
on your terminal. Once your login is complete, you can run the command below:
heroku create --buildpack https://github.com/emk/heroku-buildpack-rust.git
Ensure your project has Git and Cargo initiated. Otherwise, this might not work. Next, create a Procfile
, which is technically Heroku’s config file. We’ll use the Procfile to instruct Heroku on where to find our Rust executable:
Create a Procfile in the root of your project and add the following contents to it — the contents might be different based on the name of your project. In this example, the name of my app is app
:
web: ./target/release/app
Finally, run the command below to push to GitHub in order to trigger automatic deployment:
git push heroku master
Benefits of deploying Rust on Heroku:
- Automatic updates to the most recent stable version of Rust
- Seamless switching between Rust versions
- Support for exporting the Rust toolchain, allowing other buildpacks access
- Simplified compilation of Rust extensions for projects coded in other languages like C/C++
Docker
Docker is a PaaS service that uses virtualization to deliver resources such as software, libraries, and other configuration files in packages as containers.
Docker enables you to build and ship any software because it helps you keep track of packages using Dockerfile
. The official image has more than 10 million downloads on Docker Hub.
- Pricing: Relative (based on the VPS in use)
- Production-ready? Yes
Deployment procedures
There are several nightly containers/images built for Rust, but the official Docker image is managed by the Rust team. Also, using Docker’s multistage build can help you avoid toolchain compilation, which requires you to copy the app’s compiled binary files to the container.
All you need to do to deploy your Rust app with Docker is to first create a Dockerfile and a Docker Compose file depending on your requirement like every other Docker deployment. Here is a simple Docker file that will deploy a basic Rust application:
# Start from the latest Rust base image FROM rust:latest as builder # Set the current working directory in the image WORKDIR /usr/src/myapp # Copy the entire project COPY . . # Build for release RUN cargo build --release # Start a new stage FROM debian:buster-slim # Install OpenSSL RUN apt-get update && \ apt-get install -y openssl && \ rm -rf /var/lib/apt/lists/* # Copy the build artifact from the builder stage and set the executable's permissions COPY --from=builder /usr/src/myapp/target/release/myapp /usr/local/bin # Set the startup command to run the binary CMD ["myapp"]
Each step is well commented on to show what is happening in the build process. However, let’s take a closer look at the steps to make it more clear.
FROM rust:latest as builder
: This line is pulling the latest Rust Docker image from Docker Hub and naming this stage of the build process “builder.” This image includes all the tools necessary to compile Rust code.
WORKDIR /usr/src/myapp
: This line is setting the working directory inside the Docker image to /usr/src/myapp
. Any subsequent commands will be run from this directory.
COPY . .
: This line is copying all the files from your local directory, where the Dockerfile is located, into the current directory in the Docker image (/usr/src/myapp
).
RUN cargo build --release
: This line is running the cargo build --release
command inside the Docker image. This command compiles your Rust code in release mode, creating an optimized executable.
FROM debian:buster-slim
: This line is starting a new stage of the build process. It’s pulling a slim version of the Debian Buster image from Docker Hub. This image is smaller than the Rust image, which helps to reduce the size of the final Docker image.
The next three lines are updating the package lists for the Debian image, installing OpenSSL (a common dependency for Rust applications), and then removing the package list files to reduce the size of the image:
RUN apt-get update && \ apt-get install -y openssl && \ rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/myapp/target/release/myapp /usr/local/bin
: This line is copying the compiled Rust application from the “builder” stage into the current stage. The application is placed in /usr/local/bin
, which is a common directory for executables and is included in the PATH
environment variable by default.
CMD ["myapp"]
: This line is setting the default command to run when a container is started from the Docker image. It’s running the Rust application that was copied in the previous step.
That’s all there is to it! Now, you can run the deployment on your server by running the command docker build -t .
Render
Render is a cloud-based PaaS company that offers immense power and scalability and handles apps of all sizes.
- Price: Render pricing starts at $7/month, and increases depending on your project requirements
- Production-ready? Yes
Deployment
Render has full-fledged support for the Rocket and Actix frameworks. It could also be set up using Cargo
because it provides easy deployment with simple clicks and minimal configuration.
Essentially, you can deploy to Render in 3 easy steps:
- Create a GitHub repo for your project if you don’t already have one
- Create a Render account and link it to your GitHub repo; it’s a guided process
- Create a web service with the following configuration in your Render account:
And that’s it. The next time you push to that repo in the beach you set during the configuration, your Rust application will automatically deploy.
NGINX
NGINX is a popular web server that offers features such as load balancing, reverse proxy, mail proxy, and more.
- Pricing: NGINX is free. You are free to use it on your server
- Production-ready? Yes
Deployment
Deploying Rust using NGINX is as easy as proxy passing the web framework server and creating a system service that monitors the Rust web framework server status. After generating a production release from your Rust project by running cargo build --release
, you can choose to run it with PM2. When you are done with that, simply set up NGINX on your server with the following configuration:
server { server_name yourdomain.com www.yourdomain.com; location /api/ { proxy_pass http://127.0.0.1:{yourport}/api/; proxy_http_version 1.1; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Finally, restart NGINX and that’s it!
Clever Cloud
Clever Cloud is a PaaS company based in Europe that offers services closely related to Heroku to help developers deploy and run their apps without hassle. Unlike Heroku, Clever Cloud has native support for Rust.
- Price: ~$5/month — starting price for side projects
- Production-ready: Yes
Deployment
Clever Cloud simplifies the deployment, building, and scaling of Rust applications. It integrates platform services with Git, eliminating the complexities of buildpacks by managing application builds through an intuitive dashboard interface.
Clever Cloud has comprehensive documentation for how to deploy your Rust application onto their server. However, as an overview, one of their deployment methods uses Git workflow as follows:
- Create an account if you don’t have one
- Link your GitHub repository
- Push to your master branch. Every push to the master branch triggers a new build
Conclusion
Deploying Rust applications is a straightforward process, and the tools we covered in this article make it even more fun. As Rust adoption keeps growing, more deployment options in the Rust community will be made available. Regardless of your budget, there is a deployment tool for you as we’ve seen in this guide. Their usage will largely depend on your project requirements.
Happy hacking!
LogRocket: Full visibility into web frontends for Rust apps
Debugging Rust applications can be difficult, especially when users experience issues that are difficult to reproduce. If you’re interested in monitoring and tracking performance of your Rust apps, automatically surfacing errors, and tracking slow network requests and load time, try LogRocket.
LogRocket is like a DVR for web and mobile apps, recording literally everything that happens on your Rust app. Instead of guessing why problems happen, you can aggregate and report on what state your application was in when an issue occurred. LogRocket also monitors your app’s performance, reporting metrics like client CPU load, client memory usage, and more.
Modernize how you debug your Rust apps — start monitoring for free.