Quick Start for Shuttle.rs

Photo by Jean Gerber on Unsplash

Quick Start for Shuttle.rs

How to deploy my Axum app to Shuttle.rs

Opening

I came across a video on YouTube that shows how to quickly and easily deploy a web application made in the Rust programming language. It's a service called Shuttle.rs, and I would like to inform you of the entire flow in the order of command execution rather than deep content.

Prerequisites

Install Ubuntu packages and cargo crate needed.

$ sudo apt install -y protobuf-compiler
$ cargo install cargo-shuttle

Login to Shuttle.rs

Log in at https://www.shuttle.rs/login using your GitHub ID. After that, you can see some instructions on how to use Shuttle.rs. Please check API-Key --api-key <API-KEY-HASH-CODE>

$ cargo shuttle login --api-key <API-KEY-HASH-CODE>

Initialize your project

$ cargo shuttle init
First, let's log in to your Shuttle account.
If your browser did not automatically open, go to https://shuttle.rs/login
✔ API key · ********

How do you want to name your project? It will be hosted at ${project_name}.shuttleapp.rs.
✔ Project name · my-project

Where should we create this project?
✔ Directory · my-project

Shuttle works with a range of web frameworks. Which one do you want to use?
· axum

✔ Do you want to create the project environment on Shuttle? · yes

project 'my-project' is ready

I chose Axum as my web framework. Let's take a look at the code base.

$ tree
my-project
├── Cargo.lock
├── Cargo.toml
└── src
    └── main.rs

2 directories, 3 files
$ cat src/main.rs
use axum::{routing::get, Router};

async fn hello_world() -> &'static str {
    "Hello, world!"
}

#[shuttle_runtime::main]
async fn axum() -> shuttle_axum::ShuttleAxum {
    let router = Router::new().route("/hello", get(hello_world));

    Ok(router.into())

Build locally

$ cd my-project
$ cargo build
  Finished dev [unoptimized + debuginfo] target(s) in 1m 53s

Run locally

$ cargo shuttle run
  Starting my-project on http://127.0.0.1:8000

You can check your app response on your web browser or curl command in the terminal.

$ curl -X GET http://127.0.0.1:8000/hello
Hello, world!

Deploy to Shuttle.rs

$ cargo shuttle deploy --allow-dirty
2023-04-23T10:13:12.413706462Z  INFO Entering building state
No resources are linked to this service

Service Name:  my-project
Deployment ID: abcd1234-abcd-1234-a1b2-abcd1234abcd
Status:        running
Last Updated:  2023-04-23T01:13:04Z
URI:           https://my-project.shuttleapp.rs
$ cargo shuttle deployment list
╭────────────────────────────────────┬───────┬────────────────────╮
│                Deployment ID       ┆ Status┆   Last updated     │
╞════════════════════════════════════╪═══════╪════════════════════╡
│abcd1234-abcd-1234-a1b2-abcd1234abcd┆running┆2023-04-23T01:13:04Z│
╰────────────────────────────────────┴───────┴────────────────────╯

Awesome! we can access my service with the printed URI.

Check the results


$ curl -X GET https://my-project.shuttleapp.rs/hello

Stop service

$ cargo shuttle stop
Successfully stopped service
No deployment is currently running for this service
$ cargo shuttle deployment list
╭────────────────────────────────────┬───────┬────────────────────╮
│                Deployment ID       ┆ Status┆   Last updated     │
╞════════════════════════════════════╪═══════╪════════════════════╡
│abcd1234-abcd-1234-a1b2-abcd1234abcd┆stopped┆2023-04-23T01:23:04Z│
╰────────────────────────────────────┴───────┴────────────────────╯

Logout

$ cargo shuttle logout
Successfully logged out of shuttle.

Closing

Shuttle.rs allows you to quickly deploy your services on the Internet using the Rust programming language. As of April 2023, there seems to be no function to delete all deployed resources with the provided cargo-shuttle crate. It is currently in a beta open state, so I think it will continue to improve.