rustdeploymentcloudaxum

Deploying a Rust App to Rustfinity Cloud

ยท3 min read

Rustfinity Cloud makes deploying Rust apps ridiculously simple. In this guide, we'll walk through deploying an Axum web server from scratch โ€” from creating the project to having it live on the internet.

Prerequisites

Before we begin, make sure you have:

Log in to the CLI once you have your account:

rustfinity login

Creating a Sample Axum App

Let's create a simple Axum web server to deploy. Start by creating a new project:

cargo init my-axum-app
cd my-axum-app

Add the dependencies to Cargo.toml:

[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["full"] }

Replace the contents of src/main.rs:

use axum::{routing::get, Router};
 
#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(|| async { "Hello from Rustfinity Cloud!" }))
        .route("/health", get(|| async { "ok" }));
 
    let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string());
    let addr = format!("0.0.0.0:{port}");
 
    let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
    println!("Listening on {addr}");
    axum::serve(listener, app).await.unwrap();
}

Notice that we read the port from the PORT environment variable. This is required โ€” Rustfinity Cloud assigns a port dynamically and your app must listen on it.

Test it locally:

cargo run
# Visit http://localhost:3000

Configuring for Deployment

Rustfinity Cloud uses a Rustfinity.toml file at the root of your project for configuration. Create one:

[app]
name = "my-axum-app"
 
[build]
command = "cargo build --release"
binary = "target/release/my-axum-app"
 
[health]
path = "/health"
interval = 30

The health.path tells Rustfinity Cloud where to send health check requests. If the health check fails, your app will be automatically restarted.

Running rustfinity deploy

With everything in place, deploy your app:

rustfinity deploy

You'll see output like this:

๐Ÿ” Detecting project...
๐Ÿ“ฆ Building my-axum-app...
   Compiling my-axum-app v0.1.0
    Finished release [optimized] target(s)
๐Ÿ“ค Uploading binary (4.2 MB)...
๐Ÿš€ Deploying to Rustfinity Cloud...
โœ… Live at https://my-axum-app.rustfinity.app

Health check passed โœ“

Your app is now live! Visit the URL shown in the output.

Environment Variables & Secrets

Most apps need environment variables for database URLs, API keys, and other configuration. Set them with the CLI:

# Set a single variable
rustfinity env set DATABASE_URL "postgres://user:pass@host/db"
 
 
<InlineCarbonAd />
 
# Set multiple at once
rustfinity env set API_KEY "sk-123" SECRET_KEY "my-secret"
 
# List current variables
rustfinity env list
 
# Remove a variable
rustfinity env unset API_KEY

Environment variables are encrypted at rest and injected into your app at runtime. After changing env vars, redeploy for them to take effect:

rustfinity deploy

Health Checks

Rustfinity Cloud pings your health check endpoint at the configured interval. If it receives a non-200 response three times in a row, your app is automatically restarted.

We recommend a dedicated /health route that returns a simple 200 OK:

.route("/health", get(|| async { "ok" }))

For more advanced checks, you can verify database connectivity or other dependencies:

async fn health_check(State(pool): State<PgPool>) -> impl IntoResponse {
    match sqlx::query("SELECT 1").execute(&pool).await {
        Ok(_) => (StatusCode::OK, "ok"),
        Err(_) => (StatusCode::SERVICE_UNAVAILABLE, "unhealthy"),
    }
}

Monitoring & Logs

View your app's logs in real time:

rustfinity logs

Or tail them continuously:

rustfinity logs --follow

You can also view logs and basic metrics from the Rustfinity Cloud dashboard.

Updating Your Deployment

Redeploying is the same command:

rustfinity deploy

Rustfinity Cloud performs zero-downtime deployments by default โ€” the new version starts up and passes health checks before traffic is switched over.

To roll back to a previous deployment:

rustfinity rollback

Conclusion & Next Steps

That's all it takes to go from an empty directory to a live Rust app on the internet. Rustfinity Cloud handles the infrastructure so you can focus on writing code.

Here's what to explore next:

Happy deploying! ๐Ÿฆ€

Get updated on the latest courses, features, tools, resources about Rust, and more!

Learn Rust by Practice

Master Rust through hands-on coding exercises and real-world examples.

Check out our blog

Discover more insightful articles and stay up-to-date with the latest trends.

Subscribe to our newsletter

Get the latest updates and exclusive content delivered straight to your inbox.