0%

在shuttle平台上部署rust服务

shuttle 平台简介

shuttle 是一个 PaaS 平台,用于部署 rust 后端服务,支持多个流行的 rust web 框架,如 axum,actix-web、rocket 等。作为对比的话,类似于 heroku(python) 和 deno deploy 平台。

部署 shuttle 服务

将一个现有的 rust web 服务改造并部署到 shuttle 平台上非常简单。拿 axum 框架距离只需要在 cargo.toml 中添加 shuttle-runtime 与 shuttle-axum 依赖,并简单地修改 main 函数即可。

1
2
3
4
5
6
7
#[shuttle_runtime::main]
async fn axum() -> shuttle_axum::ShuttleAxum {

let router = Router::new().route("/", get(hello_world));

Ok(router.into())
}

然后通过命令行工具即可将服务部署到 shuttle 平台上。

1
2
3
4
# cargo install cargo-shuttle ## 安装cargo shuttle
# cargo shuttle login ## 登录shuttle
# cargp shuttle project start ## 创建项目
cargo shuttle deploy # 部署服务

实践

花了一点时间,我将之前开发的二维码生成服务qr-web-rs部署到了 shuttle 平台上,可以通过以下两个链接访问。

总结

shuttle 平台体验相当不错,并且有不少的免费额度,可以用于个人 rust 服务的部署。

扫码加入技术交流群🖱️
QR code